apistockdocs
v0.4 GitHub apistock.dev
Technical/Test helpers

modules/auth/social/socialtest

import "apistock.dev/modules/auth/social/socialtest"Source on GitHub

Package socialtest runs an in-process OpenID Connect provider standing in for Google or Apple in tests: it serves signing keys, a token endpoint and a revocation endpoint, and issues signed ID tokens, authorization codes and Apple notifications. Point a social provider at it with Endpoints.

Types#

type Claims#

go
type Claims struct {
	Subject       string
	Audience      string
	Email         string
	EmailVerified bool
	PrivateEmail  bool
	Nonce         string
	Name          string
	// IssuedAt defaults to the server's Now; Issuer to its URL.
	IssuedAt time.Time
	Issuer   string
	// Extra adds or replaces claims; a nil value removes one.
	Extra map[string]any
}

Claims describe an ID token to issue.

type Server#

go
type Server struct {
	// URL is the server's base URL and issuer.
	URL string
	// Now is the clock for issued tokens. Default: time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Server is a fake provider. It is safe for concurrent use.

func New#

go
func New(t testing.TB) *Server

New starts a server, closed when the test ends.

func (*Server) Code#

go
func (s *Server) Code(c Claims, refreshToken string) string

Code returns a single-use authorization code whose exchange returns an ID token with c's claims and refreshToken (none when empty).

func (*Server) Endpoints#

go
func (s *Server) Endpoints() social.Endpoints

Endpoints returns the server's endpoints for a social provider.

func (*Server) FailRevocations#

go
func (s *Server) FailRevocations(fail bool)

FailRevocations makes the revocation endpoint answer 503 while fail is true, to test retries.

func (*Server) IDToken#

go
func (s *Server) IDToken(c Claims) string

IDToken returns a signed ID token with c's claims, valid for an hour.

func (*Server) Notification#

go
func (s *Server) Notification(audience, eventType, subject string) string

Notification returns a signed Apple server-to-server notification.

func (*Server) Revoked#

go
func (s *Server) Revoked() []string

Revoked returns every token revoked.

func (*Server) TokenRequests#

go
func (s *Server) TokenRequests() []url.Values

TokenRequests returns the form of every token request received.

v0.4
esc
↑↓ move↵ openesc close