Skip to content

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

Add basic registration and authentication web app e2e tests (#2413)

Leendert de Borstff0bd8a70598
diff --git a/apps/web/.gitignore b/apps/web/.gitignore
index b7d33701f..00370d6d5 100644
--- a/apps/web/.gitignore
+++ b/apps/web/.gitignore
@@ -3,3 +3,7 @@ dist
stats.html
*.log
public/appsettings.Development.json
+
+# E2E test output
+playwright-report
+tests/test-results
diff --git a/apps/web/playwright.config.ts b/apps/web/playwright.config.ts
index 83a38ea1f..ca8fa7233 100644
--- a/apps/web/playwright.config.ts
+++ b/apps/web/playwright.config.ts
@@ -33,10 +33,8 @@ export default defineConfig({
['list'],
],
- // Registration and login run Argon2 key derivation in the browser, so allow for slower CI machines.
- timeout: 90000,
expect: {
- timeout: 15000,
+ timeout: 10000,
},
use: {
@@ -58,7 +56,6 @@ export default defineConfig({
command: `npx vite build && npx vite preview --port ${PREVIEW_PORT} --strictPort`,
url: WEB_URL,
reuseExistingServer: false,
- timeout: 60000,
},
outputDir: 'tests/test-results',
diff --git a/apps/web/tests/e2e/01-registration.spec.ts b/apps/web/tests/e2e/01-registration.spec.ts
new file mode 100644
index 000000000..9286ae331
--- /dev/null
+++ b/apps/web/tests/e2e/01-registration.spec.ts
@@ -0,0 +1,38 @@
+/**
+ * Category 1: Full registration setup flow via web app UI (requires API)
+ */
+import { test, expect } from '../fixtures';
+
+test.describe('1. Registration', () => {
+ test('1.1 should create a new account through the setup wizard', async ({ app, credentials }) => {
+ const { page } = app;
+ const continueButton = page.getByRole('button', { name: 'Continue' });
+
+ await test.step('open the setup wizard', async () => {
+ await app.openStart();
+ await page.getByRole('link', { name: 'Create new vault' }).click();
+ await expect(page).toHaveURL(/\/user\/setup$/);
+ });
+
+ await test.step('accept the terms', async () => {
+ await page.locator('#agreeTerms').check();
+ await continueButton.click();
+ });
+
+ await test.step('choose a username, checked against the server', async () => {
+ await page.locator('#username').fill(credentials.username);
+ await expect(page.getByText('Username is available!')).toBeVisible();
+ await continueButton.click();
+ });
+
+ await test.step('set the master password and create the account', async () => {
+ await page.locator('#password').fill(credentials.password);
+ await page.locator('#confirmPassword').fill(credentials.password);
+ await page.getByRole('button', { name: 'Create Account' }).click();
+ await app.expectVaultOpen(credentials.username);
+ });
+
+ // A new vault starts out empty.
+ await expect(page.getByText('No items yet')).toBeVisible();
+ });
+});
diff --git a/apps/web/tests/e2e/02-authentication.spec.ts b/apps/web/tests/e2e/02-authentication.spec.ts
new file mode 100644
index 000000000..133a59b66
--- /dev/null
+++ b/apps/web/tests/e2e/02-authentication.spec.ts
@@ -0,0 +1,32 @@
+/**
+ * Category 2: Authentication (requires API)
+ */
+import { test, expect } from '../fixtures';
+
+test.describe('2. Authentication', () => {
+ test('2.1 should log in and log out', async ({ app, testUser }) => {
+ await test.step('log in', async () => {
+ await app.login(testUser.username, testUser.password);
+ await expect(app.page.getByText('No items yet')).toBeVisible();
+ });
+
+ await test.step('log out', async () => {
+ await app.logout();
+ });
+
+ await test.step('logged out visitors are sent to the start page', async () => {
+ await app.page.goto('/items');
+ await expect(app.page).toHaveURL(/\/user\/start$/);
+ });
+ });
+
+ test('2.2 should reject invalid credentials', async ({ app, credentials }) => {
+ await app.page.goto('/user/login');
+ await app.page.locator('#email').fill(credentials.username);
+ await app.page.locator('#password').fill(credentials.password);
+ await app.page.locator('#login-button').click();
+
+ await expect(app.page.getByText('Invalid username or password')).toBeVisible();
+ await expect(app.page).toHaveURL(/\/user\/login$/);
+ });
+});
diff --git a/apps/web/tests/fixtures/WebApp.ts b/apps/web/tests/fixtures/WebApp.ts
new file mode 100644
index 000000000..4c4e4a79f
--- /dev/null
+++ b/apps/web/tests/fixtures/WebApp.ts
@@ -0,0 +1,52 @@
+import { expect, type Page } from '@playwright/test';
+
+/**
+ * Page object for the web app: the user-level flows tests are written in.
+ */
+export class WebApp {
+ /**
+ * Wrap a page that runs the web app.
+ */
+ public constructor(public readonly page: Page) {}
+
+ /**
+ * Open the start page as a logged-out visitor.
+ */
+ public async openStart(): Promise<void> {
+ await this.page.goto('/');
+ await expect(this.page).toHaveURL(/\/user\/start$/);
+ }
+
+ /**
+ * Log out via the user menu and wait for the start page.
+ */
+ public async logout(): Promise<void> {
+ await this.page.locator('#toggleMobileMenuButton').click();
+ await this.page.locator('#mobileMenuDropdown').getByRole('link', { name: 'Log out' }).click();
+ await expect(this.page).toHaveURL(/\/user\/start$/);
+ }
+
+ /**
+ * Log in from the start page and wait for the vault.
+ */
+ public async login(username: string, password: string): Promise<void> {
+ await this.openStart();
+ await this.page.getByRole('link', { name: 'Log in with existing account' }).click();
+ await expect(this.page).toHaveURL(/\/user\/login$/);
+
+ await this.page.locator('#email').fill(username);
+ await this.page.locator('#password').fill(password);
+ await this.page.locator('#login-button').click();
+
+ await this.expectVaultOpen(username);
+ }
+
+ /**
+ * Wait until the vault is unlocked and the items page shows for the given user.
+ */
+ public async expectVaultOpen(username: string): Promise<void> {
+ await expect(this.page).toHaveURL(/\/items$/);
+ await expect(this.page.locator('#mobileMenuDropdown').getByText(username, { exact: true })).toBeAttached();
+ }
+
+}
diff --git a/apps/web/tests/fixtures/index.ts b/apps/web/tests/fixtures/index.ts
index 08b197ca1..3c562c2fd 100644
--- a/apps/web/tests/fixtures/index.ts
+++ b/apps/web/tests/fixtures/index.ts
@@ -2,4 +2,4 @@
* Test fixtures: `test`/`expect` with the web app fixtures, and the WebApp page object tests are written in.
*/
export { test, expect, type TestCredentials } from './fixtures';
-export { WebApp, Timeouts } from './WebApp';
+export { WebApp } from './WebApp';