test(oauth-provider): adapt merged token/private-key-jwt tests to next's APIs (#9533)

These test files auto-merged main's additions onto next's refactored test
surface, producing runtime failures tsc could not catch:

- token.test.ts called main's sync createRefreshAccessTokenRequest, which next
  renamed to the async refreshAccessTokenRequest; the calls now await it and
  the concurrent-rotation helper is async.
- private-key-jwt-e2e.test.ts hit the merged-in #9578 gate: both the provider
  and RP test instances create the same default user, so the OAuth sign-in
  links to the RP's unverified local user and is blocked. The RP sets
  requireLocalEmailVerified: false so the test exercises private_key_jwt
  rather than the (separately covered) email-verification gate.
- utils/basic-auth.test.ts is removed: next made basicToClientCredentials
  private, and its colon-preservation coverage now lives in core's
  basic-credentials.test.ts.

Full oauth-provider suite green (24 files, 378 tests).
This commit is contained in:
Gustavo Valverde
2026-05-31 01:51:34 +01:00
parent a99a331376
commit 0fe3590e16
3 changed files with 7 additions and 44 deletions
@@ -124,6 +124,7 @@ describe("private_key_jwt e2e", async () => {
account: {
accountLinking: {
trustedProviders: [providerId],
requireLocalEmailVerified: false,
},
},
plugins: [
@@ -265,6 +266,7 @@ describe("private_key_jwt e2e", async () => {
account: {
accountLinking: {
trustedProviders: [providerId],
requireLocalEmailVerified: false,
},
},
plugins: [
+5 -5
View File
@@ -1044,7 +1044,7 @@ describe("oauth token - refresh_token", async () => {
expect(tokens?.refresh_token).toBeDefined();
async function refresh(refreshToken: string) {
const { body, headers } = createRefreshAccessTokenRequest({
const { body, headers } = await refreshAccessTokenRequest({
refreshToken,
options: {
clientId: oauthClient!.client_id,
@@ -1102,7 +1102,7 @@ describe("oauth token - refresh_token", async () => {
expect(tokens?.refresh_token).toBeDefined();
async function refresh(refreshToken: string) {
const { body, headers } = createRefreshAccessTokenRequest({
const { body, headers } = await refreshAccessTokenRequest({
refreshToken,
options: {
clientId: oauthClient!.client_id,
@@ -1180,7 +1180,7 @@ describe("oauth token - refresh_token", async () => {
// Reusing the revoked refresh token must trip the family-invalidation
// guard in handleRefreshTokenGrant (revoked flag → invalidate family).
const { body: replayBody, headers: replayHeaders } =
createRefreshAccessTokenRequest({
await refreshAccessTokenRequest({
refreshToken: tokens!.refresh_token!,
options: {
clientId: oauthClient.client_id,
@@ -1218,8 +1218,8 @@ describe("oauth token - refresh_token", async () => {
expect(tokens?.refresh_token).toBeDefined();
const parentToken = tokens!.refresh_token!;
const refresh = () => {
const { body, headers } = createRefreshAccessTokenRequest({
const refresh = async () => {
const { body, headers } = await refreshAccessTokenRequest({
refreshToken: parentToken,
options: {
clientId: oauthClient!.client_id,
@@ -1,39 +0,0 @@
import { base64 } from "@better-auth/utils/base64";
import { describe, expect, it } from "vitest";
import { basicToClientCredentials } from "./index";
function encodeBasic(clientId: string, clientSecret: string) {
const raw = `${clientId}:${clientSecret}`;
const encoded = base64.encode(new TextEncoder().encode(raw));
return `Basic ${encoded}`;
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc7617#section-2
*/
describe("basicToClientCredentials", () => {
it("preserves colons inside client_secret per RFC 7617", () => {
const clientId = "cid";
const clientSecret = "pa:ss:word";
const result = basicToClientCredentials(
encodeBasic(clientId, clientSecret),
);
expect(result).toBeDefined();
expect(result?.client_id).toBe(clientId);
expect(result?.client_secret).toBe(clientSecret);
});
it("keeps a trailing colon as part of client_secret", () => {
const clientId = "cid";
const clientSecret = "secret:";
const result = basicToClientCredentials(
encodeBasic(clientId, clientSecret),
);
expect(result?.client_secret).toBe(clientSecret);
});
});