Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update browser extension tests to work with sqlite-blob to manifest-v1 migration (#2159)
Leendert de Borst2d5cdabc3275
diff --git a/apps/browser-extension/tests/e2e/13-forward-compat-overflow.spec.ts b/apps/browser-extension/tests/e2e/13-forward-compat-overflow.spec.tsindex d47cc8d46..c7f92e46f 100644--- a/apps/browser-extension/tests/e2e/13-forward-compat-overflow.spec.ts+++ b/apps/browser-extension/tests/e2e/13-forward-compat-overflow.spec.ts@@ -16,7 +16,7 @@* 5. The newer client pulls again — the rename is applied AND the unknown column/table are intact*/import { test, expect, TestClient, FieldSelectors } from '../fixtures';-import { getVaultSnapshot, openManifest, pushManifest, pollUntil, requirePersonalManifest, type DecryptedManifest } from '../helpers/manifest-v2-api';+import { getVaultSnapshot, openManifest, pushManifest, pollUntil, requirePersonalManifest, resolveVaultEncryptionKey, type DecryptedManifest } from '../helpers/manifest-v2-api';import type { TestUser } from '../helpers/test-api';test.describe.serial('13. Forward-compat overflow', () => {@@ -31,6 +31,8 @@ test.describe.serial('13. Forward-compat overflow', () => {/** Manifest revision created by the simulated newer client in 13.2. */let injectedRevision: number;+ /** The account's personal manifest id, which the codec stamps onto every row it carries. */+ let personalManifestId: string;test.afterAll(async () => {await client?.cleanup();@@ -58,7 +60,7 @@ test.describe.serial('13. Forward-compat overflow', () => {test('13.2 a newer client should inject an unknown column and table into the server manifest', async () => {const token = user.token!.token;- const { manifest, personal } = await openLatestManifest(baseApiUrl, token, user.encryptionKey!);+ const { manifest, personal, vaultKey } = await openLatestManifest(baseApiUrl, token, user.encryptionKey!);// Simulate a newer client's schema additions: a column this extension build doesn't know on an// existing row, and a whole table it doesn't know at all.@@ -67,7 +69,8 @@ test.describe.serial('13. Forward-compat overflow', () => {item!.AliasEnabled = true;manifest.tables.FutureFeatures = [futureTableRow];- injectedRevision = await pushManifest(baseApiUrl, token, user.username, personal.manifestId, manifest, personal.revision, personal.blobReferences, user.encryptionKey!);+ personalManifestId = personal.manifestId;+ injectedRevision = await pushManifest(baseApiUrl, token, user.username, personal.manifestId, manifest, personal.revision, personal.blobReferences, vaultKey);expect(injectedRevision).toBeGreaterThan(personal.revision);});@@ -103,23 +106,34 @@ test.describe.serial('13. Forward-compat overflow', () => {expect(item, 'renamed credential row should be present').toBeTruthy();expect(item!.AliasEnabled, 'unknown column must survive the old-client push').toBe(true);- // The unknown table re-emitted verbatim.- expect(manifest.tables.FutureFeatures, 'unknown table must survive the old-client push').toEqual([futureTableRow]);+ /*+ * The unknown table re-emitted with its payload intact. It does not come back as-is: rows the+ * codec carries through the overflow are stamped with the manifest they arrived in, and that stamp+ * is what routes them back into this manifest on the next push.+ */+ const futureRows = manifest.tables.FutureFeatures ?? [];+ expect(futureRows, 'unknown table must survive the old-client push').toHaveLength(1);+ expect(futureRows[0], 'unknown table row must keep every column the newer client wrote').toMatchObject(futureTableRow);+ expect(futureRows[0].ManifestId, 'carried row is stamped with the manifest that routes it back').toBe(personalManifestId);});});/*** Polls until the server snapshot is manifest-v1, then decrypts and returns its personal manifest.*+ * The vault key is resolved per attempt: the same push that flips the account to manifest-v1 also+ * moves it onto the account-key model, so the key that opens the blob only exists once that landed.+ ** @param apiUrl - The base URL of the API* @param token - Bearer token- * @param encryptionKey - The user's derived vault encryption key- * @returns The decrypted manifest and its snapshot entry+ * @param derivedKey - The user's Argon2Id password-derived key+ * @returns The decrypted manifest, its snapshot entry, and the key that opened it*/-async function openLatestManifest(apiUrl: string, token: string, encryptionKey: Uint8Array): Promise<{ manifest: DecryptedManifest; personal: ReturnType<typeof requirePersonalManifest> }> {+async function openLatestManifest(apiUrl: string, token: string, derivedKey: Uint8Array): Promise<{ manifest: DecryptedManifest; personal: ReturnType<typeof requirePersonalManifest>; vaultKey: Uint8Array }> {return pollUntil(async () => {const snapshot = await getVaultSnapshot(apiUrl, token);const personal = requirePersonalManifest(snapshot);- return { manifest: await openManifest(personal.blob, encryptionKey), personal };+ const vaultKey = await resolveVaultEncryptionKey(apiUrl, token, derivedKey);+ return { manifest: await openManifest(personal.blob, vaultKey), personal, vaultKey };});}diff --git a/apps/browser-extension/tests/fixtures/TestClient.ts b/apps/browser-extension/tests/fixtures/TestClient.tsindex 0b568272e..7de5bd6f4 100644--- a/apps/browser-extension/tests/fixtures/TestClient.ts+++ b/apps/browser-extension/tests/fixtures/TestClient.ts@@ -16,6 +16,7 @@ import path from 'path';import { fileURLToPath } from 'url';import { expect } from './fixtures';+import { completeVaultUpgrade } from './helpers';import { FieldSelectors, ButtonSelectors } from './selectors';import {waitForVaultReady,@@ -140,7 +141,14 @@ export class TestClient {await this.popup.fill('input[type="text"]', username);await this.popup.fill('input[type="password"]', password);await this.popup.click('button:has-text("Log in")');- await this.popup.getByRole('button', { name: 'Vault' }).waitFor({ state: 'visible', timeout: Timeouts.LONG });+ return this.completeVaultUpgrade();+ }++ /**+ * Clear the vault upgrade gate, if the popup landed on it, and wait for the vault to be ready.+ */+ async completeVaultUpgrade(timeout: number = Timeouts.LONG): Promise<this> {+ await completeVaultUpgrade(this.popup, timeout);return this;}@@ -168,8 +176,7 @@ export class TestClient {*/async submitLogin(): Promise<this> {await this.popup.click('button:has-text("Log in")');- await this.popup.getByRole('button', { name: 'Vault' }).waitFor({ state: 'visible', timeout: Timeouts.LONG });- return this;+ return this.completeVaultUpgrade();}/**@@ -463,8 +470,8 @@ export class TestClient {async unlockVault(password: string): Promise<this> {await this.popup.fill('input#password', password);await this.popup.click('button[type="submit"]:has-text("Unlock")');- await waitForVaultReady(this.popup, Timeouts.LONG);- return this;+ // Unlocking routes to the upgrade gate too, whenever the local vault still owes a migration.+ return this.completeVaultUpgrade();}/**diff --git a/apps/browser-extension/tests/fixtures/fixtures.ts b/apps/browser-extension/tests/fixtures/fixtures.tsindex ee854e8fc..db9629c8e 100644--- a/apps/browser-extension/tests/fixtures/fixtures.ts+++ b/apps/browser-extension/tests/fixtures/fixtures.ts@@ -4,6 +4,7 @@ import { fileURLToPath } from 'url';import { createTestUser, type TestUser } from '../helpers/test-api';+import { completeVaultUpgrade } from './helpers';import { waitForPopupReady as waitForPopupReadyState, Timeouts } from './waits';const __filename = fileURLToPath(import.meta.url);@@ -162,13 +163,14 @@ export async function openPopup(/*** Helper to wait for post-login state (vault is visible).*- * This confirms the user has successfully logged in and the vault UI is ready.+ * This confirms the user has successfully logged in and the vault UI is ready. Test accounts start+ * out on a legacy sqlite-blob vault, so this also clears the upgrade gate the popup lands on.** @param popup - The popup page* @param timeout - Maximum time to wait in milliseconds (default: 30000)*/export async function waitForLoggedIn(popup: Page, timeout: number = 30000): Promise<void> {- await popup.getByRole('button', { name: 'Vault' }).waitFor({ state: 'visible', timeout });+ await completeVaultUpgrade(popup, timeout);}/**diff --git a/apps/browser-extension/tests/fixtures/helpers.ts b/apps/browser-extension/tests/fixtures/helpers.tsindex 9b6e5cbd8..60fd17595 100644--- a/apps/browser-extension/tests/fixtures/helpers.ts+++ b/apps/browser-extension/tests/fixtures/helpers.ts@@ -11,6 +11,7 @@import type { Page } from '@playwright/test';import { FieldSelectors } from './selectors';+import { waitForVaultReady, Timeouts } from './waits';// Re-export all waitsexport {@@ -57,3 +58,58 @@ export async function getPasswordValue(popup: Page): Promise<string> {export async function getNotesValue(popup: Page): Promise<string> {return getFieldValue(popup, FieldSelectors.LOGIN_NOTES);}++/**+ * Selectors for the vault upgrade gate (the `/upgrade` route).+ */+const UpgradeSelectors = {+ UPGRADE_BUTTON: 'button#upgrade-button',+ CONTINUE_BUTTON: 'button#upgrade-continue-button',+} as const;++/**+ * Walk the vault upgrade gate, if the popup landed on it.+ *+ * Test accounts are seeded with a legacy sqlite-blob vault. TODO: update tests to work with native manifest-v1 newly created account.+ *+ * @param popup - The popup page+ * @param timeout - Timeout in milliseconds for each step of the flow+ */+export async function completeVaultUpgrade(popup: Page, timeout: number = Timeouts.LONG): Promise<void> {+ /*+ * The popup hops through `/reinitialize` before it routes on, and that route already renders the+ * bottom nav, so a visible `#nav-vault` on its own is no proof that the app has settled. The hash+ * route is: wait until it is either the gate, or anything past it showing the vault UI.+ */+ await popup.waitForFunction(+ () => window.location.hash.startsWith('#/upgrade') ||+ (!window.location.hash.startsWith('#/reinitialize') && document.querySelector('#nav-vault') !== null),+ undefined,+ { timeout }+ );++ const hash = await popup.evaluate(() => window.location.hash);+ if (!hash.startsWith('#/upgrade')) {+ return;+ }++ /*+ * The gate classifies the pending upgrade on mount: a storage format move asks for consent, while+ * a local-only schema rebuild runs unattended and opens the vault by itself.+ */+ const upgradeButton = popup.locator(UpgradeSelectors.UPGRADE_BUTTON);+ await popup.locator(`${UpgradeSelectors.UPGRADE_BUTTON}, #nav-vault`).first().waitFor({ state: 'visible', timeout });++ if (await upgradeButton.isVisible()) {+ await upgradeButton.click();++ // The storage format upgrade ends on a success screen that auto-continues after a countdown.+ const continueButton = popup.locator(UpgradeSelectors.CONTINUE_BUTTON);+ await popup.locator(`${UpgradeSelectors.CONTINUE_BUTTON}, #nav-vault`).first().waitFor({ state: 'visible', timeout });+ if (await continueButton.isVisible()) {+ await continueButton.click();+ }+ }++ await waitForVaultReady(popup, timeout);+}diff --git a/apps/browser-extension/tests/fixtures/index.ts b/apps/browser-extension/tests/fixtures/index.tsindex e167f287e..c57ff9dd6 100644--- a/apps/browser-extension/tests/fixtures/index.ts+++ b/apps/browser-extension/tests/fixtures/index.ts@@ -41,6 +41,7 @@ export {getUsernameValue,getPasswordValue,getNotesValue,+ completeVaultUpgrade,} from './helpers';// Field selectors and constantsdiff --git a/apps/browser-extension/tests/helpers/manifest-v2-api.ts b/apps/browser-extension/tests/helpers/manifest-v2-api.tsindex d7730bc4c..5198d3b26 100644--- a/apps/browser-extension/tests/helpers/manifest-v2-api.ts+++ b/apps/browser-extension/tests/helpers/manifest-v2-api.ts@@ -35,6 +35,12 @@ export type VaultSnapshot = {buckets?: Array<{ category: string; blob: string; ciphertextHash: string; revision: number }>;};+/** The account-key unlock chain from GET /v2/VaultKey/{type} (fields relevant to these tests). */+type VaultKeyEnvelope = {+ encryptedAccountKey: string;+ encryptedVek?: string | null;+};+/** A decrypted manifest-v1 manifest: known top-level fields plus free-form tables. */export type DecryptedManifest = {schemaVersion: number;@@ -75,11 +81,36 @@ export function requirePersonalManifest(snapshot: VaultSnapshot): SnapshotManifereturn personal;}+/**+ * Resolves the key the vault content is actually encrypted with.+ *+ * @param apiBaseUrl - The base URL of the API+ * @param token - Bearer token+ * @param derivedKey - The user's Argon2Id password-derived key+ * @returns The key that encrypts this account's vault content+ */+export async function resolveVaultEncryptionKey(apiBaseUrl: string, token: string, derivedKey: Uint8Array): Promise<Uint8Array> {+ const response = await fetch(`${apiBaseUrl.replace(/\/$/, '')}/v2/VaultKey/password`, {+ headers: { Authorization: `Bearer ${token}` },+ });+ if (!response.ok) {+ throw new Error(`GET /v2/VaultKey failed with status ${response.status}: ${await response.text()}`);+ }++ const { vaultKey } = (await response.json()) as { vaultKey?: VaultKeyEnvelope | null };+ if (!vaultKey) {+ return derivedKey;+ }++ const accountKey = await symmetricDecryptBytes(vaultKey.encryptedAccountKey, derivedKey);+ return vaultKey.encryptedVek ? symmetricDecryptBytes(vaultKey.encryptedVek, accountKey) : accountKey;+}+/*** Decrypts and unpacks a manifest blob into its JSON object (content hash verified by the codec).** @param blobBase64 - The encrypted manifest blob from the snapshot- * @param encryptionKey - The user's derived vault encryption key+ * @param encryptionKey - The key the vault content is encrypted with, from `resolveVaultEncryptionKey`* @returns The decrypted manifest object*/export async function openManifest(blobBase64: string, encryptionKey: Uint8Array): Promise<DecryptedManifest> {@@ -99,7 +130,7 @@ export async function openManifest(blobBase64: string, encryptionKey: Uint8Array* @param manifestId - The manifest this write targets* @param currentRevision - The revision this upload is based on (server assigns currentRevision + 1)* @param blobReferences - Blob references to carry over to the new revision- * @param encryptionKey - The user's derived vault encryption key+ * @param encryptionKey - The key the vault content is encrypted with, from `resolveVaultEncryptionKey`* @returns The new manifest revision number assigned by the server*/export async function pushManifest(diff --git a/apps/browser-extension/tests/helpers/test-api.ts b/apps/browser-extension/tests/helpers/test-api.tsindex b2e422e9c..5fe3813cd 100644--- a/apps/browser-extension/tests/helpers/test-api.ts+++ b/apps/browser-extension/tests/helpers/test-api.ts@@ -314,8 +314,11 @@ async function uploadInitialVault(username: string,encryptionKey: Uint8Array): Promise<void> {- // Intentionally the v1 endpoint: the initial vault is a legacy sqlite-blob (the v2 endpoint is- // manifest-only). This mirrors a pre-manifest account; the extension migrates it on first save.+ /*+ * Intentionally the v1 endpoint: the initial vault is a legacy sqlite-blob (the v2 endpoint is+ * manifest-only). This mirrors a pre-manifest account, so the first login lands on the extension's+ * upgrade gate; `completeVaultUpgrade` in the fixtures clicks it through to manifest-v1.+ */const baseUrl = apiBaseUrl.replace(/\/$/, '') + '/v1/';// Create an empty vault database