CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
google-oauth-env.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 27d5fd3 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | import { googleOauthConfigFromEnv } from "../lib/sso"; | |
| 3 | ||
| 4 | describe("googleOauthConfigFromEnv", () => { | |
| 5 | test("returns null when credentials are absent", () => { | |
| 6 | expect(googleOauthConfigFromEnv({})).toBeNull(); | |
| 7 | expect( | |
| 8 | googleOauthConfigFromEnv({ GOOGLE_OAUTH_CLIENT_ID: "id-only" }) | |
| 9 | ).toBeNull(); | |
| 10 | expect( | |
| 11 | googleOauthConfigFromEnv({ GOOGLE_OAUTH_CLIENT_SECRET: "secret-only" }) | |
| 12 | ).toBeNull(); | |
| 13 | expect( | |
| 14 | googleOauthConfigFromEnv({ | |
| 15 | GOOGLE_OAUTH_CLIENT_ID: " ", | |
| 16 | GOOGLE_OAUTH_CLIENT_SECRET: "s", | |
| 17 | }) | |
| 18 | ).toBeNull(); | |
| 19 | }); | |
| 20 | ||
| 21 | test("builds an enabled config from the env pair", () => { | |
| 22 | const cfg = googleOauthConfigFromEnv({ | |
| 23 | GOOGLE_OAUTH_CLIENT_ID: "abc.apps.googleusercontent.com", | |
| 24 | GOOGLE_OAUTH_CLIENT_SECRET: "shh", | |
| 25 | }); | |
| 26 | expect(cfg).not.toBeNull(); | |
| 27 | expect(cfg!.enabled).toBe(true); | |
| 28 | expect(cfg!.id).toBe("google"); | |
| 29 | expect(cfg!.clientId).toBe("abc.apps.googleusercontent.com"); | |
| 30 | expect(cfg!.clientSecret).toBe("shh"); | |
| 31 | expect(cfg!.authorizationEndpoint).toBe( | |
| 32 | "https://accounts.google.com/o/oauth2/v2/auth" | |
| 33 | ); | |
| 34 | expect(cfg!.tokenEndpoint).toBe("https://oauth2.googleapis.com/token"); | |
| 35 | expect(cfg!.userinfoEndpoint).toBe( | |
| 36 | "https://openidconnect.googleapis.com/v1/userinfo" | |
| 37 | ); | |
| 38 | expect(cfg!.scopes).toBe("openid email profile"); | |
| 39 | expect(cfg!.autoCreateUsers).toBe(true); | |
| 40 | expect(cfg!.allowedEmailDomains).toBeNull(); | |
| 41 | }); | |
| 42 | ||
| 43 | test("honours optional knobs", () => { | |
| 44 | const cfg = googleOauthConfigFromEnv({ | |
| 45 | GOOGLE_OAUTH_CLIENT_ID: "id", | |
| 46 | GOOGLE_OAUTH_CLIENT_SECRET: "secret", | |
| 47 | GOOGLE_OAUTH_AUTO_CREATE: "0", | |
| 48 | GOOGLE_OAUTH_ALLOWED_DOMAINS: "example.com,corp.example.com", | |
| 49 | }); | |
| 50 | expect(cfg!.autoCreateUsers).toBe(false); | |
| 51 | expect(cfg!.allowedEmailDomains).toBe("example.com,corp.example.com"); | |
| 52 | }); | |
| 53 | }); |