2828 secretGVK = metav1.GroupVersionKind {Group : "" , Version : "v1" , Kind : "Secret" }
2929)
3030
31- func Test_roleBindingIndexer (t * testing.T ) {
31+ func TestRoleBindingIndexer (t * testing.T ) {
3232 testNamespace := "test-ns"
3333 createBinding := func (roleRefKind string , ownerRefs ... metav1.OwnerReference ) rbacv1.RoleBinding {
3434 return rbacv1.RoleBinding {
@@ -486,6 +486,17 @@ func TestAdmitLocalUserPassword(t *testing.T) {
486486 },
487487 Username : "test" ,
488488 }
489+
490+ rawUsernameSecret , err := json .Marshal (& corev1.Secret {
491+ ObjectMeta : metav1.ObjectMeta {
492+ Name : "test-user" ,
493+ },
494+ Data : map [string ][]byte {
495+ "password" : []byte (fakeUser .Username ),
496+ },
497+ })
498+ assert .NoError (t , err )
499+
489500 tests := map [string ]struct {
490501 request * admission.Request
491502 hasher passwordHasher
@@ -616,14 +627,14 @@ func TestAdmitLocalUserPassword(t *testing.T) {
616627 Resource : secretGVR ,
617628 RequestKind : & secretGVK ,
618629 RequestResource : & secretGVR ,
619- UserInfo : authenicationv1.UserInfo {Username : "password " },
630+ UserInfo : authenicationv1.UserInfo {Username : "test-user " },
620631 Object : runtime.RawExtension {
621- Raw : rawSecret ,
632+ Raw : rawUsernameSecret ,
622633 },
623634 },
624635 },
625636 hasher : func (_ string ) ([]byte , []byte , error ) {
626- return [] byte ( "hashedPassword" ), [] byte ( "salt" ), nil
637+ panic ( "should not be called" )
627638 },
628639 mockSettingsCache : func () ctrlv3.SettingCache {
629640 mock := fake.NewMockNonNamespacedCacheInterface [* v3.Setting ](ctrl )
@@ -720,10 +731,10 @@ func TestAdmitLocalUserPassword(t *testing.T) {
720731 assert .NoError (t , err )
721732 assert .Equal (t , test .wantAllowed , response .Allowed )
722733 if test .wantPatch != "" {
723- var wantPatch []interface {}
734+ var wantPatch []any
724735 err = json .Unmarshal ([]byte (test .wantPatch ), & wantPatch )
725736 assert .NoError (t , err )
726- var patch []interface {}
737+ var patch []any
727738 err = json .Unmarshal (response .Patch , & patch )
728739 assert .NoError (t , err )
729740 sortPatch (patch )
@@ -737,10 +748,10 @@ func TestAdmitLocalUserPassword(t *testing.T) {
737748 }
738749}
739750
740- func sortPatch (patch []interface {} ) {
751+ func sortPatch (patch []any ) {
741752 sort .Slice (patch , func (i , j int ) bool {
742- pi := patch [i ].(map [string ]interface {} )
743- pj := patch [j ].(map [string ]interface {} )
753+ pi := patch [i ].(map [string ]any )
754+ pj := patch [j ].(map [string ]any )
744755 return fmt .Sprint (pi ["path" ]) < fmt .Sprint (pj ["path" ])
745756 })
746757}
0 commit comments