oauth2providertest
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package oauth2providertest provides comprehensive testing utilities for OAuth2 identity provider functionality.It includes helpers for creating OAuth2 apps, performing authorization flows, token exchanges,PKCE challenge generation and verification, and testing error scenarios.
Index¶
- Constants
- Variables
- func AuthorizeOAuth2App(t *testing.T, client *codersdk.Client, baseURL string, params AuthorizeParams) string
- func CleanupOAuth2App(t *testing.T, client *codersdk.Client, appID uuid.UUID)
- func CreateTestOAuth2App(t *testing.T, client *codersdk.Client) (*codersdk.OAuth2ProviderApp, string)
- func ExchangeCodeForToken(t *testing.T, baseURL string, params TokenExchangeParams) *oauth2.Token
- func FetchOAuth2Metadata(t *testing.T, baseURL string) map[string]any
- func GenerateCodeChallenge(verifier string) string
- func GeneratePKCE(t *testing.T) (verifier, challenge string)
- func GenerateState(t *testing.T) string
- func PerformTokenExchangeExpectingError(t *testing.T, baseURL string, params TokenExchangeParams, expectedError string)
- func RequireOAuth2Error(t *testing.T, resp *http.Response, expectedError string)
- type AuthorizeParams
- type OAuth2Error
- type TokenExchangeParams
Constants¶
const (// TestRedirectURI is the standard test redirect URITestRedirectURI = "http://localhost:9876/callback"// TestResourceURI is used for testing resource parameterTestResourceURI = "https://api.example.com"// Invalid PKCE verifier for negative testingInvalidCodeVerifier = "wrong-verifier")
Test constants for OAuth2 testing
Variables¶
var OAuth2ErrorTypes = struct {InvalidRequeststringInvalidClientstringInvalidGrantstringUnauthorizedClientstringUnsupportedGrantTypestringInvalidScopestring}{InvalidRequest: "invalid_request",InvalidClient: "invalid_client",InvalidGrant: "invalid_grant",UnauthorizedClient: "unauthorized_client",UnsupportedGrantType: "unsupported_grant_type",InvalidScope: "invalid_scope",}
OAuth2ErrorTypes contains standard OAuth2 error codes
Functions¶
funcAuthorizeOAuth2App¶
func AuthorizeOAuth2App(t *testing.T, client *codersdk.Client, baseURLstring, paramsAuthorizeParams)string
AuthorizeOAuth2App performs the OAuth2 authorization flow and returns the authorization code
funcCleanupOAuth2App¶
CleanupOAuth2App deletes an OAuth2 app (helper for test cleanup)
funcCreateTestOAuth2App¶
func CreateTestOAuth2App(t *testing.T, client *codersdk.Client) (*codersdk.OAuth2ProviderApp,string)
CreateTestOAuth2App creates an OAuth2 app for testing and returns the app and client secret
funcExchangeCodeForToken¶
ExchangeCodeForToken exchanges an authorization code for tokens
funcFetchOAuth2Metadata¶
FetchOAuth2Metadata fetches and returns OAuth2 authorization server metadata
funcGenerateCodeChallenge¶
GenerateCodeChallenge creates an S256 code challenge from a verifier
funcGeneratePKCE¶
GeneratePKCE generates a random PKCE code verifier and challenge
funcGenerateState¶
GenerateState generates a random state parameter
funcPerformTokenExchangeExpectingError¶
func PerformTokenExchangeExpectingError(t *testing.T, baseURLstring, paramsTokenExchangeParams, expectedErrorstring)
PerformTokenExchangeExpectingError performs a token exchange expecting an OAuth2 error
Types¶
typeAuthorizeParams¶
type AuthorizeParams struct {ClientIDstringResponseTypestringRedirectURIstringStatestringCodeChallengestringCodeChallengeMethodstringResourcestringScopestring}
AuthorizeParams contains parameters for OAuth2 authorization
typeOAuth2Error¶
type OAuth2Error struct {Errorstring `json:"error"`ErrorDescriptionstring `json:"error_description,omitempty"`}
OAuth2Error represents an OAuth2 error response