Skip to content

Commit

Permalink
fix auth test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoeg committed Nov 5, 2023
1 parent 75c6331 commit ae03a80
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions cmd/server/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,28 @@ func TestAuthenticate(t *testing.T) {
authorization: " ",
status: http.StatusUnauthorized,
},
{
name: "non-bearer authorization",
serverToken: "token",
authorization: "non-bearer-token",
status: http.StatusUnauthorized,
},
{
name: "empty bearer authorization",
serverToken: "token",
authorization: "Bearer ",
authorization: " ",
status: http.StatusUnauthorized,
},
{
name: "whitespace bearer authorization",
serverToken: "token",
authorization: "Bearer ",
authorization: " ",
status: http.StatusUnauthorized,
},
{
name: "wrong bearer authorization",
serverToken: "token",
authorization: "Bearer another-token",
authorization: "another-token",
status: http.StatusUnauthorized,
},
{
name: "correct bearer authorization",
serverToken: "token",
authorization: "Bearer token",
authorization: "token",
status: http.StatusOK,
},
}
Expand All @@ -64,7 +58,7 @@ func TestAuthenticate(t *testing.T) {
w.WriteHeader(http.StatusOK)
})
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header.Set("Authorization", tc.authorization)
req.Header.Set("X-HAM-TOKEN", tc.authorization)
w := httptest.NewRecorder()
authenticate(tc.serverToken)(handler).ServeHTTP(w, req)

Expand Down

0 comments on commit ae03a80

Please sign in to comment.