mock

package
v0.0.0-...-a8b8e24 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateMockJWT

func GenerateMockJWT(subject, issuer, audience string) string

GenerateMockJWT generates a JWT ID token containing the passed sub/iss/aud claims. It is signed using HS256 with the secret "sharedsecret" -- only to be used for mocking tests.

func NewAuthenticator

func NewAuthenticator(iss, aud string, groups []string,
	connID, userID, email string, logger *zap.Logger) authenticator.Authenticator

NewAuthenticator returns a mock authenticator which requires no server interaction. It only checks claims and returns their name.

func NewHeaderTokenAuthenticator

func NewHeaderTokenAuthenticator(
	header string,
	tokens map[string]string,
	logger *zap.Logger) authenticator.Authenticator

NewHeaderTokenAuthenticator returns a mock authenticator which requires no server interaction. It only checks hard-coded tokens from the configured header.

func NewStaticAuthenticator

func NewStaticAuthenticator(externalID, connID, userID, email string, teams []string,
	logger *zap.Logger) authenticator.Authenticator

NewStaticAuthenticator returns a mock authenticator that always returns the passed requestor, its type, and connID. Only useful for dev and testing.

func NewStaticFailWithRequestorAuthenticator

func NewStaticFailWithRequestorAuthenticator(requestor string, err error) authenticator.Authenticator

NewStaticFailWithRequestorAuthenticator returns a mock authenticator always returns the passed requestor. Only for testing.

Types

type HeaderTokenAuthenticator

type HeaderTokenAuthenticator struct {
	// contains filtered or unexported fields
}

HeaderTokenAuthenticator is used for configuring static header-token authenticators

func (*HeaderTokenAuthenticator) Authenticate

Authenticate processes the passed request, checking if the configured header's FIRST value matches any of the the hard-coded tokens list.

type HeaderTokenConfig

type HeaderTokenConfig struct {
	Header string            `json:"header"`
	Tokens map[string]string `json:"tokens"`
}

HeaderTokenConfig is used for configuring static header-token authenticators

func (*HeaderTokenConfig) Open

Open returns an header token authenticator

type OidcAuthenticator

type OidcAuthenticator struct {
	// contains filtered or unexported fields
}

OidcAuthenticator is used for configuring mock-oidc authenticators

func (*OidcAuthenticator) Authenticate

func (a *OidcAuthenticator) Authenticate(r *http.Request) (authenticator.Requestor, error)

Authenticate processes the passed request, checking its ID token in the `Authorization: Bearer XY` header

type OidcConfig

type OidcConfig struct {
	Issuer   string   `json:"issuer"`
	Audience string   `json:"client_id"`
	Groups   []string `json:"groups"`
	ConnID   string   `json:"conn_id"`
	UserID   string   `json:"user_id"`
	Email    string
}

OidcConfig is used for configuring mock-oidc authenticators

func (*OidcConfig) Open

Open returns an authentication strategy that statically checks the iss and aud claims only

type StaticAuthenticator

type StaticAuthenticator struct {
	// contains filtered or unexported fields
}

StaticAuthenticator holds the state of a mock-static authenticator

func (*StaticAuthenticator) Authenticate

Authenticate processes the passed request, checking its ID token in the `Authorization: Bearer XY` header

type StaticConfig

type StaticConfig struct {
	ExternalID string   `json:"external_id"`
	ConnID     string   `json:"conn_id"`
	UserID     string   `json:"user_id"`
	Teams      []string `json:"teams"`
	Email      string
}

StaticConfig is used for configuring mock-static authenticators

func (*StaticConfig) Open

Open returns an authentication strategy that always returns the configured requestor.

type StaticFailWithRequestorAuthenticator

type StaticFailWithRequestorAuthenticator struct {
	// contains filtered or unexported fields
}

StaticFailWithRequestorAuthenticator holds the state of the fail_with_requestor authenticator

func (*StaticFailWithRequestorAuthenticator) Authenticate

Authenticate returns the configured requestor AND the configured error != nil

type StaticFailWithRequestorConfig

type StaticFailWithRequestorConfig struct {
	Requestor string `json:"requestor"`
	ErrorMsg  string `json:"error"`
}

StaticFailWithRequestorConfig is used for configuring the fail_with_requestor authenticator Note: This config is NOT exposed in server/authenticators.go, so it can't be chosen for any

purpose outside of tests -- because it really shouldn't.

func (*StaticFailWithRequestorConfig) Open

Open returns an authentication strategy that always returns the configured requestor AND an error != nil.

Jump to

Keyboard shortcuts

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