Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add out-of-process server start

Leendert de Borst4561e6337728
diff --git a/src/Tests/AliasVault.E2ETests/AuthTests.cs b/src/Tests/AliasVault.E2ETests/AuthTests.cs
index 3cd80c906..fe6ab2796 100644
--- a/src/Tests/AliasVault.E2ETests/AuthTests.cs
+++ b/src/Tests/AliasVault.E2ETests/AuthTests.cs
@@ -13,13 +13,13 @@ public class Tests : PlaywrightTest
public async Task Login()
{
// Replace with the URL where your Blazor app is running
- await Page.GotoAsync("http://localhost:5067");
+ await Page.GotoAsync("http://localhost:5000");
var navigationTask = Page.WaitForNavigationAsync();
await navigationTask;
// Check that we got redirected to /user/login
var currentUrl = Page.Url;
- Assert.That(currentUrl, Is.EqualTo("http://localhost:5067/user/login"));
+ Assert.That(currentUrl, Is.EqualTo("http://localhost:5000/user/login"));
// Try to login with test credentials.
var emailField = Page.Locator("input[id='email']");
@@ -29,13 +29,13 @@ public class Tests : PlaywrightTest
// Check if we get redirected when clicking on the login button.
var loginButton = Page.Locator("button[type='submit']");
- navigationTask = Page.WaitForNavigationAsync(new PageWaitForNavigationOptions() { Timeout = 2000});
+ navigationTask = Page.WaitForNavigationAsync(new PageWaitForNavigationOptions() { Timeout = 200000});
await loginButton.ClickAsync();
await navigationTask;
// Check if the redirection occurred
currentUrl = Page.Url;
- Assert.That(currentUrl, Is.EqualTo("http://localhost:5067/"));
+ Assert.That(currentUrl, Is.EqualTo("http://localhost:5000/"));
// Check if the login was successful by verifying content.
var pageContent = await Page.TextContentAsync("body");
diff --git a/src/Tests/AliasVault.E2ETests/PlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/PlaywrightTest.cs
index 09f361758..7fd7a86f0 100644
--- a/src/Tests/AliasVault.E2ETests/PlaywrightTest.cs
+++ b/src/Tests/AliasVault.E2ETests/PlaywrightTest.cs
@@ -8,12 +8,36 @@ public class PlaywrightTest
protected IBrowserContext Context { get; private set; }
protected IPage Page { get; private set; }
+ private WebAppManager _webAppManager;
+
+
[SetUp]
public async Task SetUp()
{
+ _webAppManager = new WebAppManager();
+
+ // Start WebAPI and Blazor WASM projects
+ await _webAppManager.StartWebApiAsync(5001);
+ await _webAppManager.StartBlazorWasmAsync( 5000);
+
var playwright = await Playwright.CreateAsync();
- Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
+ Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false });
Context = await Browser.NewContextAsync();
+
+ // Intercept requests and override appsettings.json
+ await Context.RouteAsync("**/appsettings.json", async route =>
+ {
+ var response = new
+ {
+ ApiUrl = "http://localhost:5001"
+ };
+ await route.FulfillAsync(new RouteFulfillOptions
+ {
+ ContentType = "application/json",
+ Body = System.Text.Json.JsonSerializer.Serialize(response)
+ });
+ });
+
Page = await Context.NewPageAsync();
}
@@ -23,5 +47,8 @@ public class PlaywrightTest
await Page.CloseAsync();
await Context.CloseAsync();
await Browser.CloseAsync();
+
+ _webAppManager.StopWebApi();
+ _webAppManager.StopBlazorWasm();
}
}
diff --git a/src/Tests/AliasVault.E2ETests/WebAppManager.cs b/src/Tests/AliasVault.E2ETests/WebAppManager.cs
new file mode 100644
index 000000000..156264518
--- /dev/null
+++ b/src/Tests/AliasVault.E2ETests/WebAppManager.cs
@@ -0,0 +1,222 @@
+using System.Diagnostics;
+using System.Net;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using OSPlatform = NUnit.Framework.Internal.OSPlatform;
+
+namespace AliasVault.E2ETests;
+
+public class WebAppManager
+{
+ private Process _webApiProcess;
+ private List<string> _webApiErrors = new();
+ private Process _blazorWasmProcess;
+ private List<string> _blazorWasmErrors = new();
+
+ private string GetBaseDirectory()
+ {
+ string currentDir = Directory.GetCurrentDirectory();
+ // Adjust this if your solution directory is different
+ string baseDir = Directory.GetParent(currentDir).Parent.Parent.FullName;
+ return baseDir;
+ }
+
+ private void KillExistingProcesses(string uniqueIdentifier)
+ {
+ var existingProcesses = Process.GetProcessesByName("dotnet")
+ .Where(p => GetCommandLineArgs(p).Contains(uniqueIdentifier));
+
+ foreach (var process in existingProcesses)
+ {
+ try
+ {
+ process.Kill();
+ process.WaitForExit();
+ TestContext.Progress.WriteLine($"Killed existing process with PID: {process.Id}");
+ }
+ catch (Exception ex)
+ {
+ TestContext.Progress.WriteLine($"Failed to kill process with PID: {process.Id}, Error: {ex.Message}");
+ }
+ }
+ }
+
+ private string GetCommandLineArgs(Process process)
+ {
+#if WINDOWS
+ return GetCommandLineArgsWindows(process);
+#else
+ return GetCommandLineArgsUnix(process);
+#endif
+ }
+
+ private string GetCommandLineArgsWindows(Process process)
+ {
+#if WINDOWS
+
+ try
+ {
+ using (var searcher = new System.Management.ManagementObjectSearcher(
+ $"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {process.Id}"))
+ using (var objects = searcher.Get())
+ {
+ return objects.Cast<System.Management.ManagementBaseObject>()
+ .SingleOrDefault()?["CommandLine"]?.ToString();
+ }
+ }
+ catch
+ {
+ return string.Empty;
+ }
+#else
+ return string.Empty;
+#endif
+ }
+
+ private string GetCommandLineArgsUnix(Process process)
+ {
+ try
+ {
+ string path = $"/proc/{process.Id}/cmdline";
+ return File.Exists(path) ? File.ReadAllText(path).Replace('\0', ' ') : string.Empty;
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+
+ public async Task StartWebApiAsync(int port)
+ {
+ var projectPath = $"{GetBaseDirectory()}/../../AliasVault.Api/AliasVault.Api.csproj";
+ KillExistingProcesses("AliasVaultWebApiIdentifier");
+
+ _webApiProcess = new Process
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ FileName = "dotnet",
+ Arguments = $"run --project {projectPath} --urls=http://localhost:{port} AliasVaultWebApiIdentifier",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
+
+ _webApiProcess.OutputDataReceived += (sender, args) =>
+ {
+ TestContext.Progress.WriteLine("WebAPI: " + args.Data);
+ if (args.Data != null && args.Data.Contains("error"))
+ {
+ _webApiErrors.Add(args.Data);
+ }
+ };
+ _webApiProcess.ErrorDataReceived += (sender, args) =>
+ {
+ if (args.Data != null && !string.IsNullOrEmpty(args.Data))
+ {
+ _webApiErrors.Add(args.Data);
+ }
+ };
+
+ try
+ {
+ _webApiProcess.Start();
+ _webApiProcess.BeginOutputReadLine();
+ _webApiProcess.BeginErrorReadLine();
+ TestContext.Progress.WriteLine("WebAPI process started, waiting for startup...");
+
+ await WaitForStartupAsync(port);
+ TestContext.Progress.WriteLine("WebAPI started successfully.");
+ }
+ catch (Exception ex)
+ {
+ TestContext.Progress.WriteLine($"Failed to start WebAPI: {ex.Message}");
+ }
+ }
+
+ public async Task StartBlazorWasmAsync(int port)
+ {
+ var projectPath = $"{GetBaseDirectory()}/../../AliasVault.WebApp/AliasVault.WebApp.csproj";
+ KillExistingProcesses("AliasVaultWasmAppIdentifier");
+
+ _blazorWasmProcess = new Process
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ FileName = "dotnet",
+ Arguments = $"run --project {projectPath} --urls=http://localhost:{port} AliasVaultWasmAppIdentifier",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ }
+ };
+
+ _blazorWasmProcess.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
+ _blazorWasmProcess.ErrorDataReceived += (sender, args) =>
+ {
+ _blazorWasmErrors.Add(args.Data);
+
+ };
+
+ _blazorWasmProcess.Start();
+ _blazorWasmProcess.BeginOutputReadLine();
+ _blazorWasmProcess.BeginErrorReadLine();
+
+ await WaitForStartupAsync(port);
+ }
+
+ private async Task WaitForStartupAsync(int port)
+ {
+ // Wait for the application to start up
+ var started = false;
+ while (!started)
+ {
+ try
+ {
+ using (var client = new HttpClient())
+ {
+ var response = await client.GetAsync($"http://localhost:{port}");
+ started = response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.NotFound;
+ }
+ }
+ catch (Exception e)
+ {
+ if (_webApiErrors != null && _webApiErrors.Count > 0)
+ {
+ // Concatenate all errors and fail the test
+ Assert.Fail($"WebAPI failed to start: {string.Join(Environment.NewLine, _webApiErrors)}");
+ return;
+ }
+ if (_blazorWasmErrors != null && _blazorWasmErrors.Count > 0)
+ {
+ Assert.Fail($"WASM failed to start: {string.Join(Environment.NewLine, _webApiErrors)}");
+ return;
+ }
+
+ Console.WriteLine(e.Message);
+ await Task.Delay(500);
+ }
+ }
+ }
+
+ public void StopWebApi()
+ {
+ if (_webApiProcess != null && !_webApiProcess.HasExited)
+ {
+ _webApiProcess.Kill();
+ _webApiProcess.Dispose();
+ }
+ }
+
+ public void StopBlazorWasm()
+ {
+ if (_blazorWasmProcess != null && !_blazorWasmProcess.HasExited)
+ {
+ _blazorWasmProcess.Kill();
+ _blazorWasmProcess.Dispose();
+ }
+ }
+}