idptest

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

A Client allows tests to simulate sending HTTP requests to an IDP.

func NewClient

func NewClient(idp idp.IdentityProvider, codec *secret.Codec) *Client

NewClient create a new client for the given IDP.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do simulates a round trip to the idp handler.

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

Get simulates a get request on the idp handler.

func (*Client) SetLoginState

func (c *Client) SetLoginState(state idputil.LoginState)

SetLoginStatus sets a login status that will be added to every request.

type Fixture

type Fixture struct {
	// Ctx holds a context appropriate for using
	// for store methods.
	Ctx context.Context

	// Codec contains a codec that will be passed in the idp.InitParams.
	Codec *secret.Codec

	// Oven contains a bakery.Oven that will be passed in the
	// idp.InitParams. Tests can use this to mint macaroons if
	// necessary.
	Oven *bakery.Oven

	// Store holds the store used by the fixture.
	Store *candidtest.Store

	// Template holds the template to use for generating pages
	Template *template.Template
	// contains filtered or unexported fields
}

Fixture provides a test fixture that is helpful for testing identity providers.

func NewFixture

func NewFixture(c *qt.C, store *candidtest.Store) *Fixture

func (*Fixture) AssertLoginFailureMatches

func (s *Fixture) AssertLoginFailureMatches(c *qt.C, regex string)

AssertLoginFailureMatches asserts that the login test has resulted in a failure with an error that matches the given regex.

func (*Fixture) AssertLoginNotComplete

func (s *Fixture) AssertLoginNotComplete(c *qt.C)

AssertLoginNotComplete asserts that the login attempt has not yet completed.

func (*Fixture) AssertLoginRedirectFailureMatches

func (s *Fixture) AssertLoginRedirectFailureMatches(c *qt.C, rurl, returnTo, state, errorCode, regex string)

AssertLoginRedirectFailureMatches asserts that the login test has resulted in a failure with an error that matches the given regex.

func (*Fixture) AssertLoginRedirectSuccess

func (s *Fixture) AssertLoginRedirectSuccess(c *qt.C, rurl, returnTo, state string, username string)

AssertLoginRedirectSuccess asserts that the given redirect URL is for a successful login of the given user.

func (*Fixture) AssertLoginSuccess

func (s *Fixture) AssertLoginSuccess(c *qt.C, username string)

AssertLoginSuccess asserts that the login test has resulted in a successful login of the given user.

func (*Fixture) Client

func (s *Fixture) Client(c *qt.C, prefix, replacement, stopPrefix string) *http.Client

Client creates an HTTP client that will replace the given prefix with the given replacement in all request URLs. The client will also stop redirecting and return the last response when a request with the given stopPrefix is attempted.

func (*Fixture) DoInteractiveLogin

func (s *Fixture) DoInteractiveLogin(c *qt.C, idp idp.IdentityProvider, loginURL string, f func(*http.Client, *http.Response) (*http.Response, error)) (*store.Identity, error)

DoInteractiveLogin performs a full interactive login cycle with the given IDP.

func (*Fixture) InitParams

func (s *Fixture) InitParams(c *qt.C, prefix string) idp.InitParams

InitParams returns a completed InitParams that a test can use to pass to idp.Init.

func (*Fixture) LoginState

func (s *Fixture) LoginState(c *qt.C, state idputil.LoginState) (*http.Cookie, string)

LoginState creates a candid-login with the given login state.

func (*Fixture) ParseResponse

func (s *Fixture) ParseResponse(c *qt.C, resp *http.Response) (*store.Identity, error)

ParseResponse parses a store.Identity from the given HTTP response.

func (*Fixture) Reset

func (f *Fixture) Reset()

Jump to

Keyboard shortcuts

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