Skip to content

Commit d201ec5

Browse files
committed
Add tests cases for invalid Bearer prefixes
1 parent ce67e4d commit d201ec5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

jwtauth_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func TestSimple(t *testing.T) {
8484
{Name: "valid BEARER", Authorization: "BEARER " + newJwtToken(TokenSecret), Status: 200, Resp: "welcome"},
8585
{Name: "valid bearer", Authorization: "bearer " + newJwtToken(TokenSecret), Status: 200, Resp: "welcome"},
8686
{Name: "valid claim", Authorization: "Bearer " + newJwtToken(TokenSecret, map[string]interface{}{"service": "test"}), Status: 200, Resp: "welcome"},
87+
{Name: "invalid bearer_", Authorization: "BEARER_" + newJwtToken(TokenSecret), Status: 401, Resp: "token is unauthorized\n"},
88+
{Name: "invalid bearerx", Authorization: "BEARERx" + newJwtToken(TokenSecret), Status: 401, Resp: "token is unauthorized\n"},
89+
{Name: "invalid bearer ", Authorization: "BEARER " + newJwtToken(TokenSecret), Status: 401, Resp: "token is unauthorized\n"},
8790
}
8891

8992
for _, tc := range tt {
@@ -93,7 +96,7 @@ func TestSimple(t *testing.T) {
9396
}
9497
status, resp := testRequest(t, ts, "GET", "/", h, nil)
9598
if status != tc.Status || resp != tc.Resp {
96-
t.Fatalf("test '%s' failed: expected status %d, got %d", tc.Name, tc.Status, status)
99+
t.Errorf("test '%s' failed: expected status %d, got %d", tc.Name, tc.Status, status)
97100
}
98101
}
99102
}

0 commit comments

Comments
 (0)