Documentation
¶
Overview ¶
Package test has fake providers, which tests sign in with: an OpenID Connect issuer, and GitHub, each an HTTP server, which gives the identity it's told to, for a code, once, when it's exchanged with the verifier of its PKCE challenge.
Index ¶
- Constants
- func SignIn(t testing.TB, ctx context.Context, p provider.RedirectProvider, ...) schema.Credential
- type Credentials
- func (c *Credentials) Delete(_ context.Context, key string) error
- func (c *Credentials) Expand(_ context.Context, value string) (string, error)
- func (c *Credentials) Get(_ context.Context, key string) (json.RawMessage, error)
- func (c *Credentials) Set(_ context.Context, key string, value json.RawMessage) error
- func (c *Credentials) WithClient(key, clientID, clientSecret string) *Credentials
- type GitHub
- type GitHubEmail
- type GitHubUser
- type OAuth
- type OIDC
Constants ¶
const ResourcePath = "/resource"
ResourcePath is the path of the fake's resource, which needs a token
Variables ¶
This section is empty.
Functions ¶
func SignIn ¶ added in v0.0.15
func SignIn(t testing.TB, ctx context.Context, p provider.RedirectProvider, code func(challenge string) string) schema.Credential
SignIn returns the credential of a sign-in with a provider: the code the fake gives for the challenge of the provider's sign-in page, with its verifier, and the redirect URL. code returns the code for a challenge, such as one of OIDC's, or GitHub's.
Types ¶
type Credentials ¶ added in v0.0.15
type Credentials struct {
// contains filtered or unexported fields
}
Credentials is a credential provider in memory, such as of providers' OAuth clients
func NewCredentials ¶ added in v0.0.15
func NewCredentials() *Credentials
NewCredentials returns credentials, without any
func (*Credentials) Delete ¶ added in v0.0.17
func (c *Credentials) Delete(_ context.Context, key string) error
Delete deletes the credential at the key, or returns not found
func (*Credentials) Get ¶ added in v0.0.15
func (c *Credentials) Get(_ context.Context, key string) (json.RawMessage, error)
Get returns the credential at the key, or not found
func (*Credentials) Set ¶ added in v0.0.15
func (c *Credentials) Set(_ context.Context, key string, value json.RawMessage) error
Set stores the credential at the key
func (*Credentials) WithClient ¶ added in v0.0.15
func (c *Credentials) WithClient(key, clientID, clientSecret string) *Credentials
WithClient stores an OAuth client, with its ID and secret, at the key, and returns the credentials
type GitHub ¶ added in v0.0.15
GitHub is a fake GitHub, at its URL, with its API at APIURL, which gives a token for a code, and the user, email addresses and organisations it's for, from the API
func NewGitHub ¶ added in v0.0.15
NewGitHub returns a fake GitHub, which is closed when the test ends
type GitHubEmail ¶ added in v0.0.15
type GitHubEmail struct {
Email string `json:"email"`
Primary bool `json:"primary"`
Verified bool `json:"verified"`
}
GitHubEmail is one of a user's email addresses
type GitHubUser ¶ added in v0.0.15
type GitHubUser struct {
ID int64
Login string
Name string
Email string // public, which can be empty
Emails []GitHubEmail
Orgs []string
}
GitHubUser is a user of the fake GitHub
type OAuth ¶ added in v0.0.15
OAuth is a fake resource, at ResourcePath, which needs to be authorized, and its authorization server, which registers clients, approves their authorizations, as a person would, and exchanges codes, with their PKCE verifiers, and refresh tokens, for tokens
func NewOAuth ¶ added in v0.0.15
NewOAuth returns a fake resource and authorization server, which is closed when the test ends
func (*OAuth) Approve ¶ added in v0.0.15
Approve approves the authorization URL, as a person would, and returns the URL it redirects to, with a code, and its state, or an error, when it isn't a valid request, such as one without S256
func (*OAuth) Client ¶ added in v0.0.15
Client adds a client, with its secret, and redirect URIs, as one which is registered beforehand, rather than dynamically, would be
func (*OAuth) ResourceURL ¶ added in v0.0.15
ResourceURL is the URL of the fake's resource
type OIDC ¶ added in v0.0.15
type OIDC struct {
*httptest.Server
Audience string
// Issuer is the issuer the fake says it is, which is its URL, unless
// it's set, such as to its URL with a slash
Issuer string
// contains filtered or unexported fields
}
OIDC is a fake OpenID Connect issuer, at its URL, which signs ID tokens, for its audience, the client ID, with a key it publishes
func NewOIDC ¶ added in v0.0.15
NewOIDC returns a fake issuer, whose audience is client, which is closed when the test ends