From 756d715ce0857b06ddb25244d9c352db68b896d7 Mon Sep 17 00:00:00 2001 From: Eva Date: Sat, 11 Apr 2026 04:21:37 +0700 Subject: [PATCH] test(oauth): cover slash-terminated authorize urls --- .../provider-openai-codex-oauth.test.ts | 24 +++++++++++++++++++ src/plugins/provider-openai-codex-oauth.ts | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 src/plugins/provider-openai-codex-oauth.test.ts diff --git a/src/plugins/provider-openai-codex-oauth.test.ts b/src/plugins/provider-openai-codex-oauth.test.ts new file mode 100644 index 00000000000..bc7b50b40cd --- /dev/null +++ b/src/plugins/provider-openai-codex-oauth.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { __testing } from "./provider-openai-codex-oauth.js"; + +describe("provider-openai-codex-oauth", () => { + it("normalizes required scopes for slash-terminated authorize URLs", () => { + const normalized = __testing.normalizeOpenAICodexAuthorizeUrl( + "https://auth.openai.com/oauth/authorize/?scope=openid%20profile", + ); + const url = new URL(normalized); + const scopes = new Set((url.searchParams.get("scope") ?? "").split(/\s+/).filter(Boolean)); + + expect(url.pathname).toBe("/oauth/authorize/"); + expect(scopes).toEqual( + new Set([ + "openid", + "profile", + "email", + "offline_access", + "model.request", + "api.responses.write", + ]), + ); + }); +}); diff --git a/src/plugins/provider-openai-codex-oauth.ts b/src/plugins/provider-openai-codex-oauth.ts index 6dd459acfd6..ab79b12de54 100644 --- a/src/plugins/provider-openai-codex-oauth.ts +++ b/src/plugins/provider-openai-codex-oauth.ts @@ -49,6 +49,10 @@ function normalizeOpenAICodexAuthorizeUrl(rawUrl: string): string { } } +export const __testing = { + normalizeOpenAICodexAuthorizeUrl, +}; + export async function loginOpenAICodexOAuth(params: { prompter: WizardPrompter; runtime: RuntimeEnv;