Documentation
¶
Overview ¶
Package ssotest runs a fake OpenID Connect provider and a fake SAML identity provider for tests of an app's SSO wiring: the OIDC side serves discovery, JWKS, a token endpoint that checks PKCE and the client, and userinfo; the SAML side signs responses with a fresh certificate. Neither is for production.
Index ¶
- Constants
- func AuthnRequest(t testing.TB, redirectURL string) (id, acs, relay string)
- func Encode(doc *etree.Document) string
- func Encrypt(assertion *etree.Element, sp *x509.Certificate, dataAlg string) *etree.Element
- func KeyPEM(key *rsa.PrivateKey) string
- func KeyPair(t testing.TB, cn string) (*rsa.PrivateKey, *x509.Certificate, string)
- type Assertion
- type OIDC
- type Person
- type SAMLIdP
- func (i *SAMLIdP) AssertionElement(a Assertion) *etree.Element
- func (i *SAMLIdP) EncryptedResponse(a Assertion, sp *x509.Certificate, dataAlg string) string
- func (i *SAMLIdP) Response(a Assertion) string
- func (i *SAMLIdP) ResponseDocument(a Assertion) *etree.Document
- func (i *SAMLIdP) Sign(el *etree.Element, sha1 bool) *etree.Element
- func (i *SAMLIdP) Signer() crypto.Signer
- func (i *SAMLIdP) Valid(acs, audience, inResponseTo, nameID string) Assertion
Constants ¶
const ( EncAES256GCM = "http://www.w3.org/2009/xmlenc11#aes256-gcm" EncAES128CBC = "http://www.w3.org/2001/04/xmlenc#aes128-cbc" EncTripleDES = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc" )
Encryption algorithms Encrypt can use.
Variables ¶
This section is empty.
Functions ¶
func AuthnRequest ¶
AuthnRequest reads an HTTP-Redirect AuthnRequest URL: the request's ID, its ACS URL and the RelayState.
func Encrypt ¶
Encrypt wraps a (usually signed) assertion in an EncryptedAssertion for the SP certificate: a fresh AES key under RSA-OAEP, the data under dataAlg (EncAES256GCM or EncAES128CBC). EncTripleDES only labels the data, for a test of the algorithm policy; it never decrypts.
func KeyPair ¶
func KeyPair(t testing.TB, cn string) (*rsa.PrivateKey, *x509.Certificate, string)
KeyPair makes an RSA key and a self-signed certificate valid for a day either side of now, and returns the certificate as PEM too.
Types ¶
type Assertion ¶
type Assertion struct {
ID string
NameID string
Audience string
Recipient string
Destination string
InResponseTo string
// Issuer defaults to the IdP's entity id.
Issuer string
NotBefore time.Time
NotOnOrAfter time.Time
// ConfirmationNotOnOrAfter bounds the SubjectConfirmationData instead
// of NotOnOrAfter when set, so the two can differ.
ConfirmationNotOnOrAfter time.Time
Attributes map[string][]string
// SignAssertion and SignResponse choose what is signed.
SignAssertion bool
SignResponse bool
// NoAudience leaves the AudienceRestriction out.
NoAudience bool
// SHA1 signs with RSA-SHA1 and a SHA-1 digest.
SHA1 bool
// Tamper, when set, edits the assertion element before it is signed:
// a test of content a real IdP would never send, signed all the same.
Tamper func(assertion *etree.Element)
}
Assertion describes the response a test wants.
type OIDC ¶
type OIDC struct {
URL string
ClientID string
ClientSecret string
// Person signs in at the next Authorize.
Person Person
// IDTokenClaims, when set, change the next ID token's claims (a test of
// a wrong aud, iss or azp).
IDTokenClaims func(claims map[string]any)
// UserInfoSubject, when set, is the sub userinfo answers.
UserInfoSubject string
// OmitIDToken leaves the id_token out of the token response.
OmitIDToken bool
// contains filtered or unexported fields
}
OIDC is a fake OpenID Connect provider.
type Person ¶
type Person struct {
Subject string
Email string
EmailVerified bool
Name string
// Extra claims are added to the ID token and userinfo.
Extra map[string]any
}
Person is who signs in at a fake IdP.
type SAMLIdP ¶
type SAMLIdP struct {
EntityID string
SSOURL string
// CertPEM is the signing certificate, for SAMLConfig.Cert.
CertPEM string
Cert *x509.Certificate
// contains filtered or unexported fields
}
SAMLIdP is a fake SAML identity provider.
func NewSAMLIdP ¶
NewSAMLIdP makes an IdP with a fresh RSA key and self-signed certificate.
func (*SAMLIdP) AssertionElement ¶
AssertionElement builds the (unsigned) assertion element.
func (*SAMLIdP) EncryptedResponse ¶
EncryptedResponse is ResponseDocument with its assertion encrypted for sp.
func (*SAMLIdP) ResponseDocument ¶
ResponseDocument builds the whole response document.