@auth0/nextjs-auth0
Version:
Auth0 Next.js SDK
71 lines (70 loc) • 2.28 kB
TypeScript
/**
* Test Helpers for Proxy Handler Tests
*
* Shared utilities for testing AuthClient proxy functionality with MSW mocking.
* These helpers support Bearer/DPoP authentication, session management, and
* DPoP nonce retry validation.
*/
import { SessionData } from "../types/index.js";
/**
* Create initial session data for testing
*
* @param overrides - Partial session data to override defaults
* @returns Complete SessionData object
*/
export declare function createInitialSessionData(overrides?: Partial<SessionData>): SessionData;
/**
* Create session cookie from session data
*
* @param sessionData - Session data to encrypt
* @param secretKey - Secret key for encryption
* @returns Cookie string in format "__session={encryptedValue}"
*/
export declare function createSessionCookie(sessionData: SessionData, secretKey: string): Promise<string>;
/**
* Extract DPoP nonce and claims from DPoP JWT header
*
* @param dpopHeader - DPoP JWT header value
* @returns Object with nonce presence, nonce value, and JWT claims
*/
export declare function extractDPoPInfo(dpopHeader: string | null): {
hasNonce: boolean;
nonce?: string;
htm?: string;
htu?: string;
jti?: string;
iat?: number;
};
/**
* Create stateful DPoP nonce retry handler for upstream API
*
* This handler tracks request attempts and simulates the DPoP nonce retry flow:
* - First request: Returns 401 with WWW-Authenticate header containing use_dpop_nonce error and DPoP-Nonce header
* - Second request: Returns success response
*
* Per RFC 9449 Section 8: Resource servers signal DPoP nonce requirement via 401 with WWW-Authenticate header
*
* @param config - Configuration for the handler
* @returns Handler function and state object for assertions
*/
export declare function createDPoPNonceRetryHandler(config: {
baseUrl: string;
path: string;
method: string;
successResponse?: any;
successStatus?: number;
}): {
handler: ({ request }: {
request: Request;
}) => Promise<Response>;
state: {
requestCount: number;
requests: Array<{
attempt: number;
hasDPoP: boolean;
hasNonce: boolean;
nonce?: string;
dpopJwt?: string;
}>;
};
};