authtest

package
v0.0.0-...-51f9457 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authtest implements authentication related test helpers.

Index

Constants

View Source
const (
	DefaultFakeEmail    = "fake_test@example.com"
	DefaultFakeLifetime = 5 * time.Minute
)

Defaults for FakeTokenGenerator.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeTokenGenerator

type FakeTokenGenerator struct {
	Email      string        // email of the default account (default "fake_test@example.com")
	Prefix     string        // prefix of fake generated tokens (default "fake_token_")
	Lifetime   time.Duration // lifetime of the returned token (default 5 min)
	KeepRecord bool          // if true, record all generated tokens
	// contains filtered or unexported fields
}

FakeTokenGenerator implements localauth.TokenGenerator by returning fake data.

Useful for integration tests that involve local auth server.

Each GenerateOAuthToken and GenerateIDToken call returns a token "<prefix><N>", where "<prefix>" is by default "fake_token_" (it can be changed via Prefix) and N starts from 0 and incremented for each call.

If KeepRecord is true, each generated token is recorded along with a list of scopes that were used to generate it. Use TokenScopes() to see what scopes have been used to generate a particular token.

func (*FakeTokenGenerator) GenerateIDToken

func (f *FakeTokenGenerator) GenerateIDToken(ctx context.Context, audience string, lifetime time.Duration) (*oauth2.Token, error)

GenerateIDToken is part of TokenGenerator interface.

func (*FakeTokenGenerator) GenerateOAuthToken

func (f *FakeTokenGenerator) GenerateOAuthToken(ctx context.Context, scopes []string, lifetime time.Duration) (*oauth2.Token, error)

GenerateOAuthToken is part of TokenGenerator interface.

func (*FakeTokenGenerator) GetEmail

func (f *FakeTokenGenerator) GetEmail() (string, error)

GetEmail is part of TokenGenerator interface.

func (*FakeTokenGenerator) TokenScopes

func (f *FakeTokenGenerator) TokenScopes(token string) []string

TokenScopes returns scopes that were used to generate given fake token.

Returns nil for unknown tokens or if KeepRecord is false and tokens weren't recorded.

Jump to

Keyboard shortcuts

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