githubtest

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 16 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 githubtest is a fake GitHub for tests of code using outbound.GitHubAppInstallation and outbound.StoredUserToken. It checks a GitHub App's JWT the way GitHub does, issues installation tokens and rotating user tokens, revokes them as the OAuth app endpoints do, and answers a bearer-protected endpoint for each kind of token, so a test can check that a token it was handed works.

Consumers' tests can use it too, as keystoretest and appstoretest are used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	*httptest.Server

	// AppID is the App's ID; JWTs must carry it as iss.
	AppID string

	// AppKey is the App's private key. AppKeyPEM gives it as GitHub
	// hands it out.
	AppKey *rsa.PrivateKey

	// InstallationID is the one installation the fake knows. Others are
	// 404, as on GitHub.
	InstallationID int64

	// ClientID and ClientSecret are the App's OAuth client, for refresh.
	ClientID     string
	ClientSecret string

	// InstallationTokenTTL and UserTokenTTL default to GitHub's one hour
	// and eight hours.
	InstallationTokenTTL time.Duration
	UserTokenTTL         time.Duration

	// Now overrides time.Now, for expiry checks and issued expiries.
	Now func() time.Time
	// contains filtered or unexported fields
}

Server is the fake. Its fields are fixed once New returns, except the TTLs and Now, which a test may set before issuing tokens.

func New

func New(t testing.TB) *Server

New starts a fake with a fresh 2048-bit App key, App ID "12345" and installation 1. It is closed when the test ends.

func (*Server) AppKeyPEM

func (s *Server) AppKeyPEM() []byte

AppKeyPEM returns the App key as PKCS#1 PEM ("RSA PRIVATE KEY"), the form GitHub's App settings page downloads.

func (*Server) ExpireUserToken

func (s *Server) ExpireUserToken(tok string)

ExpireUserToken makes access token tok expired at the fake, as if its eight hours had passed. Its refresh token still works.

func (*Server) InstallationCalls

func (s *Server) InstallationCalls() int

InstallationCalls is how many installation-token exchanges succeeded.

func (*Server) IssueUserToken

func (s *Server) IssueUserToken(subject string) *oauth2.Token

IssueUserToken mints a user token for subject, as a connect flow would receive, with a single-use refresh token.

func (*Server) LastJWTClaims

func (s *Server) LastJWTClaims() jwt.MapClaims

LastJWTClaims returns the claims of the last App JWT the fake accepted.

func (*Server) OAuthConfig

func (s *Server) OAuthConfig() *oauth2.Config

OAuthConfig returns a client config for the App's OAuth side, pointed at the fake's token endpoint.

func (*Server) RefreshCalls

func (s *Server) RefreshCalls() int

RefreshCalls is how many refresh requests arrived, accepted or not.

func (*Server) RevokeCalls added in v0.3.6

func (s *Server) RevokeCalls() int

RevokeCalls is how many revoke requests arrived, accepted or not.

func (*Server) ValidInstallationToken

func (s *Server) ValidInstallationToken(tok string) bool

ValidInstallationToken reports whether tok is a live installation token.

func (*Server) ValidUserToken

func (s *Server) ValidUserToken(tok string) (string, bool)

ValidUserToken returns the subject tok was issued to, if it is live.

Jump to

Keyboard shortcuts

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