Skip to content

Commit

Permalink
test: add check of error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestelfer committed Apr 25, 2024
1 parent a268770 commit de8d3fa
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion internal/jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestMiddleware(t *testing.T) {
customClaims BuildkiteClaims
wantStatusCode int
wantBodyText string
options []jwtmiddleware.Option
}{
{
name: "has subject",
Expand Down Expand Up @@ -91,6 +92,18 @@ func TestMiddleware(t *testing.T) {
wantStatusCode: http.StatusUnauthorized,
wantBodyText: "JWT is invalid",
},
{
name: "error handler",
claims: valid(jwt.Claims{
Audience: []string{"audience"},
Subject: "subject",
Issuer: "issuer",
}),
customClaims: custom("that dog ain't gonna hunt", "test-pipeline"),
wantStatusCode: http.StatusUnauthorized,
wantBodyText: "JWT is invalid",
options: []jwtmiddleware.Option{jwtmiddleware.WithErrorHandler(LogErrorHandler())},
},
}

jwk := generateJWK(t)
Expand Down Expand Up @@ -122,7 +135,15 @@ func TestMiddleware(t *testing.T) {

responseRecorder := httptest.NewRecorder()

mw, err := Middleware(cfg, jwtmiddleware.WithErrorHandler(errorHandler(t)))
options := []jwtmiddleware.Option{
jwtmiddleware.WithErrorHandler(errorHandler(t)),
}

if len(test.options) > 0 {
options = append(options, test.options...)
}

mw, err := Middleware(cfg, options...)
require.NoError(t, err)

handler := mw(successHandler)
Expand Down

0 comments on commit de8d3fa

Please sign in to comment.