@@ -634,6 +634,89 @@ func TestHandleMemberCluster(t *testing.T) {
634634 },
635635 wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "aks-support" , utils .GenerateGroupString ([]string {"system:authenticated" }), admissionv1 .Delete , & utils .MCMetaGVK , "" , types.NamespacedName {Name : "test-mc" })),
636636 },
637+
638+ "allow label modification by RP client" : {
639+ req : admission.Request {
640+ AdmissionRequest : admissionv1.AdmissionRequest {
641+ Name : "test-mc" ,
642+ Object : runtime.RawExtension {
643+ Raw : func () []byte {
644+ updatedMC := & clusterv1beta1.MemberCluster {
645+ ObjectMeta : metav1.ObjectMeta {
646+ Name : "test-mc" ,
647+ Labels : map [string ]string {"key1" : "value1" },
648+ Annotations : map [string ]string {
649+ "fleet.azure.com/cluster-resource-id" : "test-cluster-resource-id" ,
650+ },
651+ },
652+ }
653+ raw , _ := json .Marshal (updatedMC )
654+ return raw
655+ }(),
656+ },
657+ OldObject : runtime.RawExtension {
658+ Raw : fleetMCObjectBytes ,
659+ },
660+ UserInfo : authenticationv1.UserInfo {
661+ Username : "aksService" ,
662+ Groups : []string {"system:masters" },
663+ },
664+ RequestKind : & utils .MCMetaGVK ,
665+ Operation : admissionv1 .Update ,
666+ },
667+ },
668+ resourceValidator : fleetResourceValidator {
669+ decoder : decoder ,
670+ },
671+ wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "aksService" , utils .GenerateGroupString ([]string {"system:masters" }), admissionv1 .Update , & utils .MCMetaGVK , "" , types.NamespacedName {Name : "test-mc" })),
672+ },
673+ "deny label modification by non-RP client" : {
674+ req : admission.Request {
675+ AdmissionRequest : admissionv1.AdmissionRequest {
676+ Name : "test-mc" ,
677+ Object : runtime.RawExtension {
678+ Raw : func () []byte {
679+ updatedMC := & clusterv1beta1.MemberCluster {
680+ ObjectMeta : metav1.ObjectMeta {
681+ Name : "test-mc" ,
682+ Labels : map [string ]string {"key1" : "value1" },
683+ Annotations : map [string ]string {
684+ "fleet.azure.com/cluster-resource-id" : "test-cluster-resource-id" ,
685+ },
686+ },
687+ }
688+ raw , _ := json .Marshal (updatedMC )
689+ return raw
690+ }(),
691+ },
692+ OldObject : runtime.RawExtension {
693+ Raw : func () []byte {
694+ oldMC := & clusterv1beta1.MemberCluster {
695+ ObjectMeta : metav1.ObjectMeta {
696+ Name : "test-mc" ,
697+ Labels : map [string ]string {"key1" : "value2" },
698+ Annotations : map [string ]string {
699+ "fleet.azure.com/cluster-resource-id" : "test-cluster-resource-id" ,
700+ },
701+ },
702+ }
703+ raw , _ := json .Marshal (oldMC )
704+ return raw
705+ }(),
706+ },
707+ UserInfo : authenticationv1.UserInfo {
708+ Username : "nonRPUser" ,
709+ Groups : []string {"system:authenticated" },
710+ },
711+ RequestKind : & utils .MCMetaGVK ,
712+ Operation : admissionv1 .Update ,
713+ },
714+ },
715+ resourceValidator : fleetResourceValidator {
716+ decoder : decoder ,
717+ },
718+ wantResponse : admission .Denied (fmt .Sprintf (validation .DeniedModifyFleetLabels )),
719+ },
637720 }
638721
639722 for testName , testCase := range testCases {
0 commit comments