@@ -19,7 +19,7 @@ func TestToAttributeSet(t *testing.T) {
19
19
tests := []struct {
20
20
description string
21
21
rule rbacv1.PolicyRule
22
- expectedAttributes map [authorizer.AttributesRecord ] struct {}
22
+ expectedAttributes map [string ] authorizer.AttributesRecord
23
23
}{
24
24
{
25
25
description : "SimpleRule" ,
@@ -28,8 +28,8 @@ func TestToAttributeSet(t *testing.T) {
28
28
APIGroups : []string {"*" },
29
29
Resources : []string {"*" },
30
30
},
31
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
32
- attributesRecord (user , namespace , "*" , "*" , "*" , "" , "" ): {} ,
31
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
32
+ attributesKey (user , namespace , "*" , "*" , "*" , "" , "" ): attributesRecord ( user , namespace , "*" , "*" , "*" , "" , "" ) ,
33
33
},
34
34
},
35
35
{
@@ -38,8 +38,8 @@ func TestToAttributeSet(t *testing.T) {
38
38
Verbs : []string {"*" },
39
39
NonResourceURLs : []string {"/api" },
40
40
},
41
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
42
- attributesRecord (user , namespace , "*" , "" , "" , "" , "/api" ): {} ,
41
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
42
+ attributesKey (user , namespace , "*" , "" , "" , "" , "/api" ): attributesRecord ( user , namespace , "*" , "" , "" , "" , "/api" ) ,
43
43
},
44
44
},
45
45
{
@@ -49,9 +49,9 @@ func TestToAttributeSet(t *testing.T) {
49
49
APIGroups : []string {"*" },
50
50
Resources : []string {"*" },
51
51
},
52
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
53
- attributesRecord (user , namespace , "create" , "*" , "*" , "" , "" ): {} ,
54
- attributesRecord (user , namespace , "delete" , "*" , "*" , "" , "" ): {} ,
52
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
53
+ attributesKey (user , namespace , "create" , "*" , "*" , "" , "" ): attributesRecord ( user , namespace , "create" , "*" , "*" , "" , "" ) ,
54
+ attributesKey (user , namespace , "delete" , "*" , "*" , "" , "" ): attributesRecord ( user , namespace , "delete" , "*" , "*" , "" , "" ) ,
55
55
},
56
56
},
57
57
{
@@ -60,11 +60,11 @@ func TestToAttributeSet(t *testing.T) {
60
60
Verbs : []string {"get" , "update" },
61
61
Resources : []string {"donuts" , "coffee" },
62
62
},
63
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
64
- attributesRecord (user , namespace , "get" , "" , "donuts" , "" , "" ): {} ,
65
- attributesRecord (user , namespace , "update" , "" , "donuts" , "" , "" ): {} ,
66
- attributesRecord (user , namespace , "get" , "" , "coffee" , "" , "" ): {} ,
67
- attributesRecord (user , namespace , "update" , "" , "coffee" , "" , "" ): {} ,
63
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
64
+ attributesKey (user , namespace , "get" , "" , "donuts" , "" , "" ): attributesRecord ( user , namespace , "get" , "" , "donuts" , "" , "" ) ,
65
+ attributesKey (user , namespace , "update" , "" , "donuts" , "" , "" ): attributesRecord ( user , namespace , "update" , "" , "donuts" , "" , "" ) ,
66
+ attributesKey (user , namespace , "get" , "" , "coffee" , "" , "" ): attributesRecord ( user , namespace , "get" , "" , "coffee" , "" , "" ) ,
67
+ attributesKey (user , namespace , "update" , "" , "coffee" , "" , "" ): attributesRecord ( user , namespace , "update" , "" , "coffee" , "" , "" ) ,
68
68
},
69
69
},
70
70
{
@@ -73,9 +73,9 @@ func TestToAttributeSet(t *testing.T) {
73
73
Verbs : []string {"*" },
74
74
NonResourceURLs : []string {"/capybaras" , "/caviidaes" },
75
75
},
76
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
77
- attributesRecord (user , namespace , "*" , "" , "" , "" , "/capybaras" ): {} ,
78
- attributesRecord (user , namespace , "*" , "" , "" , "" , "/caviidaes" ): {} ,
76
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
77
+ attributesKey (user , namespace , "*" , "" , "" , "" , "/capybaras" ): attributesRecord ( user , namespace , "*" , "" , "" , "" , "/capybaras" ) ,
78
+ attributesKey (user , namespace , "*" , "" , "" , "" , "/caviidaes" ): attributesRecord ( user , namespace , "*" , "" , "" , "" , "/caviidaes" ) ,
79
79
},
80
80
},
81
81
{
@@ -85,11 +85,11 @@ func TestToAttributeSet(t *testing.T) {
85
85
Resources : []string {"donuts" , "coffee" },
86
86
ResourceNames : []string {"nyc" },
87
87
},
88
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
89
- attributesRecord (user , namespace , "get" , "" , "donuts" , "nyc" , "" ): {} ,
90
- attributesRecord (user , namespace , "update" , "" , "donuts" , "nyc" , "" ): {} ,
91
- attributesRecord (user , namespace , "get" , "" , "coffee" , "nyc" , "" ): {} ,
92
- attributesRecord (user , namespace , "update" , "" , "coffee" , "nyc" , "" ): {} ,
88
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
89
+ attributesKey (user , namespace , "get" , "" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "" , "donuts" , "nyc" , "" ) ,
90
+ attributesKey (user , namespace , "update" , "" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "" , "donuts" , "nyc" , "" ) ,
91
+ attributesKey (user , namespace , "get" , "" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "" , "coffee" , "nyc" , "" ) ,
92
+ attributesKey (user , namespace , "update" , "" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "" , "coffee" , "nyc" , "" ) ,
93
93
},
94
94
},
95
95
{
@@ -100,21 +100,21 @@ func TestToAttributeSet(t *testing.T) {
100
100
APIGroups : []string {"apps.coreos.com" , "apps.redhat.com" },
101
101
ResourceNames : []string {"nyc" },
102
102
},
103
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {
104
- attributesRecord (user , namespace , "get" , "apps.coreos.com" , "donuts" , "nyc" , "" ): {} ,
105
- attributesRecord (user , namespace , "update" , "apps.coreos.com" , "donuts" , "nyc" , "" ): {} ,
106
- attributesRecord (user , namespace , "get" , "apps.coreos.com" , "coffee" , "nyc" , "" ): {} ,
107
- attributesRecord (user , namespace , "update" , "apps.coreos.com" , "coffee" , "nyc" , "" ): {} ,
108
- attributesRecord (user , namespace , "get" , "apps.redhat.com" , "donuts" , "nyc" , "" ): {} ,
109
- attributesRecord (user , namespace , "update" , "apps.redhat.com" , "donuts" , "nyc" , "" ): {} ,
110
- attributesRecord (user , namespace , "get" , "apps.redhat.com" , "coffee" , "nyc" , "" ): {} ,
111
- attributesRecord (user , namespace , "update" , "apps.redhat.com" , "coffee" , "nyc" , "" ): {} ,
103
+ expectedAttributes : map [string ] authorizer.AttributesRecord {
104
+ attributesKey (user , namespace , "get" , "apps.coreos.com" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "apps.coreos.com" , "donuts" , "nyc" , "" ) ,
105
+ attributesKey (user , namespace , "update" , "apps.coreos.com" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "apps.coreos.com" , "donuts" , "nyc" , "" ) ,
106
+ attributesKey (user , namespace , "get" , "apps.coreos.com" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "apps.coreos.com" , "coffee" , "nyc" , "" ) ,
107
+ attributesKey (user , namespace , "update" , "apps.coreos.com" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "apps.coreos.com" , "coffee" , "nyc" , "" ) ,
108
+ attributesKey (user , namespace , "get" , "apps.redhat.com" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "apps.redhat.com" , "donuts" , "nyc" , "" ) ,
109
+ attributesKey (user , namespace , "update" , "apps.redhat.com" , "donuts" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "apps.redhat.com" , "donuts" , "nyc" , "" ) ,
110
+ attributesKey (user , namespace , "get" , "apps.redhat.com" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "get" , "apps.redhat.com" , "coffee" , "nyc" , "" ) ,
111
+ attributesKey (user , namespace , "update" , "apps.redhat.com" , "coffee" , "nyc" , "" ): attributesRecord ( user , namespace , "update" , "apps.redhat.com" , "coffee" , "nyc" , "" ) ,
112
112
},
113
113
},
114
114
{
115
115
description : "NoVerbs" ,
116
116
rule : rbacv1.PolicyRule {},
117
- expectedAttributes : map [authorizer.AttributesRecord ] struct {} {},
117
+ expectedAttributes : map [string ] authorizer.AttributesRecord {},
118
118
},
119
119
}
120
120
@@ -130,11 +130,12 @@ func TestToAttributeSet(t *testing.T) {
130
130
require .True (t , ok , "type assertion for attributes failed" )
131
131
132
132
// make sure we're expecting the attribute
133
- _ , exists := tt .expectedAttributes [a ]
133
+ key := attributesKey (a .GetUser (), a .GetNamespace (), a .GetVerb (), a .GetAPIGroup (), a .GetResource (), a .GetName (), a .GetPath ())
134
+ _ , exists := tt .expectedAttributes [key ]
134
135
require .True (t , exists , fmt .Sprintf ("found unexpected attributes %v" , attributes ))
135
136
136
137
// ensure each expected attribute only appears once
137
- delete (tt .expectedAttributes , a )
138
+ delete (tt .expectedAttributes , key )
138
139
}
139
140
140
141
// check that all expected have been found
0 commit comments