Skip to content

Commit 367214d

Browse files
author
azush26
committed
Add an unit test for requests including value after token
1 parent bf516ab commit 367214d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

staging/src/k8s.io/apiserver/pkg/authentication/request/bearertoken/bearertoken_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ func TestAuthenticateRequest(t *testing.T) {
4242
}
4343
}
4444

45+
func TestAuthenticateRequestIncludingValueAfterToken(t *testing.T) {
46+
testCases := []struct {
47+
Req *http.Request
48+
}{
49+
{Req: &http.Request{Header: http.Header{"Authorization": []string{"Bearer token a"}}}},
50+
{Req: &http.Request{Header: http.Header{"Authorization": []string{"Bearer token a b c"}}}},
51+
{Req: &http.Request{Header: http.Header{"Authorization": []string{"Bearer token a"}}}},
52+
}
53+
for i, testCase := range testCases {
54+
auth := New(authenticator.TokenFunc(func(ctx context.Context, token string) (*authenticator.Response, bool, error) {
55+
if token != "token" {
56+
t.Errorf("unexpected token: %s", token)
57+
}
58+
return &authenticator.Response{User: &user.DefaultInfo{Name: "user"}}, true, nil
59+
}))
60+
resp, ok, err := auth.AuthenticateRequest(testCase.Req)
61+
if !ok || resp == nil || err != nil {
62+
t.Errorf("%d: expected valid user", i)
63+
}
64+
}
65+
}
66+
4567
func TestAuthenticateRequestTokenInvalid(t *testing.T) {
4668
auth := New(authenticator.TokenFunc(func(ctx context.Context, token string) (*authenticator.Response, bool, error) {
4769
return nil, false, nil

0 commit comments

Comments
 (0)