mirror of
https://github.com/penpot/penpot.git
synced 2026-08-08 05:48:50 +00:00
Add end-to-end HTTP tests under backend/test/e2e/ using Node.js built-in test runner (node:test) and native fetch. Tests run through the devenv nginx proxy on port 3450. Test suites (19 tests total): - auth-flow: demo profile creation, login, session cookies, access tokens - export-binfile: file creation, export to asset URL via SSE - asset-download: download with cookie/token auth, 401 without auth, S3 redirect behavior, full export-to-download flow Key findings documented in tests: - nginx @handle_redirect intercepts backend 307 and proxies to S3 directly, stripping the client Authorization header (bug does not reproduce in devenv) - SSE end event uses ~#uri tagged format for URLs - Unauthenticated RPC returns uuid/zero profile (not null) AI-assisted-by: mimo-v2.5-pro Signed-off-by: Andrey Antukh <niwi@niwi.nz>
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import { rpcPost, extractCookie } from "./client.mjs";
|
|
|
|
export async function createDemoProfile() {
|
|
const res = await rpcPost("create-demo-profile", {});
|
|
if (res.body.type === "validation" || res.body.type === "restriction") {
|
|
throw new Error(
|
|
`Failed to create demo profile: ${res.body.code} - ${res.body.hint || ""}`
|
|
);
|
|
}
|
|
return { email: res.body.email, password: res.body.password };
|
|
}
|
|
|
|
export async function login(email, password) {
|
|
const res = await rpcPost("login-with-password", { email, password });
|
|
if (res.status !== 200 || res.body.type) {
|
|
throw new Error(
|
|
`Login failed: ${JSON.stringify(res.body)}`
|
|
);
|
|
}
|
|
const cookie = extractCookie(res.setCookie);
|
|
return { profile: res.body, cookie };
|
|
}
|
|
|
|
export async function createAccessToken(cookie, name = "e2e-test-token") {
|
|
const res = await rpcPost("create-access-token", { name }, { cookieToken: cookie });
|
|
if (res.status !== 200 || res.body.type) {
|
|
throw new Error(
|
|
`Create access token failed: ${JSON.stringify(res.body)}`
|
|
);
|
|
}
|
|
return res.body;
|
|
}
|
|
|
|
export async function setupTestProfile() {
|
|
const { email, password } = await createDemoProfile();
|
|
const { profile, cookie } = await login(email, password);
|
|
return { profile, cookie, email, password };
|
|
}
|