6
6
"errors"
7
7
"net/http"
8
8
"reflect"
9
+ "sort"
9
10
"strconv"
10
11
"strings"
11
12
"testing"
@@ -14,6 +15,7 @@ import (
14
15
"k8s.io/apiserver/pkg/authentication/authenticator"
15
16
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
16
17
"k8s.io/apiserver/pkg/authentication/user"
18
+ authuser "k8s.io/apiserver/pkg/authentication/user"
17
19
18
20
"github.com/jetstack/kube-oidc-proxy/pkg/mocks"
19
21
)
@@ -71,9 +73,12 @@ func (f *fakeRT) RoundTrip(h *http.Request) (*http.Response, error) {
71
73
f .expUser , h .Header .Get ("Impersonate-User" ))
72
74
}
73
75
74
- if ! reflect .DeepEqual (h .Header ["Impersonate-Group" ], f .expGroup ) {
75
- f .t .Errorf ("client transport got unexpected group impersonation header, exp=%s got=%s" ,
76
- f .expGroup , h .Header .Get ("Impersonate-Group" ))
76
+ if exp , act := sort .StringSlice (f .expGroup ), sort .StringSlice (h .Header ["Impersonate-Group" ]); ! reflect .DeepEqual (exp , act ) {
77
+ f .t .Errorf (
78
+ "client transport got unexpected group impersonation header, exp=%#v got=%#v" ,
79
+ exp ,
80
+ act ,
81
+ )
77
82
}
78
83
79
84
for k , vv := range h .Header {
@@ -362,6 +367,7 @@ func Test_RoundTrip(t *testing.T) {
362
367
}
363
368
p .fakeToken .EXPECT ().AuthenticateToken (gomock .Any (), "fake-token" ).Return (authResponse , true , nil )
364
369
p .fakeRT .expUser = "a-user"
370
+ p .fakeRT .expGroup = []string {authuser .AllAuthenticated }
365
371
req .Header ["Authorization" ] = []string {"bearer fake-token" }
366
372
_ , err = p .RoundTrip (req )
367
373
if err != nil {
@@ -371,7 +377,7 @@ func Test_RoundTrip(t *testing.T) {
371
377
authResponse = & authenticator.Response {
372
378
User : & user.DefaultInfo {
373
379
Name : "a-user" ,
374
- Groups : []string {"a-group-a" , "a-group-b" },
380
+ Groups : []string {"a-group-a" , "a-group-b" , authuser . AllAuthenticated },
375
381
Extra : map [string ][]string {
376
382
"foo" : []string {"a" , "b" },
377
383
"bar" : []string {"c" , "d" },
@@ -381,7 +387,7 @@ func Test_RoundTrip(t *testing.T) {
381
387
}
382
388
p .fakeToken .EXPECT ().AuthenticateToken (gomock .Any (), "fake-token" ).Return (authResponse , true , nil )
383
389
p .fakeRT .expUser = "a-user"
384
- p .fakeRT .expGroup = []string {"a-group-a" , "a-group-b" }
390
+ p .fakeRT .expGroup = []string {"a-group-a" , "a-group-b" , authuser . AllAuthenticated }
385
391
p .fakeRT .expExtra = map [string ][]string {
386
392
"Impersonate-Extra-Foo" : []string {"a" , "b" },
387
393
"Impersonate-Extra-Bar" : []string {"c" , "d" },
0 commit comments