config.test.js
946 bytes
| 1 | import { describe, expect, it } from "vitest"; |
|---|---|
| 2 | import { loadConfig } from "../src/config.js"; |
| 3 | |
| 4 | describe("production configuration", () => { |
| 5 | it("rejects a missing or weak token-encryption secret", () => { |
| 6 | expect(() => loadConfig({ NODE_ENV: "production" })).toThrow(/SESSION_SECRET/); |
| 7 | expect(() => loadConfig({ |
| 8 | NODE_ENV: "production", |
| 9 | SESSION_SECRET: "too-short", |
| 10 | })).toThrow(/SESSION_SECRET/); |
| 11 | }); |
| 12 | |
| 13 | it("accepts a production secret with at least 32 characters", () => { |
| 14 | const config = loadConfig({ |
| 15 | NODE_ENV: "production", |
| 16 | SESSION_SECRET: "0123456789abcdef0123456789abcdef", |
| 17 | }); |
| 18 | expect(config.sessionSecret).toHaveLength(32); |
| 19 | }); |
| 20 | |
| 21 | it("requires a strong secret whenever GitHub credentials are configured", () => { |
| 22 | expect(() => loadConfig({ |
| 23 | GITHUB_CLIENT_ID: "client", |
| 24 | GITHUB_CLIENT_SECRET: "secret", |
| 25 | GITHUB_APP_SLUG: "app", |
| 26 | })).toThrow(/SESSION_SECRET/); |
| 27 | }); |
| 28 | }); |
| 29 | |