Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor tests (#1473)
Leendert de Borst9c8543c361eb
diff --git a/apps/server/AliasVault.Client/Main/Components/Forms/EmailDomainField.razor b/apps/server/AliasVault.Client/Main/Components/Forms/EmailDomainField.razorindex 011f24874..1fb286e75 100644--- a/apps/server/AliasVault.Client/Main/Components/Forms/EmailDomainField.razor+++ b/apps/server/AliasVault.Client/Main/Components/Forms/EmailDomainField.razor@@ -2,6 +2,7 @@@inject JsInteropService JsInteropService@inject IStringLocalizerFactory LocalizerFactory@inject ItemService ItemService+@inject DbService DbService@using Microsoft.Extensions.Localization@using AliasVault.Client.Services.JsInterop.Models@using AliasVault.Client.Main.Models@@ -389,12 +390,18 @@}IsCustomDomain = false;-- // Switching to domain chooser mode- var defaultDomain = ShowPrivateDomains && PrivateDomains.Count > 0- ? PrivateDomains[0]- : (PublicDomains.Count > 0 ? PublicDomains[0] : string.Empty);-++ // Switching to domain chooser mode - use user's configured default domain from settings+ var userDefaultDomain = DbService.Settings.DefaultEmailDomain;+ var allDomains = PrivateDomains.Concat(PublicDomains).ToList();++ // Use user's configured default if it's a valid domain, otherwise fall back to first available+ var defaultDomain = !string.IsNullOrEmpty(userDefaultDomain) && allDomains.Contains(userDefaultDomain)+ ? userDefaultDomain+ : (ShowPrivateDomains && PrivateDomains.Count > 0+ ? PrivateDomains[0]+ : (PublicDomains.Count > 0 ? PublicDomains[0] : string.Empty));+if (!string.IsNullOrEmpty(defaultDomain)){SelectedDomain = defaultDomain;diff --git a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.csindex de334ac16..0592776c7 100644--- a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs@@ -231,6 +231,28 @@ public class ClientPlaywrightTest : PlaywrightTestvar generateButton = Page.Locator("text=Generate Random Alias");Assert.That(generateButton, Is.Not.Null, "Generate button not found.");+ // Check if email field is specified with a private email domain (alias).+ // In that case we need to:+ // 1. Click "+ Email" button to add the email field (for Login type items)+ // 2. Switch from "Email" mode to "Alias" mode+ if (formValues != null && formValues.TryGetValue("email", out var emailValue) && IsPrivateEmailDomain(emailValue))+ {+ // Click the "+ Email" button to add the email field section+ var addEmailButton = Page.Locator("button:has-text('Email')").First;+ await addEmailButton.ClickAsync();++ // Wait for the email field to appear+ await Page.WaitForSelectorAsync("input#email", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });++ // Click the "Alias" button to switch from "Email" mode to "Alias" mode.+ // This will also generate a random email prefix.+ var aliasButton = Page.Locator("button:has-text('Alias')").First;+ await aliasButton.ClickAsync();++ // Wait for the alias mode to be active (the input should now show a domain suffix button)+ await Page.WaitForSelectorAsync("button:has-text('@')", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });+ }+// Fill all input fields with specified values and remaining empty fields with random data.await InputHelper.FillInputFields(formValues);await InputHelper.FillEmptyInputFieldsWithRandom();@@ -479,4 +501,23 @@ public class ClientPlaywrightTest : PlaywrightTest// Wait for "Find all of your items below" message to appear.await WaitForUrlAsync("items**", "Find all of your items below");}++ /// <summary>+ /// Checks if the email address belongs to a private email domain configured for this test environment.+ /// </summary>+ /// <param name="email">The email address to check.</param>+ /// <returns>True if the email is from a private domain (example.tld, example2.tld).</returns>+ private static bool IsPrivateEmailDomain(string email)+ {+ if (string.IsNullOrEmpty(email) || !email.Contains('@'))+ {+ return false;+ }++ var domain = email.Split('@')[1].ToLowerInvariant();++ // These are the private email domains configured in SetupEnvironment()+ string[] privateDomains = ["example.tld", "example2.tld", "disabled.tld"];+ return privateDomains.Contains(domain);+ }}diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/GeneralSettingsTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/GeneralSettingsTests.csindex 881764d63..f6f49d41e 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/GeneralSettingsTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/GeneralSettingsTests.cs@@ -37,6 +37,20 @@ public class GeneralSettingsTests : ClientPlaywrightTestawait NavigateUsingBlazorRouter("items/create");await WaitForUrlAsync("items/create", "Add Item");+ // Click the "+ Email" button to add the email field section (not shown by default for Login type).+ var addEmailButton = Page.Locator("button:has-text('Email')").First;+ await addEmailButton.ClickAsync();++ // Wait for the email field to appear.+ await Page.WaitForSelectorAsync("input#email", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });++ // Click the "Alias" button to switch from "Email" mode to "Alias" mode.+ var aliasButton = Page.Locator("button:has-text('Alias')").First;+ await aliasButton.ClickAsync();++ // Wait for the alias mode to be active (the input should now show a domain suffix button).+ await Page.WaitForSelectorAsync("button:has-text('@')", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });+var defaultEmailDomainText = await Page.TextContentAsync("body");Assert.That(defaultEmailDomainText, Does.Contain("example2.tld"), "Default email domain not visible on add item page.");}diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.csindex 233d0c4aa..69ba0d788 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs@@ -81,15 +81,15 @@ public class DbSyncTests : ClientPlaywrightTest{var baselineVault = await CreateBaselineVault(async () =>{- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline1" }, { "username", "user1" }, { "email", "email1" } });- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline2" }, { "username", "user2" }, { "email", "email2" } });- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline3" }, { "username", "user3" }, { "email", "email3" } });+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline1" }, { "username", "user1" }, { "email", "[email protected]" } });+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline2" }, { "username", "user2" }, { "email", "[email protected]" } });+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline3" }, { "username", "user3" }, { "email", "[email protected]" } });});// Client 1 updates the vault first.var client1Vault = await SimulateClient(baselineVault, async () =>{- await UpdateItemEntry("TestBaseline2", new Dictionary<string, string> { { "service-name", "TestBaseMutate2" }, { "username", "usermutate2" }, { "email", "emailmutate2" } });+ await UpdateItemEntry("TestBaseline2", new Dictionary<string, string> { { "service-name", "TestBaseMutate2" }, { "username", "usermutate2" }, { "email", "[email protected]" } });});// Then client 2 updates the same vault causing a conflict and requiring a client-side merge.@@ -100,7 +100,7 @@ public class DbSyncTests : ClientPlaywrightTestApiDbContext.Vaults.Add(client1Vault);await ApiDbContext.SaveChangesAsync();- await UpdateItemEntry("TestBaseline3", new Dictionary<string, string> { { "service-name", "TestBaseMutate3" }, { "username", "usermutate3" }, { "email", "emailmutate3" } });+ await UpdateItemEntry("TestBaseline3", new Dictionary<string, string> { { "service-name", "TestBaseMutate3" }, { "username", "usermutate3" }, { "email", "[email protected]" } });});// Then another client updates the client 1 vault again, which should also cause a conflict with the client 2 vault update.diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.csindex 0f4377edd..6eb810a89 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs@@ -35,8 +35,10 @@ public class ResetVaultTests : ClientPlaywrightTestApiTimeProvider.AdvanceBy(TimeSpan.FromSeconds(1));var randomServiceName = $"Item service {i}";+ var randomEmail = $"email-{i}@example.tld";await CreateItemEntry(new Dictionary<string, string>{+ { "email", randomEmail },{ "service-name", randomServiceName },});@@ -77,8 +79,10 @@ public class ResetVaultTests : ClientPlaywrightTest// Create a new item entry.var serviceName = "Item service after reset";+ var email = $"[email protected]";await CreateItemEntry(new Dictionary<string, string>{+ { "email", email },{ "service-name", serviceName },});