wsstream: use a single approach to detect connection upgrade
Signed-off-by: Monis Khan <mok@microsoft.com> Kubernetes-commit: 62b063b74b5eb1b7e72ebac7b5348593249f732b
This commit is contained in:
parent
41188ea6a1
commit
64eaf11221
|
@ -46,6 +46,25 @@ func TestAuthenticateRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAuthenticateRequestMultipleConnectionHeaders(t *testing.T) {
|
||||||
|
auth := NewProtocolAuthenticator(authenticator.TokenFunc(func(ctx context.Context, token string) (*authenticator.Response, bool, error) {
|
||||||
|
if token != "token" {
|
||||||
|
t.Errorf("unexpected token: %s", token)
|
||||||
|
}
|
||||||
|
return &authenticator.Response{User: &user.DefaultInfo{Name: "user"}}, true, nil
|
||||||
|
}))
|
||||||
|
resp, ok, err := auth.AuthenticateRequest(&http.Request{
|
||||||
|
Header: http.Header{
|
||||||
|
"Connection": []string{"not", "upgrade"},
|
||||||
|
"Upgrade": []string{"websocket"},
|
||||||
|
"Sec-Websocket-Protocol": []string{"base64url.bearer.authorization.k8s.io.dG9rZW4,dummy"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if !ok || resp == nil || err != nil {
|
||||||
|
t.Errorf("expected valid user")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAuthenticateRequestTokenInvalid(t *testing.T) {
|
func TestAuthenticateRequestTokenInvalid(t *testing.T) {
|
||||||
auth := NewProtocolAuthenticator(authenticator.TokenFunc(func(ctx context.Context, token string) (*authenticator.Response, bool, error) {
|
auth := NewProtocolAuthenticator(authenticator.TokenFunc(func(ctx context.Context, token string) (*authenticator.Response, bool, error) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
|
|
Loading…
Reference in New Issue