Skip to content

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

Fix vault mutate tests (#1473)

Leendert de Borst69b43d51b5a8
diff --git a/apps/server/AliasVault.Client/Main/Layout/DbStatusIndicator.razor b/apps/server/AliasVault.Client/Main/Layout/DbStatusIndicator.razor
index a0844bb5b..d42b681ff 100644
--- a/apps/server/AliasVault.Client/Main/Layout/DbStatusIndicator.razor
+++ b/apps/server/AliasVault.Client/Main/Layout/DbStatusIndicator.razor
@@ -3,7 +3,7 @@
@inject DbService DbService
@inject IStringLocalizerFactory LocalizerFactory
-<div class="ms-1 items-center flex">
+<div class="ms-1 items-center flex" id="vault-sync-indicator" data-syncing="@IsSyncing.ToString().ToLowerInvariant()">
<SmallLoadingIndicator Title="@GetStatusTitle()" Spinning="@IsSyncing">
@if (!IsSyncing)
{
diff --git a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs
index 0592776c7..dfde635ba 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs
@@ -235,6 +235,8 @@ public class ClientPlaywrightTest : PlaywrightTest
// 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
+ // 3. Modify formValues to only contain the local part (prefix) of the email
+ // 4. Select the correct domain if it's not the default one
if (formValues != null && formValues.TryGetValue("email", out var emailValue) && IsPrivateEmailDomain(emailValue))
{
// Click the "+ Email" button to add the email field section
@@ -251,6 +253,34 @@ public class ClientPlaywrightTest : PlaywrightTest
// 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 });
+
+ // Wait for the email input to be populated with a generated value (the component generates a random prefix)
+ await Page.WaitForFunctionAsync(
+ "() => document.querySelector('input#email')?.value?.length > 0",
+ null,
+ new() { Timeout = 5000 });
+
+ // Extract the local part and domain from the email address
+ var parts = emailValue.Split('@');
+ var localPart = parts[0];
+ var domain = parts[1];
+
+ // Check if we need to select a different domain (click on domain button to show popup, then select)
+ var currentDomainButton = Page.Locator("button:has-text('@')").First;
+ var currentDomainText = await currentDomainButton.TextContentAsync();
+ if (currentDomainText != null && !currentDomainText.Contains(domain))
+ {
+ // Click to open domain popup
+ await currentDomainButton.ClickAsync();
+
+ // Wait for popup and select the correct domain
+ await Page.WaitForSelectorAsync($"button:has-text('{domain}')", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });
+ await Page.Locator($"button:has-text('{domain}')").First.ClickAsync();
+ }
+
+ // Update formValues to only contain the local part (prefix) since the input in Alias mode
+ // only expects the prefix. If we pass the full email, the component will switch back to Email mode.
+ formValues["email"] = localPart;
}
// Fill all input fields with specified values and remaining empty fields with random data.
@@ -299,6 +329,37 @@ public class ClientPlaywrightTest : PlaywrightTest
// Wait for the edit item page to load.
await WaitForUrlAsync("items/**/edit", "Edit the existing item");
+ // If email field is specified with a private email domain, we need to handle Alias mode specially.
+ // When updating, if the item already has a private email, the email field will be in Alias mode.
+ // In Alias mode, the input only expects the local part (prefix), not the full email.
+ if (formValues != null && formValues.TryGetValue("email", out var emailValue) && IsPrivateEmailDomain(emailValue))
+ {
+ // Check if we're in Alias mode (domain suffix button is visible)
+ var domainButton = Page.Locator("button:has-text('@')");
+ if (await domainButton.CountAsync() > 0)
+ {
+ // Extract the local part and domain from the email address
+ var parts = emailValue.Split('@');
+ var localPart = parts[0];
+ var domain = parts[1];
+
+ // Check if we need to select a different domain
+ var currentDomainText = await domainButton.First.TextContentAsync();
+ if (currentDomainText != null && !currentDomainText.Contains(domain))
+ {
+ // Click to open domain popup
+ await domainButton.First.ClickAsync();
+
+ // Wait for popup and select the correct domain
+ await Page.WaitForSelectorAsync($"button:has-text('{domain}')", new() { State = WaitForSelectorState.Visible, Timeout = 5000 });
+ await Page.Locator($"button:has-text('{domain}')").First.ClickAsync();
+ }
+
+ // Update formValues to only contain the local part (prefix)
+ formValues["email"] = localPart;
+ }
+ }
+
// Fill all input fields with specified values and remaining empty fields with random data.
await InputHelper.FillInputFields(formValues);
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs
index 69ba0d788..4a23db00f 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs
@@ -79,17 +79,18 @@ public class DbSyncTests : ClientPlaywrightTest
[Order(2)]
public async Task DbSyncClientMergeCredentialPropertiesTest()
{
+ // Use unique prefix "PropTest" to avoid conflicts with other tests in this class
var baselineVault = await CreateBaselineVault(async () =>
{
- 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]" } });
+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "PropTestBaseline1" }, { "username", "propuser1" }, { "email", "[email protected]" } });
+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "PropTestBaseline2" }, { "username", "propuser2" }, { "email", "[email protected]" } });
+ await CreateItemEntry(new Dictionary<string, string> { { "service-name", "PropTestBaseline3" }, { "username", "propuser3" }, { "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", "[email protected]" } });
+ await UpdateItemEntry("PropTestBaseline2", new Dictionary<string, string> { { "service-name", "PropTestMutate2" }, { "username", "propmutate2" }, { "email", "[email protected]" } });
});
// Then client 2 updates the same vault causing a conflict and requiring a client-side merge.
@@ -100,7 +101,7 @@ public class DbSyncTests : ClientPlaywrightTest
ApiDbContext.Vaults.Add(client1Vault);
await ApiDbContext.SaveChangesAsync();
- await UpdateItemEntry("TestBaseline3", new Dictionary<string, string> { { "service-name", "TestBaseMutate3" }, { "username", "usermutate3" }, { "email", "[email protected]" } });
+ await UpdateItemEntry("PropTestBaseline3", new Dictionary<string, string> { { "service-name", "PropTestMutate3" }, { "username", "propmutate3" }, { "email", "[email protected]" } });
});
// Then another client updates the client 1 vault again, which should also cause a conflict with the client 2 vault update.
@@ -112,14 +113,14 @@ public class DbSyncTests : ClientPlaywrightTest
await ApiDbContext.SaveChangesAsync();
// Update username to test that field-level merge works correctly.
- await UpdateItemEntry("TestBaseMutate2", new Dictionary<string, string> { { "service-name", "TestBaseMutate23" }, { "username", "usermutate23" } });
+ await UpdateItemEntry("PropTestMutate2", new Dictionary<string, string> { { "service-name", "PropTestMutate23" }, { "username", "propmutate23" } });
});
// Assert that the two conflicting vaults have been merged and all mutated field values are found.
Dictionary<string, List<string>> expectedStrings = new()
{
- { "TestBaseMutate23", new List<string> { "usermutate23", "[email protected]" } },
- { "TestBaseMutate3", new List<string> { "usermutate3", "[email protected]" } },
+ { "PropTestMutate23", new List<string> { "propmutate23", "[email protected]" } },
+ { "PropTestMutate3", new List<string> { "propmutate3", "[email protected]" } },
};
foreach (var serviceName in expectedStrings)