Download frontend/src/lib/auth-origins.integration.test.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/auth-origins.integration.test.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/lib/auth-origins.integration.test.ts
-
curl -L -o auth-origins.integration.test.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/auth-origins.integration.test.ts
1.46 kB
| // @vitest-environment node | |
| import { betterAuth } from "better-auth"; | |
| import { memoryAdapter } from "better-auth/adapters/memory"; | |
| import { expect, it } from "vitest"; | |
| import { getAuthTrustedOrigins } from "./auth-origins"; | |
| it("allows legacy self-hosted signup while rejecting an untrusted request origin", async () => { | |
| const auth = betterAuth({ | |
| baseURL: "http://localhost:3107", | |
| secret: "test-origin-validation-secret-at-least-32-chars", | |
| database: memoryAdapter({ user: [], session: [], account: [], verification: [] }), | |
| trustedOrigins: getAuthTrustedOrigins({ NEXT_PUBLIC_APP_URL: "http://localhost:3107" }), | |
| emailAndPassword: { enabled: true }, | |
| advanced: { disableOriginCheck: false, disableCSRFCheck: false }, | |
| }); | |
| const request = (origin: string) => new Request("http://localhost:3001/api/auth/sign-up/email", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", Origin: origin, Cookie: "browser-preference=test" }, | |
| body: JSON.stringify({ name: "Local user", email: "origin-test@example.com", password: "test-password-123" }), | |
| }); | |
| const rejected = await auth.handler(request("https://untrusted.example")); | |
| expect(rejected.status).toBe(403); | |
| expect((await rejected.json()).code).toBe("INVALID_ORIGIN"); | |
| const accepted = await auth.handler(request("http://localhost:3001")); | |
| expect(accepted.status).toBe(200); | |
| expect((await accepted.json()).user.email).toBe("origin-test@example.com"); | |
| }); | |