3.8 KiB
3.8 KiB
@suaveplan/testing-integration-oauth-mock - Real-HTTP mock OAuth 2.0 IdP fixture with PKCE, primeUser/primeError control, and full request audit
Real-HTTP mock OAuth 2.0 Identity Provider for integration tests.
createMockOauthIdp(opts) boots a real node:http listener on an
ephemeral 127.0.0.1 port and implements:
GET /authorize— issues an authorization code, captures PKCE challenge, echoes state.POST /token—authorization_codeandrefresh_tokengrants; PKCEplain+S256verification with rotated refresh tokens.GET /userinfo— Bearer-authenticated user payload shaped asgithub(default),google,generic, or via a customuserMapper.GET /.well-known/openid-configuration+GET /jwks.json— gated onopenid: true.
Test-control levers:
primeUser({ … })— FIFO queue of user payloads for the next/userinforesponse.primeError("access_denied" | …)— FIFO queue of RFC-6749 error codes for the next/authorize.lastRequest()/allRequests()— frozen audit records of every served HTTP request.
Documentation tree
- audit —
AuditLogis the request-recorder that backs thelastRequest()andallRequests()accessors on the mock IdP handle.… - primer —
Primeris the in-memory control surface that lets a test author tell the mock IdP "the next user-info response should… - authorize —
handleAuthorizeimplements the OAuth 2.0 authorization-code endpoint (RFC-6749 §4.1.1) for the mock IdP. It issues a… - openid —
handleOpenIdConfigserves the/.well-known/openid-configurationdiscovery document andhandleJwksserves the matc… - token —
handleTokenimplements the OAuth 2.0 token endpoint (RFC-6749 §4.1.3 and §6) for the mock IdP. It supports two grant… - userinfo —
handleUserInfoimplements the OAuth/OIDC userinfo endpoint. Given aBearerauthorization header, it looks up the as… - error-codes — This module defines the closed registry of error codes raised by
@suaveplan/testing-integration-oauth-mock. The packa…- error-codes — This module defines the closed registry of error codes raised by
@suaveplan/testing-integration-oauth-mock. The packa…
- error-codes — This module defines the closed registry of error codes raised by
- server —
createMockOauthIdpboots a real HTTP listener (Node'shttp.createServer) on an ephemeral port and routes OAuth 2.0…- server —
createMockOauthIdpboots a real HTTP listener (Node'shttp.createServer) on an ephemeral port and routes OAuth 2.0…
- server —
- generic —
buildGenericUserproduces an OIDC-flavoured userinfo payload with the commonsub/email/nameclaims. It is t… - github —
buildGithubUserproduces a userinfo payload that closely mirrors theGET https://api.github.com/userresponse GitHu… - google —
buildGoogleUserproduces a Google OIDC-style userinfo payload that matches the response Google's `/oauth2/v3/userinfo…
Quick start
import { createMockOauthIdp } from "@suaveplan/testing-integration-oauth-mock";
const idp = await createMockOauthIdp({ userShape: "github" });
idp.primeUser({ id: 42, login: "alice" });
// drive a Better-Auth / next-auth GitHub provider against `idp.url`
await idp.stop();
Compliance
- Rule 8 — testing-infrastructure: no
@suaveplan/*runtime dependencies; onlynode:*builtins. - Rule 11 — test-runner imports go through
@suaveplan/testing/runner. - Rule 2 — real HTTP, no mocking libraries.