socialtest

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package socialtest provides a backend-agnostic conformance suite for the social.Store interface. Every backend (memory, sqlite, postgres, mongo) is expected to pass the same contract, so behavioral drift between them is caught here rather than in production.

An OAuth connection holds the provider tokens that stand in for a user's password at Google or GitHub, so the cases lean on whether those survive a write and whether a refresh actually replaces them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeURLParam added in v1.10.0

func AuthorizeURLParam(authURL, name string) string

AuthorizeURLParam reads one query parameter from an authorization URL the plugin built, such as nonce or client_id.

func RunConformance

func RunConformance(t *testing.T, newFixture Factory, skip ...string)

RunConformance runs every contract test against fixtures from newFixture.

Types

type Factory

type Factory func(t *testing.T) Fixture

Factory builds a fresh, empty, migrated fixture for a single test.

type Fixture

type Fixture struct {
	Store  social.Store
	AppID  id.AppID
	UserID id.UserID
	// OtherUserID is a second user under the same app, used to prove that
	// listing a user's connections does not reach past them.
	OtherUserID id.UserID
	// OtherAppID and OtherAppUser are a second tenant.
	OtherAppID   id.AppID
	OtherAppUser id.UserID
}

Fixture is one backend ready to test, plus the rows its connections hang off.

type Issuer added in v1.10.0

type Issuer struct {
	Server   *httptest.Server
	URL      string
	ClientID string

	// DiscoveryHits counts fetches of the discovery document.
	DiscoveryHits atomic.Int32
	// TokenRequests counts calls to the token endpoint.
	TokenRequests atomic.Int32
	// contains filtered or unexported fields
}

Issuer is a minimal OpenID Connect issuer for tests: discovery, JWKS, a token endpoint that returns a signed id_token, and userinfo. It serves TLS, so use Client() for calls to it.

func NewIssuer added in v1.10.0

func NewIssuer(t *testing.T, clientID string) *Issuer

NewIssuer starts an issuer whose tokens are for clientID. It stops when the test ends.

func (*Issuer) Client added in v1.10.0

func (i *Issuer) Client() *http.Client

Client trusts the issuer's certificate.

func (*Issuer) SetClaims added in v1.10.0

func (i *Issuer) SetClaims(claims map[string]any)

SetClaims sets the claims the token endpoint's next id_tokens carry, on top of the defaults Sign adds.

func (*Issuer) SetUserInfo added in v1.10.0

func (i *Issuer) SetUserInfo(info map[string]any)

SetUserInfo sets the userinfo response. Nil answers 404.

func (*Issuer) Sign added in v1.10.0

func (i *Issuer) Sign(claims map[string]any) string

Sign returns an RS256 id_token with iss, aud, sub, iat and exp filled in unless claims sets them.

func (*Issuer) SignWithOtherKey added in v1.10.0

func (i *Issuer) SignWithOtherKey(claims map[string]any) string

SignWithOtherKey signs with a key the JWKS does not publish.

Jump to

Keyboard shortcuts

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