Skip to content

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

Update .NET e2e tests for browser extension integration tests (#1404)

Leendert de Borst741789f40f2a
diff --git a/apps/browser-extension/src/entrypoints/popup/utils/SrpUtility.ts b/apps/browser-extension/src/entrypoints/popup/utils/SrpUtility.ts
index c492ccda5..7217ae998 100644
--- a/apps/browser-extension/src/entrypoints/popup/utils/SrpUtility.ts
+++ b/apps/browser-extension/src/entrypoints/popup/utils/SrpUtility.ts
@@ -57,22 +57,28 @@ class SrpUtility {
): Promise<ValidateLoginResponse> {
const normalizedUsername = SrpAuthService.normalizeUsername(username);
+ /*
+ * Use srpIdentity from server response if available, otherwise fall back to normalized username.
+ * @todo Remove fallback after 0.26.0+ has been released.
+ */
+ const srpIdentity = loginResponse.srpIdentity ?? normalizedUsername;
+
// Generate client ephemeral
const clientEphemeral = SrpAuthService.generateEphemeral();
- // Derive private key
+ // Derive private key using srpIdentity (not the typed username)
const privateKey = SrpAuthService.derivePrivateKey(
loginResponse.salt,
- normalizedUsername,
+ srpIdentity,
passwordHashString
);
- // Derive session
+ // Derive session using srpIdentity (not the typed username)
const session = SrpAuthService.deriveSession(
clientEphemeral.secret,
loginResponse.serverEphemeral,
loginResponse.salt,
- normalizedUsername,
+ srpIdentity,
privateKey
);
@@ -114,22 +120,28 @@ class SrpUtility {
): Promise<ValidateLoginResponse> {
const normalizedUsername = SrpAuthService.normalizeUsername(username);
+ /*
+ * Use srpIdentity from server response if available, otherwise fall back to normalized username.
+ * @todo Remove fallback after 0.26.0+ has been released.
+ */
+ const srpIdentity = loginResponse.srpIdentity ?? normalizedUsername;
+
// Generate client ephemeral
const clientEphemeral = SrpAuthService.generateEphemeral();
- // Derive private key
+ // Derive private key using srpIdentity (not the typed username)
const privateKey = SrpAuthService.derivePrivateKey(
loginResponse.salt,
- normalizedUsername,
+ srpIdentity,
passwordHashString
);
- // Derive session
+ // Derive session using srpIdentity (not the typed username)
const session = SrpAuthService.deriveSession(
clientEphemeral.secret,
loginResponse.serverEphemeral,
loginResponse.salt,
- normalizedUsername,
+ srpIdentity,
privateKey
);
diff --git a/apps/browser-extension/src/utils/auth/SrpAuthService.ts b/apps/browser-extension/src/utils/auth/SrpAuthService.ts
index 6ed53c404..d5ee0f83b 100644
--- a/apps/browser-extension/src/utils/auth/SrpAuthService.ts
+++ b/apps/browser-extension/src/utils/auth/SrpAuthService.ts
@@ -347,9 +347,9 @@ export class SrpAuthService {
const loginResponse = (await initiateResponse.json()) as LoginResponse;
- /**
+ /*
* Use srpIdentity from server response if available, otherwise fall back to normalized username.
- * Note: the fallback can be removed in the future after 0.26.0+ is deployed.
+ * @todo Remove fallback after 0.26.0+ has been released.
*/
const srpIdentity = loginResponse.srpIdentity ?? normalizedUsername;
diff --git a/apps/server/Tests/AliasVault.E2ETests/Common/BrowserExtensionPlaywrightTest.cs b/apps/server/Tests/AliasVault.E2ETests/Common/BrowserExtensionPlaywrightTest.cs
index d53b1e7d9..49dc43add 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Common/BrowserExtensionPlaywrightTest.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Common/BrowserExtensionPlaywrightTest.cs
@@ -75,7 +75,7 @@ public class BrowserExtensionPlaywrightTest : ClientPlaywrightTest
try
{
// Try to find an element that's only visible when logged in
- await extensionPopup.WaitForSelectorAsync("text=Vault", new() { Timeout = 500 });
+ await extensionPopup.WaitForSelectorAsync("text=Items", new() { Timeout = 500 });
// If we get here, we're already logged in
return extensionPopup;
@@ -108,7 +108,12 @@ public class BrowserExtensionPlaywrightTest : ClientPlaywrightTest
// Wait for login to complete by waiting for expected text.
if (waitForLogin)
{
+ // Wait for bottom navigation to appear (indicates login completed)
await extensionPopup.WaitForSelectorAsync("text=Vault");
+
+ // Also wait for the items list container to be visible,
+ // indicating the vault has loaded and rendered
+ await extensionPopup.WaitForSelectorAsync("#items-list", new() { Timeout = 15000 });
}
return extensionPopup;
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
index 56e8988ca..b670a265f 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
@@ -7,8 +7,6 @@
namespace AliasVault.E2ETests.Tests.Extensions;
-using Microsoft.EntityFrameworkCore;
-
/// <summary>
/// End-to-end tests for the Chrome extension.
/// </summary>
@@ -18,7 +16,7 @@ using Microsoft.EntityFrameworkCore;
public class ChromeExtensionTests : BrowserExtensionPlaywrightTest
{
/// <summary>
- /// Tests if the extension can load a vault and a previously created credential entry is present.
+ /// Tests if the extension can load a vault created by the Blazor web app and a previously created item entry is present.
/// </summary>
/// <returns>Async task.</returns>
[Order(1)]
@@ -35,86 +33,11 @@ public class ChromeExtensionTests : BrowserExtensionPlaywrightTest
var extensionPopup = await LoginToExtension();
// Assert extension loaded vault successfully and service name is present.
- await extensionPopup.WaitForSelectorAsync("text=" + serviceName);
+ await extensionPopup.WaitForSelectorAsync("text=" + serviceName, new() { Timeout = 15000 });
var pageContent = await extensionPopup.TextContentAsync("body");
Assert.That(pageContent, Does.Contain(serviceName));
}
- /// <summary>
- /// Tests if the extension can unlock and access the vault when the server is offline.
- /// This verifies the offline mode functionality where the vault is stored locally
- /// and can be decrypted using stored encryption parameters.
- /// </summary>
- /// <returns>Async task.</returns>
- [Order(2)]
- [Test]
- public async Task ExtensionOfflineUnlockTest()
- {
- // Step 1: Create a credential via the client app
- var serviceName = "Offline Test Credential";
- await CreateItemEntry(new Dictionary<string, string>
- {
- { "service-name", serviceName },
- });
-
- // Step 2: Login to the extension (this stores vault and encryption params locally)
- var extensionPopup = await LoginToExtension();
-
- // Verify the credential is visible after login
- await extensionPopup.WaitForSelectorAsync("text=" + serviceName);
- var pageContent = await extensionPopup.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain(serviceName), "Credential should be visible after initial login");
-
- // Step 3: Close the extension popup (simulates session end where encryption key is lost)
- await extensionPopup.CloseAsync();
-
- // Step 4: Block all API requests to simulate server being offline
- // This intercepts all requests to the API and returns a network error
- await Context.RouteAsync(
- $"**{ApiBaseUrl.TrimEnd('/')}/**",
- async route =>
- {
- await route.AbortAsync("connectionrefused");
- });
-
- // Also block the base API URL without trailing content
- await Context.RouteAsync(
- ApiBaseUrl.TrimEnd('/') + "/*",
- async route =>
- {
- await route.AbortAsync("connectionrefused");
- });
-
- // Step 5: Open a new extension popup (simulating browser restart)
- var extensionId = GetExtensionIdFromContext();
- var offlineExtensionPopup = await Context.NewPageAsync();
- await offlineExtensionPopup.GotoAsync($"chrome-extension://{extensionId}/popup.html");
-
- // Step 6: Wait for the unlock page to appear (vault is locked, session expired)
- // The extension should detect it has a local vault but no encryption key
- await offlineExtensionPopup.WaitForSelectorAsync("text=Unlock", new() { Timeout = 10000 });
-
- // Step 7: Enter password to unlock
- await offlineExtensionPopup.FillAsync("input[type='password']", TestUserPassword);
- await offlineExtensionPopup.ClickAsync("button:has-text('Unlock')");
-
- // Step 8: Verify the vault is unlocked and credential is visible
- // Wait for the credentials list to appear with our test credential
- await offlineExtensionPopup.WaitForSelectorAsync("text=" + serviceName, new() { Timeout = 15000 });
- var offlinePageContent = await offlineExtensionPopup.TextContentAsync("body");
- Assert.That(offlinePageContent, Does.Contain(serviceName), "Credential should be visible after offline unlock");
-
- // Step 9: Verify the offline indicator is shown
- var offlineIndicator = await offlineExtensionPopup.QuerySelectorAsync("text=Offline");
- Assert.That(offlineIndicator, Is.Not.Null, "Offline indicator should be visible when server is unavailable");
-
- // Clean up: Unroute the API blocking
- await Context.UnrouteAsync($"**{ApiBaseUrl.TrimEnd('/')}/**");
- await Context.UnrouteAsync(ApiBaseUrl.TrimEnd('/') + "/*");
-
- await offlineExtensionPopup.CloseAsync();
- }
-
/// <summary>
/// Gets the extension ID from the browser context using reflection.
/// This is a helper method for tests that need to open the extension popup manually.
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
index 8491885ed..81ad71cbe 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
@@ -44,6 +44,12 @@ public class VaultUpgradeTests : BrowserExtensionPlaywrightTest
// Clear any tracked entities from previous operations.
ApiDbContext.ChangeTracker.Clear();
+ // The 1.0.0 vault was created when SRP used the username as the identity.
+ // Update the user's SrpIdentity to match what the old vault expects (lowercase username).
+ var user = ApiDbContext.AliasVaultUsers.First();
+ user.SrpIdentity = TestUserUsername.ToLowerInvariant();
+ await ApiDbContext.SaveChangesAsync();
+
// Insert static 1.0.0 vault into the database for the current user.
ApiDbContext.Vaults.Add(
new Vault
@@ -60,6 +66,7 @@ public class VaultUpgradeTests : BrowserExtensionPlaywrightTest
Salt = "1a73a8ef3a1c6dd891674c415962d87246450f8ca5004ecca24be770a4d7b1f7",
Verifier = "ab284d4e6da07a2bc95fb4b9dcd0e192988cc45f51e4c51605e42d4fc1055f8398e579755f4772a045abdbded8ae47ae861faa9ff7cb98155103d7038b9713b12d80dff9134067f02564230ab2f5a550ae293b8b7049516a7dc3f918156cde7190bee7e9c84398b2b5b63aeea763cd776b3e9708fb1f66884340451187ca8aacfced19ea28bc94ae28eefa720aae7a3185b139cf6349c2d43e8147f1edadd249c7e125ce15e775c45694d9796ee3f9b8c5beacd37e777a2ea1e745c781b5c085b7e3826f6abe303a14f539cd8d9519661a91cc4e7d44111b8bc9aac1cf1a51ad76658502b436da746844348dfcfb2581c4e4c340058c116a06f975f57a689df4",
});
+
await ApiDbContext.SaveChangesAsync();
// Login to the extension.