Skip to content

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

Update browser extension tests to include error reporting assertions

Leendert de Borst36300f891fb6
diff --git a/.github/workflows/e2e-tests-browser-extension.yml b/.github/workflows/e2e-tests-browser-extension.yml
index 17a6ee339..a98f4e087 100644
--- a/.github/workflows/e2e-tests-browser-extension.yml
+++ b/.github/workflows/e2e-tests-browser-extension.yml
@@ -67,7 +67,7 @@ jobs:
with:
timeout_minutes: 60
max_attempts: 3
- command: cd apps/browser-extension && npm run test:e2e:build
+ command: cd apps/browser-extension && npm run test:e2e
env:
ALIASVAULT_API_URL: "http://localhost:5100"
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index 733990a2e..99a9225fb 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -16,8 +16,7 @@
"build:safari": "npm run build:rust && wxt build -b safari",
"test": "vitest",
"test:coverage": "vitest run --coverage",
- "test:e2e": "playwright test",
- "test:e2e:build": "node scripts/run-e2e.mjs",
+ "test:e2e": "node scripts/run-e2e.mjs",
"test:e2e:headed": "node scripts/run-e2e.mjs --headed --workers=1",
"test:e2e:h": "node scripts/run-e2e.mjs --headed --workers=1",
"test:e2e:pause": "node scripts/run-e2e.mjs --pause",
diff --git a/apps/browser-extension/scripts/run-e2e.mjs b/apps/browser-extension/scripts/run-e2e.mjs
index e1f6904eb..d64c0e93d 100755
--- a/apps/browser-extension/scripts/run-e2e.mjs
+++ b/apps/browser-extension/scripts/run-e2e.mjs
@@ -10,9 +10,9 @@
// Usage:
// node scripts/run-e2e.mjs [test numbers] [extra playwright args]
//
-// npm run test:e2e:build all tests
-// npm run test:e2e:build 15 every test in file 15 (15.x)
-// npm run test:e2e:build 15.1 test 15.1; also 15.1,15.2 or 15.1-15.2
+// npm run test:e2e all tests
+// npm run test:e2e 15 every test in file 15 (15.x)
+// npm run test:e2e 15.1 test 15.1; also 15.1,15.2 or 15.1-15.2
// npm run test:e2e:h 15.1 same, in a visible browser, one test at a time
// npm run test:e2e:p 15.1 same, and stops at each client.pause() in the Playwright Inspector
diff --git a/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx b/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx
index c43c944ed..92d1bd7f6 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx
@@ -56,7 +56,7 @@ const VaultErrorReport: React.FC<VaultErrorReportProps> = ({ error }) => {
};
return (
- <div className="mb-4 rounded-lg border border-red-300 dark:border-red-800 bg-red-50 dark:bg-red-900/30 p-3">
+ <div id="vault-error-report" className="mb-4 rounded-lg border border-red-300 dark:border-red-800 bg-red-50 dark:bg-red-900/30 p-3">
<p className="text-sm text-red-700 dark:text-red-300">
{t('common.errors.vaultLoadError')}
</p>
@@ -66,6 +66,7 @@ const VaultErrorReport: React.FC<VaultErrorReportProps> = ({ error }) => {
<button
type="button"
+ id="vault-error-details-toggle"
onClick={() => setShowDetails(!showDetails)}
className="mt-2 text-xs font-medium text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 focus:outline-none"
>
@@ -74,11 +75,12 @@ const VaultErrorReport: React.FC<VaultErrorReportProps> = ({ error }) => {
{showDetails && (
<>
- <pre className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded bg-red-100 dark:bg-gray-900 p-2 text-[11px] leading-snug text-red-900 dark:text-red-200 select-text">
+ <pre id="vault-error-details" className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded bg-red-100 dark:bg-gray-900 p-2 text-[11px] leading-snug text-red-900 dark:text-red-200 select-text">
{buildErrorReport()}
</pre>
<button
type="button"
+ id="copy-error-report"
onClick={copyErrorReport}
className={`mt-2 inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-semibold text-white focus:outline-none focus:ring-2 focus:ring-offset-1 ${
copied
diff --git a/apps/browser-extension/tests/e2e/17-vault-errors.spec.ts b/apps/browser-extension/tests/e2e/17-vault-errors.spec.ts
new file mode 100644
index 000000000..e047849c0
--- /dev/null
+++ b/apps/browser-extension/tests/e2e/17-vault-errors.spec.ts
@@ -0,0 +1,95 @@
+/**
+ * Category 17: Vault errors (Requires API)
+ *
+ * Each test breaks the account's server vault on purpose, then checks the extension shows the real error with
+ * its code instead of a generic "server not available" message.
+ */
+import { test, expect, TestClient, Timeouts } from '../fixtures';
+import { writeManifestWithBrokenRow, writeUndecryptableManifest } from '../helpers/vault-tamper';
+
+import type { Page } from '@playwright/test';
+
+const SERVER_NOT_AVAILABLE_MESSAGE = 'The AliasVault server is not available.';
+
+/**
+ * Check the login page shows the copyable vault error report with the given code.
+ */
+async function expectVaultErrorReport(popup: Page, code: string, detail: string): Promise<void> {
+ const report = popup.locator('#vault-error-report');
+ await expect(report).toBeVisible({ timeout: Timeouts.LONG });
+ await expect(report).toContainText('Please copy the error details below and contact support');
+ await expect(report).toContainText(`(Code: ${code})`);
+ await expect(popup.getByText(SERVER_NOT_AVAILABLE_MESSAGE)).toHaveCount(0);
+
+ await popup.locator('#vault-error-details-toggle').click();
+ await expect(popup.locator('#vault-error-details')).toContainText(detail);
+ await expect(popup.locator('#copy-error-report')).toBeVisible();
+}
+
+/**
+ * Check the popup shows the sync failure dialog with the materialize error and its code.
+ */
+async function expectSyncFailedDialog(popup: Page): Promise<void> {
+ await expect(popup.getByRole('heading', { name: 'Sync failed' })).toBeVisible({ timeout: Timeouts.LONG });
+ await expect(popup.getByText('(Code: E-508)')).toBeVisible();
+ await expect(popup.getByText('NOT NULL constraint failed')).toBeVisible();
+ await expect(popup.getByText(SERVER_NOT_AVAILABLE_MESSAGE)).toHaveCount(0);
+}
+
+test.describe('17. Vault errors', () => {
+ let client: TestClient | undefined;
+
+ test.afterEach(async () => {
+ await client?.cleanup();
+ client = undefined;
+ });
+
+ test('17.1 should report a server vault that does not decrypt on login', async ({ testUser, apiUrl }) => {
+ await writeUndecryptableManifest(apiUrl, testUser);
+
+ client = await TestClient.create();
+ await client.configureApiUrl(apiUrl);
+ await client.attemptLogin(testUser.username, testUser.password);
+ await client.pause();
+
+ await expectVaultErrorReport(client.popup, 'E-503', 'AES-GCM decryption failed');
+ });
+
+ test('17.2 should report a server vault that does not load into the local database on login', async ({ testUser, apiUrl }) => {
+ // Decrypts and passes the codec, but the row misses required columns, so materializing it fails.
+ await writeManifestWithBrokenRow(apiUrl, testUser, 'Items', { Id: crypto.randomUUID(), Name: 'Broken row' });
+
+ client = await TestClient.create();
+ await client.configureApiUrl(apiUrl);
+ await client.attemptLogin(testUser.username, testUser.password);
+ await client.pause();
+
+ await expectVaultErrorReport(client.popup, 'E-508', 'NOT NULL constraint failed');
+ });
+
+ test('17.3 should report a server vault that does not load during a sync after login', async ({ testUser, apiUrl }) => {
+ client = await TestClient.create();
+ await client.login(apiUrl, testUser.username, testUser.password);
+ await client.goToVault();
+
+ await writeManifestWithBrokenRow(apiUrl, testUser, 'Items', { Id: crypto.randomUUID(), Name: 'Broken row' });
+ await client.triggerSync();
+
+ await expectSyncFailedDialog(client.popup);
+ await client.pause();
+ });
+
+ test('17.4 should report a server vault that does not load on unlock', async ({ testUser, apiUrl }) => {
+ client = await TestClient.create();
+ await client.login(apiUrl, testUser.username, testUser.password);
+ await client.lockVault();
+
+ await writeManifestWithBrokenRow(apiUrl, testUser, 'Items', { Id: crypto.randomUUID(), Name: 'Broken row' });
+ await client.popup.fill('input#password', testUser.password);
+ await client.popup.click('button[type="submit"]:has-text("Unlock")');
+
+ // The local vault still unlocks; the sync that follows reports the broken server vault.
+ await expectSyncFailedDialog(client.popup);
+ await client.pause();
+ });
+});
diff --git a/apps/browser-extension/tests/helpers/manifest-v2-api.ts b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
index fcd784195..2979551e2 100644
--- a/apps/browser-extension/tests/helpers/manifest-v2-api.ts
+++ b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
@@ -181,6 +181,22 @@ export async function pushManifest(
return written.revision;
}
+/**
+ * Uploads an already encrypted manifest blob as a new revision, so a test can write bytes no client would.
+ *
+ * @param apiBaseUrl - The base URL of the API
+ * @param token - Bearer token
+ * @param username - The vault owner's username
+ * @param manifestId - The manifest this write targets
+ * @param blob - The base64 manifest ciphertext to store
+ * @param currentRevision - The revision this upload is based on
+ */
+export async function pushManifestBlob(apiBaseUrl: string, token: string, username: string, manifestId: string, blob: string, currentRevision: number): Promise<void> {
+ const manifestCiphertextHash = createHash('sha256').update(Buffer.from(blob, 'base64')).digest('hex');
+ const write = { manifestId, manifestBlob: blob, manifestCiphertextHash, currentRevision, credentialsCount: 0, blobReferences: [] };
+ await postVaultWrite(apiBaseUrl, token, username, [write], []);
+}
+
/**
* Writes the first manifest-v1 revision for a newly registered account.
*
diff --git a/apps/browser-extension/tests/helpers/vault-tamper.ts b/apps/browser-extension/tests/helpers/vault-tamper.ts
new file mode 100644
index 000000000..3a041c305
--- /dev/null
+++ b/apps/browser-extension/tests/helpers/vault-tamper.ts
@@ -0,0 +1,39 @@
+/**
+ * Breaks a test account's server vault on purpose, through the same API a client writes with, so tests can check
+ * how the extension reports a vault it cannot open.
+ */
+
+import { randomBytes } from 'crypto';
+
+import { getSyncableTableNames, vaultCodecCanonicalizeFromSqlite, vaultCodecGenerateManifestSalt } from '@aliasvault/client/rust/RustCore';
+
+import { getVaultSnapshot, pushManifest, pushManifestBlob, requirePersonalManifest, resolveVaultEncryptionKey, type DecryptedManifest } from './manifest-v2-api';
+
+import type { TestUser } from './test-api';
+
+/**
+ * Replace the personal manifest with bytes that do not decrypt with the account's vault key.
+ */
+export async function writeUndecryptableManifest(apiUrl: string, user: TestUser): Promise<void> {
+ const token = user.token!.token;
+ const { manifestId, revision } = requirePersonalManifest(await getVaultSnapshot(apiUrl, token));
+ await pushManifestBlob(apiUrl, token, user.username, manifestId, randomBytes(256).toString('base64'), revision);
+}
+
+/**
+ * Replace the personal manifest with a well-formed one that decrypts, holding a row the client cannot load.
+ */
+export async function writeManifestWithBrokenRow(apiUrl: string, user: TestUser, table: string, row: Record<string, unknown>): Promise<void> {
+ const token = user.token!.token;
+ const { manifestId, revision } = requirePersonalManifest(await getVaultSnapshot(apiUrl, token));
+ const canonicalized = await vaultCodecCanonicalizeFromSqlite({
+ tables: (await getSyncableTableNames()).map((name) => ({ name, records: [] })),
+ canonicalizedAt: new Date().toISOString(),
+ manifests: [{ manifestId, manifestSalt: await vaultCodecGenerateManifestSalt(), name: null }],
+ });
+ const manifest = canonicalized.manifests[0].manifest as DecryptedManifest;
+ manifest.tables[table] = [...(manifest.tables[table] ?? []), row];
+
+ const vaultKey = await resolveVaultEncryptionKey(apiUrl, token, user.encryptionKey!);
+ await pushManifest(apiUrl, token, user.username, manifestId, manifest, revision, [], vaultKey);
+}
diff --git a/docs/docs/contributing/development/browser-extensions.md b/docs/docs/contributing/development/browser-extensions.md
index d2bf0591c..aed171938 100644
--- a/docs/docs/contributing/development/browser-extensions.md
+++ b/docs/docs/contributing/development/browser-extensions.md
@@ -107,13 +107,10 @@ The E2E tests live in `tests/e2e/` and use [Playwright](https://playwright.dev/)
2. Run the E2E suite. This builds the Chrome extension into `dist/chrome-mv3` and runs Playwright against it:
```bash
-npm run test:e2e:build
-```
-
-If you've already built the extension and just want to re-run the specs (or a single one), call Playwright directly:
-
-```bash
-npm run test:e2e -- <spec-name>
+npm run test:e2e # all tests
+npm run test:e2e 4.3 # select by number: 4 (file), 4.3, 4.1,4.3 or 4.1-4.3
+npm run test:e2e:h 4.3 # same, in a visible browser, one test at a time
+npm run test:e2e:p 4.3 # same, and stops at each client.pause() in the Playwright Inspector
```
## Manual tests
diff --git a/docs/docs/contributing/development/development-setup.md b/docs/docs/contributing/development/development-setup.md
index dbfb093d9..7357244a2 100644
--- a/docs/docs/contributing/development/development-setup.md
+++ b/docs/docs/contributing/development/development-setup.md
@@ -56,7 +56,7 @@ The web app and the browser extension have their own Playwright suites, which ru
```bash
cd apps/web && npm run test:e2e
-cd apps/browser-extension && npm run test:e2e:build
+cd apps/browser-extension && npm run test:e2e
```
The Admin app is tested by the .NET E2E project: