@@ -40,3 +40,72 @@ func TestGroupAdder(t *testing.T) {
40
40
t .Errorf ("Expected original,added groups, got %#v" , user .GetGroups ())
41
41
}
42
42
}
43
+
44
+ func TestAuthenticatedGroupAdder (t * testing.T ) {
45
+ tests := []struct {
46
+ name string
47
+ inputUser user.Info
48
+ expectedUser user.Info
49
+ }{
50
+ {
51
+ name : "add" ,
52
+ inputUser : & user.DefaultInfo {
53
+ Name : "user" ,
54
+ Groups : []string {"some-group" },
55
+ },
56
+ expectedUser : & user.DefaultInfo {
57
+ Name : "user" ,
58
+ Groups : []string {"some-group" , user .AllAuthenticated },
59
+ },
60
+ },
61
+ {
62
+ name : "don't double add" ,
63
+ inputUser : & user.DefaultInfo {
64
+ Name : "user" ,
65
+ Groups : []string {user .AllAuthenticated , "some-group" },
66
+ },
67
+ expectedUser : & user.DefaultInfo {
68
+ Name : "user" ,
69
+ Groups : []string {user .AllAuthenticated , "some-group" },
70
+ },
71
+ },
72
+ {
73
+ name : "don't add for anon" ,
74
+ inputUser : & user.DefaultInfo {
75
+ Name : user .Anonymous ,
76
+ Groups : []string {"some-group" },
77
+ },
78
+ expectedUser : & user.DefaultInfo {
79
+ Name : user .Anonymous ,
80
+ Groups : []string {"some-group" },
81
+ },
82
+ },
83
+ {
84
+ name : "don't add for unauthenticated group" ,
85
+ inputUser : & user.DefaultInfo {
86
+ Name : "user" ,
87
+ Groups : []string {user .AllUnauthenticated , "some-group" },
88
+ },
89
+ expectedUser : & user.DefaultInfo {
90
+ Name : "user" ,
91
+ Groups : []string {user .AllUnauthenticated , "some-group" },
92
+ },
93
+ },
94
+ }
95
+
96
+ for _ , test := range tests {
97
+ adder := authenticator .Request (
98
+ NewAuthenticatedGroupAdder (
99
+ authenticator .RequestFunc (func (req * http.Request ) (user.Info , bool , error ) {
100
+ return test .inputUser , true , nil
101
+ }),
102
+ ),
103
+ )
104
+
105
+ user , _ , _ := adder .AuthenticateRequest (nil )
106
+ if ! reflect .DeepEqual (user , test .expectedUser ) {
107
+ t .Errorf ("got %#v" , user )
108
+ }
109
+ }
110
+
111
+ }
0 commit comments