testoauth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testoauth is a fake OAuth 2.0 authorization and token server for tests, with a stand-in for the user's browser.

Index

Constants

View Source
const ClientID = "godwit-test"

ClientID is the only client the server knows.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	URL    string
	Status int
	Body   string
}

Callback is the browser's visit to the app's loopback redirect.

func Get

func Get(t *testing.T, u string) Callback

Get visits a loopback URL as the browser would.

type Server

type Server struct {
	AuthURL, TokenURL string
	// contains filtered or unexported fields
}

Server issues codes, tokens and unsigned id_tokens. Refresh tokens do not rotate unless RotateRefresh(true).

func Start

func Start(t *testing.T) *Server

Start runs a Server until the test ends.

func (*Server) Browse

func (s *Server) Browse(t *testing.T, authURL, email string) Callback

Browse plays the user's browser: it opens authURL, signs in as email and follows the server's redirect to the loopback address.

func (*Server) Config

func (s *Server) Config(scopes ...string) auth.OAuthConfig

Config is an OAuthConfig for this server.

func (*Server) Deny

func (s *Server) Deny(deny bool)

Deny makes the user refuse consent: the server redirects with error=access_denied.

func (*Server) Hang

func (s *Server) Hang(t *testing.T) (release func())

Hang makes token requests wait, without an answer, until release is called or the client goes away. release also runs when the test ends.

func (*Server) OmitExpiry

func (s *Server) OmitExpiry(on bool)

OmitExpiry makes token responses leave out expires_in.

func (*Server) RespondNext

func (s *Server) RespondNext(status int, body string)

RespondNext makes the token endpoint answer its next request with status and a JSON body, whatever was asked.

func (*Server) RevokeAccess

func (s *Server) RevokeAccess()

RevokeAccess invalidates every access token issued so far; refresh tokens still work.

func (*Server) RevokeAll

func (s *Server) RevokeAll()

RevokeAll invalidates every refresh and access token issued so far.

func (*Server) RotateRefresh

func (s *Server) RotateRefresh(on bool)

RotateRefresh makes each refresh issue a new refresh token. The old one stays valid, as Microsoft's do until they expire.

func (*Server) S256Requested

func (s *Server) S256Requested() bool

S256Requested reports whether every authorization request so far asked for code_challenge_method=S256 (false before the first).

func (*Server) SetEmail

func (s *Server) SetEmail(email string)

SetEmail makes later id_tokens name email whoever signed in; "" undoes it.

func (*Server) TokenRequests

func (s *Server) TokenRequests() int

TokenRequests is how many requests the token endpoint has received.

func (*Server) ValidAccess

func (s *Server) ValidAccess(token string) bool

ValidAccess reports whether token is a live access token.

func (*Server) VerifierChecked

func (s *Server) VerifierChecked() bool

VerifierChecked reports whether every code exchange so far sent a code_verifier matching its challenge (false before the first).

Jump to

Keyboard shortcuts

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