Skip to content

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

Update client e2e tests (#2159)

Leendert de Borst256ee40064b1
diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.cs
index de0a69670..664eb7d1e 100644
--- a/apps/server/AliasVault.Client/Services/ItemService.cs
+++ b/apps/server/AliasVault.Client/Services/ItemService.cs
@@ -223,6 +223,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
// Set timestamps on attachments
foreach (var attachment in item.Attachments)
{
+ attachment.Id = attachment.Id == Guid.Empty ? Guid.NewGuid() : attachment.Id;
attachment.ItemId = item.Id;
SetInsertTimestamps(attachment, currentDateTime);
}
@@ -230,6 +231,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
// Set timestamps on TOTP codes
foreach (var totpCode in item.TotpCodes)
{
+ totpCode.Id = totpCode.Id == Guid.Empty ? Guid.NewGuid() : totpCode.Id;
totpCode.ItemId = item.Id;
SetInsertTimestamps(totpCode, currentDateTime);
}
@@ -237,6 +239,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
// Set timestamps on passkeys
foreach (var passkey in item.Passkeys)
{
+ passkey.Id = passkey.Id == Guid.Empty ? Guid.NewGuid() : passkey.Id;
passkey.ItemId = item.Id;
SetInsertTimestamps(passkey, currentDateTime);
}
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/ApiTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/ApiTests.cs
index 9f30dce4a..92ed9f921 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/ApiTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/ApiTests.cs
@@ -31,6 +31,17 @@ public class ApiTests : ClientPlaywrightTest
await base.OneTimeSetUp();
}
+ /// <summary>
+ /// Reset the environment variables so later fixtures in the same process get the default.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [OneTimeTearDown]
+ public override async Task OneTimeTearDown()
+ {
+ Environment.SetEnvironmentVariable("IP_LOGGING_ENABLED", null);
+ await base.OneTimeTearDown();
+ }
+
/// <summary>
/// Test if an error in the API is logged to the database.
/// </summary>
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
index de73b5056..21324a0bc 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
@@ -207,17 +207,8 @@ public class EmailDecryptionTests : ClientPlaywrightTest
var emailReceived = await ApiDbContext.Emails.FirstOrDefaultAsync(x => x.To == email);
Assert.That(emailReceived, Is.Not.Null, "Email not received by server. Check SMTP server and email encryption/decryption logic.");
- // Assert that the attachment is stored in the database.
- var attachmentReceived = await ApiDbContext.EmailAttachments.FirstOrDefaultAsync(x => x.EmailId == emailReceived.Id);
- Assert.That(attachmentReceived, Is.Not.Null, "Attachment not found in database. Check email attachment encryption logic.");
-
- // Assert that the attachment content is encrypted
- var attachmentContent = Encoding.UTF8.GetString(attachmentReceived!.Bytes);
- Assert.Multiple(() =>
- {
- Assert.That(attachmentContent, Does.Not.Contain("This is an attachment."), "Attachment content stored as plain text in database. Check attachment encryption logic.");
- Assert.That(attachmentContent, Is.Not.Empty, "Attachment content is empty. Check attachment encryption logic.");
- });
+ // Small attachments stay inline in the encrypted message source, only large ones are stored as separate parts.
+ Assert.That(emailReceived!.AttachmentCount, Is.EqualTo(1), "Attachment count not stored on the email. Check email attachment logic.");
// Assert that subject is not stored as plain text in the database.
Assert.That(emailReceived!.Subject, Does.Not.Contain(textSubject), "Email subject stored as plain text in database. Check email encryption logic.");
@@ -257,8 +248,7 @@ public class EmailDecryptionTests : ClientPlaywrightTest
Assert.That(body, Does.Contain("attachment.txt"), "Attachment metadata not visible in email modal. Check email attachment parse logic.");
// Assert that clicking on the attachment link downloads it.
- await Page.Locator(".attachment-link").First.ClickAsync();
- var download = await Page.WaitForDownloadAsync();
+ var download = await Page.RunAndWaitForDownloadAsync(() => Page.Locator(".attachment-link").First.ClickAsync());
// Get the path of the downloaded file
var downloadedFilePath = await download.PathAsync();
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbPersistTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbPersistTests.cs
index 5e60500f8..b9a3ff9de 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbPersistTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbPersistTests.cs
@@ -59,14 +59,14 @@ public class DbPersistTests : ClientPlaywrightTest
// Assert that the vault revision number is 2 in the server database.
// Account registration will create a new vault with revision number 1, first item save will increment to 2.
// Note: for this we expect the previous test to have run first and created a first item.
- var firstUpdateVault = await ApiDbContext.VaultManifests.OrderByDescending(x => x.RevisionNumber).FirstAsync();
+ var firstUpdateVault = await ApiDbContext.VaultManifests.AsNoTracking().OrderByDescending(x => x.RevisionNumber).FirstAsync();
Assert.That(firstUpdateVault.RevisionNumber, Is.EqualTo(2), "Vault revision number is not at 2 after creating the first item in a new vault.");
// Create a new item which will trigger a vault save to the server.
await CreateItemEntry();
// Assert that the vault revision number is now 3 in the server database.
- var secondUpdateVault = await ApiDbContext.VaultManifests.OrderByDescending(x => x.RevisionNumber).FirstAsync();
+ var secondUpdateVault = await ApiDbContext.VaultManifests.AsNoTracking().OrderByDescending(x => x.RevisionNumber).FirstAsync();
Assert.That(secondUpdateVault.RevisionNumber, Is.EqualTo(3), "Vault revision number is not 3 after the second item save.");
}
}
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 28b1af681..5ccdeb95e 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbSyncTests.cs
@@ -140,72 +140,6 @@ public class DbSyncTests : ClientPlaywrightTest
}
}
- /// <summary>
- /// Test that merge between two vaults where one has changed the password results in an error.
- /// </summary>
- /// <returns>Async task.</returns>
- [Test]
- [Order(3)]
- public async Task DbSyncClientMergePasswordChangeErrorTest()
- {
- var baselineVault = await CreateBaselineVault(async () =>
- {
- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestBaseline" } });
- });
-
- var client1Vault = await SimulateClient(baselineVault, async () =>
- {
- await NavigateUsingBlazorRouter("items");
- await WaitForUrlAsync("items", "Find all of your items");
-
- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestA" } });
-
- // Attempt to change password.
- await NavigateUsingBlazorRouter("settings/security/change-password");
- await WaitForUrlAsync("settings/security/change-password", "Current Password");
-
- // Fill in the form.
- var currentPasswordField = Page.Locator("input[id='currentPassword']");
- var newPasswordField = Page.Locator("input[id='newPassword']");
- var confirmPasswordField = Page.Locator("input[id='newPasswordConfirm']");
-
- var newPassword = TestUserPassword + "123";
-
- await currentPasswordField.FillAsync(TestUserPassword);
- await newPasswordField.FillAsync(newPassword);
- await confirmPasswordField.FillAsync(newPassword);
-
- // Advance time by 1 second manually to ensure the new vault (encrypted with new password) is created in the future.
- ApiTimeProvider.AdvanceBy(TimeSpan.FromSeconds(1));
-
- // Click the change password button.
- var changePasswordButton = Page.Locator("button:has-text('Change Password')");
- await changePasswordButton.ClickAsync();
-
- // Wait for success message.
- await WaitForUrlAsync("settings/security/change-password**", "Password changed successfully.");
- });
-
- await SimulateClient(baselineVault, async () =>
- {
- // Restore client1's vault state as the server's current revision to simulate a conflict when
- // this second client updates the same vault.
- await RestoreServerVault(client1Vault);
-
- await NavigateUsingBlazorRouter("items");
- await WaitForUrlAsync("items", "Find all of your items");
-
- await CreateItemEntry(new Dictionary<string, string> { { "service-name", "TestB" } }, null, false);
-
- // Wait for 1 second to ensure the page is loaded.
- await Task.Delay(1000);
- });
-
- // Assert that merge failed error message is shown.
- var pageContent = await Page.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain("An unknown error occurred."), $"Merge failed error expected after another client changed the password but no error message found.");
- }
-
/// <summary>
/// Create a baseline vault.
/// </summary>
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
index 4fb09d9fd..f5213e3f5 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
@@ -45,6 +45,12 @@ public class DbUpgradeTests : ClientPlaywrightTest
// Update the user's SrpIdentity to match what the old vault expects (lowercase username).
var user = ApiDbContext.AliasVaultUsers.First();
user.SrpIdentity = TestUserUsername.ToLowerInvariant();
+
+ // Remove v2 key material so login falls back to the legacy salt/verifier on the vault row,
+ // as it would for an account that predates the unlock-key model.
+ ApiDbContext.UserUnlockKeys.RemoveRange(ApiDbContext.UserUnlockKeys.Where(x => x.UserId == user.Id));
+ ApiDbContext.UserGrantKeys.RemoveRange(ApiDbContext.UserGrantKeys.Where(x => x.UserId == user.Id));
+ ApiDbContext.VaultManifestAccessKeys.RemoveRange(ApiDbContext.VaultManifestAccessKeys.Where(x => x.UserId == user.Id));
await ApiDbContext.SaveChangesAsync();
// Overwrite the user's current vault with the static 1.0.0 vault (the current row is updated in place;
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
index a5622c156..d345c3dec 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
@@ -74,7 +74,7 @@ public class ResetVaultTests : ClientPlaywrightTest
await WaitForUrlAsync("items", "successfully reset");
// Check API that the latest vault has no items.
- var latestVault = await ApiDbContext.VaultManifests.Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
+ var latestVault = await ApiDbContext.VaultManifests.AsNoTracking().Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
Assert.That(latestVault.CredentialsCount, Is.EqualTo(0), "Latest vault should have no items after reset.");
// Create a new item entry.
@@ -87,7 +87,7 @@ public class ResetVaultTests : ClientPlaywrightTest
});
// Check that the now latest vault has one item, and only one active claimed alias.
- latestVault = await ApiDbContext.VaultManifests.Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
+ latestVault = await ApiDbContext.VaultManifests.AsNoTracking().Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
Assert.Multiple(() =>
{
Assert.That(latestVault.CredentialsCount, Is.EqualTo(1), "Latest vault should have one item after reset.");
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs
index 44ee7bea0..a4b4a60d4 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs
@@ -30,7 +30,7 @@ public class UnlockTests : ClientPlaywrightTest
await RefreshPageAndUnlockVault();
// Check if we get redirected back to the page we were trying to access.
- await WaitForUrlAsync(startUrl, "Test webapi call 1");
+ await WaitForUrlAsync(startUrl, "Test 1 OK.");
var pageContent = await Page.TextContentAsync("body");
Assert.That(pageContent, Does.Contain("Test 1 OK."), "No index content after unlocking database.");
@@ -69,7 +69,7 @@ public class UnlockTests : ClientPlaywrightTest
await submitButton.ClickAsync();
// Check if we get redirected back to the page we were trying to access.
- await WaitForUrlAsync(startUrl, "Test webapi call 1");
+ await WaitForUrlAsync(startUrl, "Test 1 OK.");
var pageContent = await Page.TextContentAsync("body");
Assert.That(pageContent, Does.Contain("Test 1 OK."), "No index content after unlocking database.");