Documentation
¶
Overview ¶
Package oidctest is an in-memory OpenID Connect provider for tests: an httptest server with discovery, the token endpoint (authorization code with PKCE, refresh with rotation), userinfo, JWKS and revocation, signing id_tokens with ES256. Its knobs (Tamper) make each id_token check fail on its own, so a test can show a refusal comes from the check it names.
Index ¶
- Constants
- func SignES256(key *ecdsa.PrivateKey, header, claims map[string]any) string
- type Fake
- func (f *Fake) AddUser(u User)
- func (f *Fake) Advance(d time.Duration)
- func (f *Fake) Authorize(t testing.TB, authURL, sub string) url.Values
- func (f *Fake) Ban(sub string)
- func (f *Fake) Calls(path string) int
- func (f *Fake) FailNext(path string, n int)
- func (f *Fake) Issuer() string
- func (f *Fake) LiveRefreshTokens(sub string) int
- func (f *Fake) Now() time.Time
- func (f *Fake) RevokeRefreshTokens(sub string)
- func (f *Fake) Revoked() []string
- func (f *Fake) SetClock(clock func() time.Time)
- func (f *Fake) SetRoles(sub string, roles ...string)
- func (f *Fake) SetTamper(t Tamper)
- type Tamper
- type User
Constants ¶
const ( ClientID = "muster-test-client" ClientSecret = "muster-test-client-secret-0123456789" )
ClientID and ClientSecret are the one client the fake knows.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fake ¶
Fake is the provider.
func (*Fake) Authorize ¶
Authorize plays the browser at the authorization endpoint: it reads the authorization request muster redirected to (authURL), signs sub in, and returns the callback's query (code and state) as the provider would send the browser back with. It fails the test on a request muster should never make (wrong client, no PKCE S256, another redirect URI).
func (*Fake) LiveRefreshTokens ¶
LiveRefreshTokens is how many refresh tokens of sub the provider would still accept.
func (*Fake) Now ¶
Now is the fake's clock; SetNow and Advance move it. The provider under test must share it (oidc.Config.Now) for exp and iat to line up.
func (*Fake) RevokeRefreshTokens ¶
RevokeRefreshTokens makes every refresh token of sub invalid_grant.
func (*Fake) SetClock ¶
SetClock makes the fake read its time from clock (another fake's, so the two agree); Advance then has no effect.
type Tamper ¶
type Tamper struct {
Issuer string // "" = the fake's own issuer
Audience []string // nil = the client id
Azp string // "" = none
ExpIn time.Duration // 0 = 5 minutes; negative = already expired
IatIn time.Duration // 0 = now; positive = in the future
Nonce *string // nil = the authorization request's nonce
Subject *string // nil = the account's sub
OtherKey bool // sign with a key the JWKS does not publish (same kid)
Alg string // "" = ES256 (the header only; the signature stays ES256)
NoIDToken bool // answer the code with no id_token at all
AuthTime *time.Time // nil = now
NoRefresh bool // answer the code with no refresh token
UserinfoAs string // "" = the token's own account; else userinfo answers for this sub
}
Tamper changes what the NEXT id_tokens look like. The zero value is an honest token.