@@ -58,6 +58,21 @@ func TestValidatePolicy(t *testing.T) {
58
58
T : field .ErrorTypeInvalid ,
59
59
F : "roles[any1].metadata.name" ,
60
60
},
61
+ "invalid role" : {
62
+ A : authorizationapi.Policy {
63
+ ObjectMeta : kapi.ObjectMeta {Namespace : kapi .NamespaceDefault , Name : authorizationapi .PolicyName },
64
+ Roles : map [string ]* authorizationapi.Role {
65
+ "any1" : {
66
+ ObjectMeta : kapi.ObjectMeta {Namespace : kapi .NamespaceDefault , Name : "any1" },
67
+ Rules : []authorizationapi.PolicyRule {
68
+ {AttributeRestrictions : & authorizationapi.RoleBinding {}},
69
+ },
70
+ },
71
+ },
72
+ },
73
+ T : field .ErrorTypeInvalid ,
74
+ F : "roles[any1].rules[0].attributeRestrictions" ,
75
+ },
61
76
}
62
77
for k , v := range errorCases {
63
78
errs := ValidatePolicy (& v .A , true )
@@ -370,6 +385,16 @@ func TestValidateRole(t *testing.T) {
370
385
T : field .ErrorTypeRequired ,
371
386
F : "metadata.name" ,
372
387
},
388
+ "invalid rule" : {
389
+ A : authorizationapi.Role {
390
+ ObjectMeta : kapi.ObjectMeta {Name : authorizationapi .PolicyName , Namespace : kapi .NamespaceDefault },
391
+ Rules : []authorizationapi.PolicyRule {
392
+ {AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
393
+ },
394
+ },
395
+ T : field .ErrorTypeInvalid ,
396
+ F : "rules[0].attributeRestrictions" ,
397
+ },
373
398
}
374
399
for k , v := range errorCases {
375
400
errs := ValidateRole (& v .A , true )
0 commit comments