Files
gitea-mirror/tests/e2e/playwright.config.ts
T
ARUNAVO RAYandGitHub 83dd74dd52 feat(auth): API keys for programmatic access (#380)
* feat(auth): API keys for programmatic access

Adds the @better-auth/api-key plugin so scripts and CI pipelines can call
the existing endpoints with an x-api-key header instead of a session
cookie. Keys are owned by a user, hashed at rest, prefixed gm_, never
expire unless an expiry is chosen, and are not rate limited. A small
guard plugin refuses key management calls that arrive with a key, so a
leaked key cannot mint or revoke keys.

New API Keys section on the Authentication tab with create, show once,
copy and revoke. Migration 0017 adds the api_keys table with the
validator fixture. docs/API.md documents the header and the calls
automation needs. An e2e spec covers create, use, refuse and revoke over
HTTP. bun.nix regenerated for the new package.

Closes #314

Claude-Session: https://claude.ai/code/session_01Tp9pmi65a8k5jLMQFLf4JX

* fix(e2e): send Origin on cookie-authenticated key management calls

Better Auth rejects a cookie-authenticated POST without an Origin header (403 MISSING_OR_NULL_ORIGIN). Browsers always send one, the Playwright request context does not, so the spec sets it on the create and delete calls. Also asserts the guard's 403 code and documents the Origin requirement for scripts that manage keys with a session.

Claude-Session: https://claude.ai/code/session_01Tp9pmi65a8k5jLMQFLf4JX
2026-09-02 14:57:58 +05:30

100 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, devices } from "@playwright/test";
/**
* Playwright configuration for gitea-mirror E2E tests.
*
* Expected services (started by run-e2e.sh before Playwright launches):
* - Fake GitHub API server on http://localhost:4580
* - Git HTTP server on http://localhost:4590
* - Gitea instance on http://localhost:3333
* - gitea-mirror app on http://localhost:4321
*
* Test files are numbered to enforce execution order (they share state
* via a single Gitea + app instance):
* 01-health.spec.ts – service smoke tests
* 02-mirror-workflow.spec.ts – full first-mirror journey
* 03-backup.spec.ts – backup config toggling
* 04-force-push.spec.ts – force-push simulation & backup verification
* 05-sync-verification.spec.ts – dynamic repos, content integrity, reset
* 06-api-keys.spec.ts – API key creation, header auth, revocation
*/
export default defineConfig({
testDir: ".",
testMatch: /\d+-.*\.spec\.ts$/,
/* Fail the build on CI if test.only is left in source */
forbidOnly: !!process.env.CI,
/* Retry once on CI to absorb flakiness from container startup races */
retries: process.env.CI ? 1 : 0,
/* Limit parallelism – the tests share a single Gitea + app instance */
workers: 1,
fullyParallel: false,
/* Generous timeout: mirrors involve real HTTP round-trips to Gitea */
timeout: 120_000,
expect: { timeout: 15_000 },
/* Reporter */
reporter: process.env.CI
? [
["github"],
["html", { open: "never", outputFolder: "playwright-report" }],
]
: [
["list"],
["html", { open: "on-failure", outputFolder: "playwright-report" }],
],
outputDir: "test-results",
use: {
/* Base URL of the gitea-mirror app */
baseURL: process.env.APP_URL || "http://localhost:4321",
/* Collect traces on first retry so CI failures are debuggable */
trace: "on-first-retry",
screenshot: "only-on-failure",
video: "retain-on-failure",
/* Extra HTTP headers aren't needed but keep accept consistent */
extraHTTPHeaders: {
Accept: "application/json, text/html, */*",
},
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
/* We do NOT use webServer here because run-e2e.sh manages all services.
* On CI the GitHub Action workflow starts them before invoking Playwright.
* Locally, run-e2e.sh does the same.
*
* If you want Playwright to start the app for you during local dev, uncomment:
*
* webServer: [
* {
* command: "npx tsx tests/e2e/fake-github-server.ts",
* port: 4580,
* reuseExistingServer: true,
* timeout: 10_000,
* },
* {
* command: "bun run dev",
* port: 4321,
* reuseExistingServer: true,
* timeout: 30_000,
* env: {
* GITHUB_API_URL: "http://localhost:4580",
* BETTER_AUTH_SECRET: "e2e-test-secret",
* },
* },
* ],
*/
});