Skip to content

Commit

Permalink
feat: add more tests for auto authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Nov 12, 2023
1 parent 0a6fdce commit ed4d39f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/authenticator/auto_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package authenticator_test

import (
"crypto/rsa"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -58,8 +59,8 @@ func (suite *AutoAuthenticatorTestSuite) SetupSuite() {
require.NoError(err)

testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
authHeader := req.Header.Get("Authentication")
tokenString := strings.TrimSuffix(authHeader, "Bearer")
authHeader := req.Header.Get("Authorization")
tokenString := strings.TrimPrefix(authHeader, "bearer ")

_, err := jwt.Parse(tokenString, func(
token *jwt.Token,
Expand All @@ -68,9 +69,14 @@ func (suite *AutoAuthenticatorTestSuite) SetupSuite() {
})
if err != nil {
res.WriteHeader(http.StatusUnauthorized)

return
}

userData, err := json.Marshal(map[string]any{})
require.NoError(err)
res.Header().Add("X-User-Data", string(userData))

res.WriteHeader(http.StatusOK)
}))
suite.Server = testServer
Expand Down

0 comments on commit ed4d39f

Please sign in to comment.