Help us shape the future of Go! Take the 2026 Go Developer Survey

authtest

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package authtest is a fake GitHub OAuth server for device-flow and refresh tests. It listens on loopback only and issues obviously fake tokens (ghu_test_access_N, ghr_test_refresh_N). Like GitHub, it answers OAuth errors with HTTP 200 and an "error" field, and it rotates the refresh token on every refresh, so a second refresh with the old one fails the way it does at GitHub.

Index

Constants

View Source
const (
	ClientID   = "Iv1.test-client"
	DeviceCode = "dc_test_1"
	UserCode   = "WDJB-MJHT"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Pending       int    // polls answered authorization_pending before the approval
	SlowDown      bool   // the first poll answers slow_down (with interval 10)
	Deny          bool   // polls answer access_denied
	ExpiredCode   bool   // polls answer expired_token
	CodeExpiresIn int    // the device code's lifetime in seconds; 0 means 900
	RefreshToken  string // a valid refresh token to start with, for refresh-only tests
	RefreshBad    bool   // every refresh answers bad_refresh_token
	EchoSecrets   bool   // error replies repeat the posted form (tokens included) in error_description
	Fail500       bool   // every request fails with HTTP 500, its body repeating the posted form
	RefreshGate   func() // runs inside each refresh before it answers (the race test blocks here)
}

Options script the server. They are fixed when it starts, so tests never race the handler.

type Server

type Server struct {
	URL      string
	ClientID string
	// contains filtered or unexported fields
}

func New

func New(t testing.TB, o Options) *Server

New starts a server and stops it when the test ends.

func (*Server) AccessToken

func (s *Server) AccessToken(n int) string

AccessToken and RefreshToken are the n-th pair the server issues (from 1).

func (*Server) Client

func (s *Server) Client() *http.Client

func (*Server) Forms

func (s *Server) Forms() []url.Values

Forms are the posted forms, in order.

func (*Server) Polls

func (s *Server) Polls() int

func (*Server) RefreshToken

func (s *Server) RefreshToken(n int) string

func (*Server) Refreshes

func (s *Server) Refreshes() int

Jump to

Keyboard shortcuts

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