gogcli-mcp 2.21.1 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,16 +80,41 @@ describe('gogcli Cloudflare connector — OAuth surface', () => {
80
80
  }
81
81
 
82
82
  it('GET /authorize renders the gogcli login page with the connector-key field', async () => {
83
- // No `client_id` query param: the login page renders without needing a
84
- // registered OAuth client, which is all we verify here.
85
- // `redirect_uri` IS required, though — do not remove it. workers-oauth-provider
86
- // 0.8.x calls validateRedirectUriScheme() unconditionally from parseAuthRequest,
87
- // and it rejects any value with no scheme — including the empty string an ABSENT
88
- // `redirect_uri` becomes ("Invalid redirect URI"). client_id stays omitted, so no
89
- // client lookup happens and the assertion below is unchanged.
83
+ // `/authorize` is only reachable for a REGISTERED client, so the request has
84
+ // to be preceded by a real dynamic client registration.
85
+ //
86
+ // It did not always: workers-oauth-provider 0.8.x parsed the request without
87
+ // a `client_id` (it only called validateRedirectUriScheme unconditionally,
88
+ // which is why `redirect_uri` was already here). 0.10.x moved the
89
+ // `client_id is required` check and the client lookup ahead of everything
90
+ // else in parseAuthRequest, so the old URL now throws before the login page
91
+ // is ever rendered — an AuthorizationError from inside the library, not from
92
+ // any code in this repo. Registering first is the fix, and it exercises the
93
+ // path a real client actually takes.
94
+ const redirectUri = 'https://example.com/callback';
95
+ const registration = await SELF.fetch('https://example.com/register', {
96
+ method: 'POST',
97
+ headers: { 'content-type': 'application/json' },
98
+ body: JSON.stringify({
99
+ client_name: 'worker test client',
100
+ redirect_uris: [redirectUri],
101
+ token_endpoint_auth_method: 'none',
102
+ }),
103
+ });
104
+ expect(registration.status).toBe(201);
105
+ const { client_id: clientId } = (await registration.json()) as { client_id: string };
106
+ expect(clientId).toBeTruthy();
107
+
108
+ // PKCE is mandatory for a public client (`token_endpoint_auth_method: none`)
109
+ // on the authorization-code flow, and the provider enforces it during the
110
+ // same parse. The challenge is never redeemed here — this test stops at the
111
+ // rendered page — so any well-formed S256 value will do.
112
+ const codeChallenge = 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM';
90
113
  const res = await SELF.fetch(
91
114
  'https://example.com/authorize?response_type=code&state=abc' +
92
- `&redirect_uri=${encodeURIComponent('https://example.com/callback')}`,
115
+ `&client_id=${encodeURIComponent(clientId)}` +
116
+ `&redirect_uri=${encodeURIComponent(redirectUri)}` +
117
+ `&code_challenge=${codeChallenge}&code_challenge_method=S256`,
93
118
  );
94
119
  expect(res.status).toBe(200);
95
120
  expect(res.headers.get('content-type')).toContain('text/html');