Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Fix existing tests (#306)
Leendert de Borstc5ccde298fcf
diff --git a/src/AliasVault.Api/Controllers/AuthController.cs b/src/AliasVault.Api/Controllers/AuthController.csindex affa5f403..8d760285f 100644--- a/src/AliasVault.Api/Controllers/AuthController.cs+++ b/src/AliasVault.Api/Controllers/AuthController.cs@@ -464,6 +464,21 @@ public class AuthController(IDbContextFactory<AliasServerDbContext> dbContextFacreturn (false, "Username 'admin' is not allowed.");}+ // Check if it's a valid email address+ if (username.Contains('@'))+ {+ try+ {+ var addr = new System.Net.Mail.MailAddress(username);+ return (addr.Address == username, string.Empty);+ }+ catch+ {+ return (false, $"'{username}' is not a valid email address.");+ }+ }++ // If it's not an email, check if it only contains letters and digitsif (!username.All(char.IsLetterOrDigit)){return (false, $"Username '{username}' is invalid, can only contain letters or digits.");diff --git a/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.csindex 0ecee2b25..592a00889 100644--- a/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs+++ b/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs@@ -132,9 +132,9 @@ public class ClientPlaywrightTest : PlaywrightTestPage = await Context.NewPageAsync();InputHelper = new(Page);- // Check that we get redirected to /user/login when accessing the root URL and not authenticated.+ // Check that we get redirected to /user/start when accessing the root URL and not authenticated.await Page.GotoAsync(AppBaseUrl);- await WaitForUrlAsync("user/login");+ await WaitForUrlAsync("user/start");// Register a new account here because every test requires this.await Register();@@ -283,8 +283,10 @@ public class ClientPlaywrightTest : PlaywrightTestprotected async Task Login(bool rememberMe = false){// Check that we are on the login page after navigating to the base URL.- // We are expecting to not be authenticated and thus to be redirected to the login page.+ // We are expecting to not be authenticated and thus to be redirected to the start page.await Page.GotoAsync(AppBaseUrl);+ await WaitForUrlAsync("user/start", "Log in with");+ await NavigateUsingBlazorRouter("user/login");await WaitForUrlAsync("user/login", "Your username");// Try to log in with test credentials.@@ -315,7 +317,19 @@ public class ClientPlaywrightTest : PlaywrightTestprotected async Task Logout(){await NavigateUsingBlazorRouter("user/logout");- await WaitForUrlAsync("user/login**", "Sign in to");+ await WaitForUrlAsync("user/start**", "Log in with");+ }++ /// <summary>+ /// Hard refresh and navigate to the login page.+ /// </summary>+ /// <returns>Task.</returns>+ protected async Task NavigateToLogin()+ {+ await Page.GotoAsync(AppBaseUrl);+ await WaitForUrlAsync("user/start", "Log in with");+ await NavigateUsingBlazorRouter("user/login");+ await WaitForUrlAsync("user/login", "Your username");}/// <summary>@@ -344,8 +358,7 @@ public class ClientPlaywrightTest : PlaywrightTestprotected async Task Register(bool checkForSuccess = true, string? username = null, string? password = null){// Try to register a new account.- var registerButton = await WaitForAndGetElement("a[href='/user/register']");- await registerButton.ClickAsync();+ await NavigateUsingBlazorRouter("user/register");await WaitForUrlAsync("user/register");// Try to register an account with the generated test credentials.diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.csindex bcc83b981..b3bd432da 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs@@ -179,6 +179,7 @@ public class EmailDecryptionTests : ClientPlaywrightTest// Assert that the claim was created on the server.var claim = await ApiDbContext.UserEmailClaims.FirstOrDefaultAsync(x => x.Address == email);+ Assert.That(claim, Is.Not.Null, "Claim for email address not found in database. Check if credential creation and claim creation are working correctly.");// Login as new user.await LogoutAndLoginAsNewUser();diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/CodeLockoutTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/CodeLockoutTests.csindex 971739b27..035680f25 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/CodeLockoutTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/CodeLockoutTests.cs@@ -29,6 +29,7 @@ public class CodeLockoutTests : TwoFactorAuthBaseawait Logout();// Attempt to log in again with test credentials.+ await NavigateUsingBlazorRouter("user/login");await WaitForUrlAsync("user/login", "Your username");// Wait for the page to fully load.diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/RecoveryLockoutTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/RecoveryLockoutTests.csindex 03effef0a..27cd686fd 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/RecoveryLockoutTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/RecoveryLockoutTests.cs@@ -28,9 +28,7 @@ public class RecoveryLockoutTests : TwoFactorAuthBaseawait EnableTwoFactor();await Logout();-- // Attempt to log in again with test credentials.- await WaitForUrlAsync("user/login", "Your username");+ await NavigateToLogin();// Wait for the page to fully load.await Task.Delay(100);diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.csindex d08f09448..82bdc5a13 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs@@ -38,9 +38,7 @@ public class TwoFactorAuthTests : TwoFactorAuthBaseAssert.That(message, Does.Contain("Two-factor authentication is now successfully enabled."), "No success message displayed.");await Logout();-- // Attempt to log in again with test credentials.- await WaitForUrlAsync("user/login", "Your username");+ await NavigateToLogin();// Wait for the page to fully load.await Task.Delay(100);@@ -80,9 +78,7 @@ public class TwoFactorAuthTests : TwoFactorAuthBasevar (_, recoveryCode) = await EnableTwoFactor();await Logout();-- // Attempt to log in again with test credentials.- await WaitForUrlAsync("user/login", "Your username");+ await NavigateToLogin();// Wait for the page to fully load.await Task.Delay(100);diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard4/AuthTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard4/AuthTests.csindex d815acc42..37743ce03 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard4/AuthTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard4/AuthTests.cs@@ -121,6 +121,7 @@ public class AuthTests : ClientPlaywrightTestpublic async Task PasswordAuthLockoutTest(){await Logout();+ await NavigateToLogin();// Fill in wrong password 11 times. After 11 times, the account should be locked.// Note: the actual lockout happens on the 10th wrong attempt, but the lockout message is only displayed