@@ -187,6 +187,50 @@ func TestGenerateRbacResourcesWithNameSpaces(t *testing.T) {
187187
188188}
189189
190+ func TestGenerateRbacResourcesWithEmailWithSpecialCharacters (t * testing.T ) {
191+ logger := createLogger ()
192+ assert := assert .New (t )
193+ groups := []string {"admins" , "developers" }
194+ federatedClaims := tokenhandler.FederatedClaims {
195+ ConnectorID : "ldap" ,
196+ UserID : "cn=jane,ou=People,dc=example,dc=org" ,
197+ }
198+ user := & tokenhandler.User {
199+ 200+ Groups : groups ,
201+ FederatedClaims : federatedClaims ,
202+ }
203+ testRbacResources , err := generateRbacResources (user , createFakeConfig ("developers" ), []string {"default" }, logger )
204+ assert .NoError (err )
205+ roleSuccess := assert .Equal (len (testRbacResources .clusterRoles ), 1 )
206+ assert .Equal (len (testRbacResources .clusterRoleBindings ), 2 )
207+ assert .Equal (testRbacResources .serviceAccount .Name , "jane-doe-foo-example-com" )
208+ if roleSuccess {
209+ assert .Equal (testRbacResources .clusterRoles [0 ].name , "developers-from-jwt" )
210+ }
211+ var bindNames , roleNames []string
212+ for _ , crBind := range testRbacResources .clusterRoleBindings {
213+ bindNames = append (bindNames , crBind .name )
214+ roleNames = append (roleNames , crBind .roleName )
215+ }
216+ assert .ElementsMatch (bindNames , []string {"jane-doe-foo-example-com-admin-binding" , "jane-doe-foo-example-com-developers-from-jwt-binding" })
217+ assert .ElementsMatch (roleNames , []string {"admin" , "developers-from-jwt" })
218+
219+ testRbacResources , err = generateRbacResources (user , createFakeConfig ("fakegroup" ), []string {"default" }, logger )
220+ assert .NoError (err )
221+ assert .Equal (len (testRbacResources .clusterRoles ), 0 )
222+ assert .Equal (len (testRbacResources .clusterRoleBindings ), 1 )
223+ assert .Equal (testRbacResources .serviceAccount .Name , "jane-doe-foo-example-com" )
224+ bindNames = nil
225+ roleNames = nil
226+ for _ , crBind := range testRbacResources .clusterRoleBindings {
227+ bindNames = append (bindNames , crBind .name )
228+ roleNames = append (roleNames , crBind .roleName )
229+ }
230+ assert .ElementsMatch (bindNames , []string {"jane-doe-foo-example-com-admin-binding" })
231+ assert .ElementsMatch (roleNames , []string {"admin" })
232+ }
233+
190234func TestGenerateClusterRole (t * testing.T ) {
191235 assert := assert .New (t )
192236 cRole , err := generateClusterRole ("developers" , createFakeConfig ("developers" ))
0 commit comments