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, 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 ¶
- type Server
- func (s *Server) AppKeyPEM() []byte
- func (s *Server) ExpireUserToken(tok string)
- func (s *Server) InstallationCalls() int
- func (s *Server) IssueUserToken(subject string) *oauth2.Token
- func (s *Server) LastJWTClaims() jwt.MapClaims
- func (s *Server) OAuthConfig() *oauth2.Config
- func (s *Server) RefreshCalls() int
- func (s *Server) ValidInstallationToken(tok string) bool
- func (s *Server) ValidUserToken(tok string) (string, bool)
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 ¶
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 ¶
AppKeyPEM returns the App key as PKCS#1 PEM ("RSA PRIVATE KEY"), the form GitHub's App settings page downloads.
func (*Server) ExpireUserToken ¶
ExpireUserToken makes access token tok expired at the fake, as if its eight hours had passed. Its refresh token still works.
func (*Server) InstallationCalls ¶
InstallationCalls is how many installation-token exchanges succeeded.
func (*Server) IssueUserToken ¶
IssueUserToken mints a user token for subject, as a connect flow would receive, with a single-use refresh token.
func (*Server) LastJWTClaims ¶
LastJWTClaims returns the claims of the last App JWT the fake accepted.
func (*Server) OAuthConfig ¶
OAuthConfig returns a client config for the App's OAuth side, pointed at the fake's token endpoint.
func (*Server) RefreshCalls ¶
RefreshCalls is how many refresh requests arrived, accepted or not.
func (*Server) ValidInstallationToken ¶
ValidInstallationToken reports whether tok is a live installation token.