ssotest

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

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

View Source
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

func AuthnRequest(t testing.TB, redirectURL string) (id, acs, relay string)

AuthnRequest reads an HTTP-Redirect AuthnRequest URL: the request's ID, its ACS URL and the RelayState.

func Encode

func Encode(doc *etree.Document) string

Encode base64-encodes a document.

func Encrypt

func Encrypt(assertion *etree.Element, sp *x509.Certificate, dataAlg string) *etree.Element

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 KeyPEM

func KeyPEM(key *rsa.PrivateKey) string

KeyPEM encodes an RSA key as PKCS #8 PEM.

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.

func NewOIDC

func NewOIDC(t testing.TB) *OIDC

NewOIDC starts a fake provider; it stops when the test ends.

func (*OIDC) Authorize

func (o *OIDC) Authorize(t testing.TB, authURL string) url.Values

Authorize plays the person consenting at authURL: it records the PKCE challenge and nonce and returns the query the IdP would redirect back with (code and state).

func (*OIDC) Issuer

func (o *OIDC) Issuer() string

Issuer is the provider's issuer.

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

func NewSAMLIdP(t testing.TB, entityID string) *SAMLIdP

NewSAMLIdP makes an IdP with a fresh RSA key and self-signed certificate.

func (*SAMLIdP) AssertionElement

func (i *SAMLIdP) AssertionElement(a Assertion) *etree.Element

AssertionElement builds the (unsigned) assertion element.

func (*SAMLIdP) EncryptedResponse

func (i *SAMLIdP) EncryptedResponse(a Assertion, sp *x509.Certificate, dataAlg string) string

EncryptedResponse is ResponseDocument with its assertion encrypted for sp.

func (*SAMLIdP) Response

func (i *SAMLIdP) Response(a Assertion) string

Response returns the base64 SAMLResponse an ACS post carries.

func (*SAMLIdP) ResponseDocument

func (i *SAMLIdP) ResponseDocument(a Assertion) *etree.Document

ResponseDocument builds the whole response document.

func (*SAMLIdP) Sign

func (i *SAMLIdP) Sign(el *etree.Element, sha1 bool) *etree.Element

Sign signs el in place of itself (an enveloped signature).

func (*SAMLIdP) Signer

func (i *SAMLIdP) Signer() crypto.Signer

Signer is the IdP's signing key, for a test that signs its own messages (a LogoutRequest over the redirect binding).

func (*SAMLIdP) Valid

func (i *SAMLIdP) Valid(acs, audience, inResponseTo, nameID string) Assertion

Valid returns an Assertion that a correctly configured SP accepts now.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL