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 ¶
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.
type Option ¶
type Option func(server *AuthorizationService)
Click to show internal directories.
Click to hide internal directories.