test

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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) Expand added in v0.0.15

func (c *Credentials) Expand(_ context.Context, value string) (string, error)

Expand returns the value, as it is

func (*Credentials) Get added in v0.0.15

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

type GitHub struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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

func NewGitHub(t testing.TB) *GitHub

NewGitHub returns a fake GitHub, which is closed when the test ends

func (*GitHub) APIURL added in v0.0.15

func (g *GitHub) APIURL() string

APIURL is the URL of the fake's API

func (*GitHub) Code added in v0.0.15

func (g *GitHub) Code(challenge string, user GitHubUser) string

Code returns a code for the challenge, whose token is for the user, which is exchanged once

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

type OAuth struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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

func NewOAuth(t testing.TB) *OAuth

NewOAuth returns a fake resource and authorization server, which is closed when the test ends

func (*OAuth) Approve added in v0.0.15

func (o *OAuth) Approve(authorizeURL string) (string, error)

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

func (o *OAuth) Client(id, secret string, redirects ...string)

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

func (o *OAuth) ResourceURL() string

ResourceURL is the URL of the fake's resource

func (*OAuth) Revoke added in v0.0.15

func (o *OAuth) Revoke()

Revoke makes every token the server issued invalid, so it needs to be authorized again

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

func NewOIDC(t testing.TB) *OIDC

NewOIDC returns a fake issuer, whose audience is client, which is closed when the test ends

func (*OIDC) Code added in v0.0.15

func (i *OIDC) Code(challenge string, claims map[string]any) string

Code returns a code for the challenge, whose ID token has the claims, which is exchanged once

func (*OIDC) Sign added in v0.0.15

func (i *OIDC) Sign(claims map[string]any) string

Sign returns an ID token with the claims, from the issuer, for its audience, which expires in an hour, unless the claims say otherwise

Jump to

Keyboard shortcuts

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