mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 21:07:21 +00:00
Improved the security of the connection between the app window and AI Studio (#1146)
This commit is contained in:
1 parent
64dc621a7d
commit
faae2951f7
26 files changed
+1056
-88
No files matched your search
@@ -0,0 +1,29 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AIStudio.Tests.Tools.AppAccess;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the access checks run before anything else in the request pipeline of the app.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A middleware or an endpoint which comes first would answer requests the checks never saw. The
|
||||
/// test reads the calls from the source of Program.cs, so that a new one is checked without anybody
|
||||
/// having to add it to a test.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class AppAccessPipelineTests
|
||||
{
|
||||
private static string ReadProgramSource([CallerFilePath] string sourceFilePath = "") => File.ReadAllText(Path.Combine(Path.GetDirectoryName(sourceFilePath)!, "..", "..", "..", "MindWork AI Studio", "Program.cs"));
|
||||
|
||||
[Test]
|
||||
public void TheAccessChecksComeBeforeEveryOtherMiddlewareAndEndpoint()
|
||||
{
|
||||
var calls = Regex.Matches(ReadProgramSource(), @"\bapp\.(Use|Map)\w*(<\w+>)?\(")
|
||||
.Select(match => match.Value)
|
||||
.ToList();
|
||||
|
||||
Assert.That(calls, Has.Count.GreaterThan(2), "The test found no middleware or endpoint after the access checks.");
|
||||
Assert.That(calls.Take(2), Is.EqualTo(new[] { "app.UseHostFiltering(", "app.UseMiddleware<AppAccessMiddleware>(" }));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user