Documentation
¶
Overview ¶
Package oauthtest runs a fake OpenID Provider for the tests of servers that use mcp-oauth, shaped like Dex on a private management cluster: discovery and the JWKS under /dex, served over TLS with a certificate of its own on a hostname that resolves to an RFC 1918 address of this machine. mcp-oauth reaches it as it reaches a real Dex, through its guarded dialers, so a test exercises the production validation path: signature, issuer, audience, expiry and the private-address rules.
A test using New cannot be parallel: New calls t.Setenv, and it replaces net.DefaultResolver for the rest of the test so that IssuerHost and KeysHost resolve.
Index ¶
- Constants
- func Settings(t testing.TB, env map[string]string) oauthconfig.Settings
- type IdP
- func (p *IdP) AccessToken(t testing.TB, audience []string, claims map[string]any) string
- func (p *IdP) Env() map[string]string
- func (p *IdP) IDToken(t testing.TB, audience []string, claims map[string]any) string
- func (p *IdP) TrustedIssuers(t testing.TB, audiences []string, more map[string]any) string
- type Option
Constants ¶
const ( // IssuerHost is the hostname of the issuer. IssuerHost = "idp.test" // KeysHost is the hostname of the JWKS with [WithJWKSOnKeysHost]. KeysHost = "keys.test" // ClientID is the client the environment of [IdP.Env] signs in with // and trusts forwarded ID tokens for. ClientID = "oauthtest-client" // Subject, Email, Name and Group are the claims a minted token carries // unless the caller overrides them. Subject = "oauthtest-subject" Email = "person@idp.test" Name = "Test Person" Group = "oauthtest-group" )
Variables ¶
This section is empty.
Functions ¶
func Settings ¶
Settings sets env for the rest of t, with every other inherited OAUTH_* variable unset, and returns what oauthconfig.SettingsFromEnv reads from it.
Types ¶
type IdP ¶
type IdP struct {
// Issuer is https://idp.test:<port>/dex.
Issuer string
// JWKSURI is the jwks_uri discovery advertises: on IssuerHost, or on
// KeysHost with WithJWKSOnKeysHost.
JWKSURI string
// CAFile is the PEM file of the self-signed certificate the provider
// serves, which is its own CA.
CAFile string
// contains filtered or unexported fields
}
IdP is a running fake OpenID Provider.
func New ¶
New starts a provider that stops when t ends. It skips t when the machine has no RFC 1918 IPv4 address, since mcp-oauth never fetches a JWKS from loopback, or when the process proxy setting, which net/http reads once, routes the test hosts through a proxy.
func (*IdP) AccessToken ¶
AccessToken is IdP.IDToken with the RFC 9068 typ at+jwt, the type a trusted issuer entry accepts by default.
func (*IdP) Env ¶
Env is the OAUTH_* environment of a server that signs people in with this provider as Dex and accepts its ID tokens forwarded for ClientID. Change the map before passing it to Settings, for example to set OAUTH_ALLOW_PRIVATE_IP_JWKS_HOSTS or OAUTH_TRUSTED_ISSUERS.
func (*IdP) IDToken ¶
IDToken mints an ID token (typ JWT) for audience, valid for 30 minutes, for Subject with the Email, Name and Group profile. claims are added last and replace any of these, registered claims included.
func (*IdP) TrustedIssuers ¶
TrustedIssuers is an OAUTH_TRUSTED_ISSUERS value with one entry for this provider: its issuer, JWKS URI and CA, and audiences. The keys of more, such as openIDProvider, acceptedTypHeaders or allowPrivateIPJWKSHosts, are added last and replace any of these.