Documentation ¶
Overview ¶
Package oauth2test implements reusable integration tests to run against any OAuth2 authentication server.
Index ¶
- func AccessTokenTest(t *testing.T, spec *Spec, accessToken string)
- func AuthorizationCodeGrantTest(t *testing.T, spec *Spec)
- func AuthorizationEndpointTest(t *testing.T, spec *Spec)
- func ClientCredentialsGrantTest(t *testing.T, spec *Spec)
- func Do(handler http.Handler, req *Request)
- func ImplicitGrantTest(t *testing.T, spec *Spec)
- func IntrospectionEndpointTest(t *testing.T, spec *Spec)
- func PasswordGrantTest(t *testing.T, spec *Spec)
- func ProtectedResourceTest(t *testing.T, spec *Spec)
- func RefreshTokenGrantTest(t *testing.T, spec *Spec)
- func RefreshTokenTest(t *testing.T, spec *Spec, refreshToken string)
- func RevocationEndpointTest(t *testing.T, spec *Spec)
- func Run(t *testing.T, spec *Spec)
- func TokenEndpointTest(t *testing.T, spec *Spec)
- type Request
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessTokenTest ¶
AccessTokenTest validates the specified access token by requesting the protected resource.
func AuthorizationCodeGrantTest ¶
AuthorizationCodeGrantTest tests the authorization code grant.
func AuthorizationEndpointTest ¶
AuthorizationEndpointTest executes general authorization endpoint tests.
func ClientCredentialsGrantTest ¶
ClientCredentialsGrantTest tests the client credentials grant.
func ImplicitGrantTest ¶
ImplicitGrantTest tests the implicit grant.
func IntrospectionEndpointTest ¶
IntrospectionEndpointTest executes general token introspection tests.
func PasswordGrantTest ¶
PasswordGrantTest tests the password grant.
func ProtectedResourceTest ¶
ProtectedResourceTest validates authorization of the protected resource.
func RefreshTokenGrantTest ¶
RefreshTokenGrantTest tests the refresh token grant.
func RefreshTokenTest ¶
RefreshTokenTest validates the specified refreshToken by requesting a new access token and validating it as well.
func RevocationEndpointTest ¶
RevocationEndpointTest executes general token revocation tests.
func TokenEndpointTest ¶
TokenEndpointTest executes general token endpoint tests.
Types ¶
type Request ¶
type Request struct { Method string Path string Header map[string]string Form map[string]string Username string Password string Callback func(*httptest.ResponseRecorder, *http.Request) }
A Request is a convenience wrapper to specify test requests.
type Spec ¶
type Spec struct { // The server handler. Handler http.Handler // The token endpoint (e.g. /oauth2/token). TokenEndpoint string // The authorization endpoint (e.g. /oauth2/authorize). AuthorizeEndpoint string // The revocation endpoint (e.g. /oauth2/revoke). RevocationEndpoint string // The introspection endpoint (e.g. /oauth2/introspect). IntrospectionEndpoint string // The protected resource (e.g. /api/protected). ProtectedResource string // The supported grants. PasswordGrantSupport bool ClientCredentialsGrantSupport bool ImplicitGrantSupport bool AuthorizationCodeGrantSupport bool RefreshTokenGrantSupport bool // The details of a confidential client. ConfidentialClientID string ConfidentialClientSecret string // The details of a public client. PublicClientID string // The scopes that are considered invalid, valid and exceeding by the // authentication server. InvalidScope string ValidScope string ExceedingScope string // The expected "expire_in" value of returned tokens. ExpectedExpiresIn int // The tokens for the protected resource tests. InvalidToken string UnknownToken string ValidToken string ExpiredToken string InsufficientToken string // The details of the primary resource owner for the password grant test. // // Note: Only needed if the password grant is supported. ResourceOwnerUsername string ResourceOwnerPassword string // The redirect URI that is considered invalid and valid by the // authentication server. // // Note: Only needed if the implicit grant or authorization code grant is // supported. InvalidRedirectURI string PrimaryRedirectURI string SecondaryRedirectURI string // The invalid, unknown, valid and expired refresh tokens that is used // during the refresh token grant tests. // // Note: Only needed if the refresh token grant is supported. InvalidRefreshToken string UnknownRefreshToken string ValidRefreshToken string ExpiredRefreshToken string // The invalid, unknown and expired authorization code that is used during // the authorization code grant tests. // // Note: Only needed if the authorization code grant is supported. InvalidAuthorizationCode string UnknownAuthorizationCode string ExpiredAuthorizationCode string // The params and headers needed to authorize the resource owner during the // implicit grant or authorization code grant test. // // Note: Only needed if the implicit grant or authorization code grant // is supported. InvalidAuthorizationParams map[string]string InvalidAuthorizationHeaders map[string]string ValidAuthorizationParams map[string]string ValidAuthorizationHeaders map[string]string // If enabled the implementation is checked for properly revoking tokens // if a code replay attack is carried out. CodeReplayMitigation bool }
Spec declares the needed info for testing an OAuth2 authentication server.