Files
punimtag/e2e/tests/auth.setup.ts
T
ilia 4273162d9e
CI / skip-ci-check (pull_request) Successful in 4s
CI / docker-ci (pull_request) Successful in 6s
CI / secret-scan (pull_request) Successful in 11s
CI / viewer-unit (pull_request) Failing after 1m3s
CI / admin-unit (pull_request) Failing after 1m1s
CI / e2e (pull_request) Failing after 59s
test: interceptNetworkCall + Zod widening, PROD smoke, NextAuth write gates
- upload.smoke.spec.ts / gallery.search-filters.spec.ts: replace
  waitForResponse/text-scrape with typed interceptNetworkCall spies (status
  + JSON shape) on the real upload POST and the filtered /api/search GET.
- api.fastapi-login.spec.ts: Zod-validate the FastAPI TokenResponse and
  /auth/me UserResponse instead of loose casts. gallery.search-filters.spec.ts
  gets the same treatment for the Prisma-backed SearchResponse.
- prod.smoke.spec.ts: opt-in (PROD_BASE_URL) health + login-page check on a
  real PROD host; skips as a no-op until the PROD LXC exists (none does yet
  per `pct list` — see ROADMAP).
- viewer.write-gates.spec.ts: NextAuth (browser-session) hasWriteAccess gate
  on POST /api/faces/{id}/identify — viewer 403s, admin passes through.
  Provisioned a third, independent auth-DB user (e2e-viewer@levkine.ca,
  hasWriteAccess=false) for this via ansible's provision-punimtag-e2e-user.py
  (see that repo for the vault/Infisical/Gitea/Vaultwarden side).
2026-07-14 22:07:30 -04:00

42 lines
1.8 KiB
TypeScript

import { assertPublicHost, saveStorageState, waitForUrlHost } from '@levkin/playkit';
import { test as setup } from '../fixtures';
import path from 'node:path';
const authFile = path.join(__dirname, '../.auth/admin.json');
const viewerAuthFile = path.join(__dirname, '../.auth/viewer.json');
setup('authenticate e2e admin', async ({ page, playkitConfig, loginPage, e2eCredentials, timings }) => {
setup.skip(!e2eCredentials, 'E2E_ADMIN_EMAIL/PASSWORD required');
assertPublicHost(playkitConfig.baseUrl);
await timings.measure('setup_login', async () => {
await loginPage.openLogin();
await loginPage.signIn(e2eCredentials!.email, e2eCredentials!.password);
await page.waitForURL((url) => !url.pathname.includes('/login'), { timeout: 30_000 });
await page.getByLabel('Account menu').waitFor({ state: 'visible', timeout: 30_000 });
await waitForUrlHost(page, playkitConfig.expectedHost);
});
await saveStorageState(page, authFile);
});
// NextAuth auth-DB viewer (hasWriteAccess=false) — optional, only needed by
// viewer.write-gates.spec.ts. Skips (not fails) when E2E_VIEWER_* is unset.
setup(
'authenticate e2e viewer (no write access)',
async ({ page, playkitConfig, loginPage, e2eViewerCredentials, timings }) => {
setup.skip(!e2eViewerCredentials, 'E2E_VIEWER_EMAIL/PASSWORD required');
assertPublicHost(playkitConfig.baseUrl);
await timings.measure('setup_login_viewer', async () => {
await loginPage.openLogin();
await loginPage.signIn(e2eViewerCredentials!.email, e2eViewerCredentials!.password);
await page.waitForURL((url) => !url.pathname.includes('/login'), { timeout: 30_000 });
await page.getByLabel('Account menu').waitFor({ state: 'visible', timeout: 30_000 });
await waitForUrlHost(page, playkitConfig.expectedHost);
});
await saveStorageState(page, viewerAuthFile);
},
);