This commit is contained in:
Zai Shi 2025-05-20 15:35:07 -07:00
parent 6193bef251
commit 2191e1c023
3 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { encodeBase64Url } from "@stackframe/stack-shared/dist/utils/bytes";
import { encodeBasicAuthorizationHeader } from "@stackframe/stack-shared/dist/utils/http";
import { expect } from "vitest";
import { it, updateCookiesFromResponse } from "../../../../../../helpers";
import { Auth, InternalApiKey, Project, backendContext, niceBackendFetch } from "../../../../../backend-helpers";
@ -202,7 +203,7 @@ it(`should exchange the authorization code for an admin API key that works`, asy
redirect_uri: "http://localhost:30000/api/v2/auth/authorize",
},
headers: {
"Authorization": "Basic bmVvbi1sb2NhbDpuZW9uLWxvY2FsLXNlY3JldA=="
"Authorization": encodeBasicAuthorizationHeader("custom-local", "custom-local-secret")
},
});
expect(tokenResponse).toMatchInlineSnapshot(`
@ -256,7 +257,7 @@ it(`should not exchange the authorization code when the client secret is incorre
redirect_uri: "http://localhost:30000/api/v2/auth/authorize",
},
headers: {
"Authorization": "Basic bmVvbi1sb2NhbDpuZW9uLWxvY2FsLXNlY2JldA=="
"Authorization": encodeBasicAuthorizationHeader("custom-local", "wrong-secret")
},
});
expect(tokenResponse).toMatchInlineSnapshot(`

View File

@ -1,4 +1,5 @@
import { encodeBase64Url } from "@stackframe/stack-shared/dist/utils/bytes";
import { encodeBasicAuthorizationHeader } from "@stackframe/stack-shared/dist/utils/http";
import { expect } from "vitest";
import { it, updateCookiesFromResponse } from "../../../../../../helpers";
import { Auth, InternalApiKey, Project, backendContext, niceBackendFetch } from "../../../../../backend-helpers";
@ -202,7 +203,7 @@ it(`should exchange the authorization code for an admin API key that works`, asy
redirect_uri: "http://localhost:30000/api/v2/auth/authorize",
},
headers: {
"Authorization": "Basic bmVvbi1sb2NhbDpuZW9uLWxvY2FsLXNlY3JldA=="
"Authorization": encodeBasicAuthorizationHeader("neon-local", "neon-local-secret")
},
});
expect(tokenResponse).toMatchInlineSnapshot(`
@ -256,7 +257,7 @@ it(`should not exchange the authorization code when the client secret is incorre
redirect_uri: "http://localhost:30000/api/v2/auth/authorize",
},
headers: {
"Authorization": "Basic bmVvbi1sb2NhbDpuZW9uLWxvY2FsLXNlY2JldA=="
"Authorization": encodeBasicAuthorizationHeader("neon-local", "wrong-secret")
},
});
expect(tokenResponse).toMatchInlineSnapshot(`

View File

@ -482,6 +482,7 @@ export const basicAuthorizationHeaderSchema = yupString().test('is-basic-authori
// Neon integration
export const neonAuthorizationHeaderSchema = basicAuthorizationHeaderSchema.test('is-neon-authorization-header', 'Invalid client_id:client_secret values; did you use the correct values for the Neon integration?', (value) => {
if (!value) return true;
console.log("????????????", value, decodeBasicAuthorizationHeader(value));
const [clientId, clientSecret] = decodeBasicAuthorizationHeader(value) ?? throwErr(`Neon authz header invalid? This should've been validated by basicAuthorizationHeaderSchema: ${value}`);
for (const neonClientConfig of JSON.parse(process.env.STACK_INTEGRATION_CLIENTS_CONFIG || '[]')) {
if (clientId === neonClientConfig.client_id && clientSecret === neonClientConfig.client_secret) return true;