Help us shape the future of Go! Take the 2026 Go Developer Survey

mock

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mock provides in-memory and stub implementations that facilitate unit testing of the client-side authorization flow.

The mocks allow tests to simulate OAuth2/OIDC interactions without performing actual network round-trips.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestClient

func NewTestClient(issuer string) *oauth2.Config

Types

type AuthorizationService

type AuthorizationService struct {
	PrivateKey              *rsa.PrivateKey
	Issuer                  string
	ClientID                string
	ClientSecret            string
	AuthorizedScopes        []string
	TokenHandler            func(w http.ResponseWriter, r *http.Request)
	AuthorizeHandler        func(w http.ResponseWriter, r *http.Request)
	MetadataHandler         func(w http.ResponseWriter, r *http.Request)
	ResourceHandler         func(w http.ResponseWriter, r *http.Request)
	ResourceMetadataHandler func(w http.ResponseWriter, r *http.Request)
	// JwksHandler handles requests for the JSON Web Key Set
	JwksHandler func(w http.ResponseWriter, r *http.Request)
}

AuthorizationService is a test server that simulates an OAuth2 authorization server

func NewAuthorizationService

func NewAuthorizationService(opts ...Option) (*AuthorizationService, error)

NewAuthorizationService creates a new mock OAuth2 authorization server

func (*AuthorizationService) Handler

func (m *AuthorizationService) Handler() http.Handler

Handler returns an http.Handler for all mock endpoints, suitable for any HTTP server.

func (*AuthorizationService) Register

func (m *AuthorizationService) Register(mux *http.ServeMux)

Register registers HTTP handlers for all mock endpoints onto the given ServeMux.

type HTTPTestAuthorizationServer

type HTTPTestAuthorizationServer struct {
	*AuthorizationService
	Server *httptest.Server
	Issuer string
}

func NewHTTPTestAuthorizationServer

func NewHTTPTestAuthorizationServer() (*HTTPTestAuthorizationServer, error)

func (*HTTPTestAuthorizationServer) Close

func (s *HTTPTestAuthorizationServer) Close()

type Handler

type Handler struct {
	// Server is the mock authorization server with endpoint handlers.
	Server *AuthorizationService
}

Handler routes HTTP requests to the appropriate mock OAuth2 server endpoints.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches incoming HTTP requests based on URL path.

type Option

type Option func(server *AuthorizationService)

Jump to

Keyboard shortcuts

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