@@ -60,95 +60,111 @@ func TestMaxPrivilege(t *testing.T) {
60
60
}
61
61
62
62
func TestACLManagement (t * testing.T ) {
63
+ assert := assert .New (t )
64
+
63
65
// Create management ACL
64
66
acl , err := NewACL (true , nil )
65
- assert .Nil (t , err )
67
+ assert .Nil (err )
66
68
67
69
// Check default namespace rights
68
- assert .Equal (t , true , acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
69
- assert .Equal (t , true , acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
70
+ assert .True (acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
71
+ assert .True (acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
72
+ assert .True (acl .AllowNamespace ("default" ))
70
73
71
74
// Check non-specified namespace
72
- assert .Equal (t , true , acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
75
+ assert .True (acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
76
+ assert .True (acl .AllowNamespace ("foo" ))
73
77
74
78
// Check the other simpler operations
75
- assert .Equal (t , true , acl .IsManagement ())
76
- assert .Equal (t , true , acl .AllowAgentRead ())
77
- assert .Equal (t , true , acl .AllowAgentWrite ())
78
- assert .Equal (t , true , acl .AllowNodeRead ())
79
- assert .Equal (t , true , acl .AllowNodeWrite ())
80
- assert .Equal (t , true , acl .AllowOperatorRead ())
81
- assert .Equal (t , true , acl .AllowOperatorWrite ())
79
+ assert .True (acl .IsManagement ())
80
+ assert .True (acl .AllowAgentRead ())
81
+ assert .True (acl .AllowAgentWrite ())
82
+ assert .True (acl .AllowNodeRead ())
83
+ assert .True (acl .AllowNodeWrite ())
84
+ assert .True (acl .AllowOperatorRead ())
85
+ assert .True (acl .AllowOperatorWrite ())
86
+ assert .True (acl .AllowQuotaRead ())
87
+ assert .True (acl .AllowQuotaWrite ())
82
88
}
83
89
84
90
func TestACLMerge (t * testing.T ) {
91
+ assert := assert .New (t )
92
+
85
93
// Merge read + write policy
86
94
p1 , err := Parse (readAll )
87
- assert .Nil (t , err )
95
+ assert .Nil (err )
88
96
p2 , err := Parse (writeAll )
89
- assert .Nil (t , err )
97
+ assert .Nil (err )
90
98
acl , err := NewACL (false , []* Policy {p1 , p2 })
91
- assert .Nil (t , err )
99
+ assert .Nil (err )
92
100
93
101
// Check default namespace rights
94
- assert .Equal (t , true , acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
95
- assert .Equal (t , true , acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
102
+ assert .True (acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
103
+ assert .True (acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
104
+ assert .True (acl .AllowNamespace ("default" ))
96
105
97
106
// Check non-specified namespace
98
- assert .Equal (t , false , acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
107
+ assert .False (acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
108
+ assert .False (acl .AllowNamespace ("foo" ))
99
109
100
110
// Check the other simpler operations
101
- assert .Equal (t , false , acl .IsManagement ())
102
- assert .Equal (t , true , acl .AllowAgentRead ())
103
- assert .Equal (t , true , acl .AllowAgentWrite ())
104
- assert .Equal (t , true , acl .AllowNodeRead ())
105
- assert .Equal (t , true , acl .AllowNodeWrite ())
106
- assert .Equal (t , true , acl .AllowOperatorRead ())
107
- assert .Equal (t , true , acl .AllowOperatorWrite ())
111
+ assert .False (acl .IsManagement ())
112
+ assert .True (acl .AllowAgentRead ())
113
+ assert .True (acl .AllowAgentWrite ())
114
+ assert .True (acl .AllowNodeRead ())
115
+ assert .True (acl .AllowNodeWrite ())
116
+ assert .True (acl .AllowOperatorRead ())
117
+ assert .True (acl .AllowOperatorWrite ())
118
+ assert .True (acl .AllowQuotaRead ())
119
+ assert .True (acl .AllowQuotaWrite ())
108
120
109
121
// Merge read + blank
110
122
p3 , err := Parse ("" )
111
- assert .Nil (t , err )
123
+ assert .Nil (err )
112
124
acl , err = NewACL (false , []* Policy {p1 , p3 })
113
- assert .Nil (t , err )
125
+ assert .Nil (err )
114
126
115
127
// Check default namespace rights
116
- assert .Equal ( t , true , acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
117
- assert .Equal ( t , false , acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
128
+ assert .True ( acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
129
+ assert .False ( acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
118
130
119
131
// Check non-specified namespace
120
- assert .Equal ( t , false , acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
132
+ assert .False ( acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
121
133
122
134
// Check the other simpler operations
123
- assert .Equal (t , false , acl .IsManagement ())
124
- assert .Equal (t , true , acl .AllowAgentRead ())
125
- assert .Equal (t , false , acl .AllowAgentWrite ())
126
- assert .Equal (t , true , acl .AllowNodeRead ())
127
- assert .Equal (t , false , acl .AllowNodeWrite ())
128
- assert .Equal (t , true , acl .AllowOperatorRead ())
129
- assert .Equal (t , false , acl .AllowOperatorWrite ())
135
+ assert .False (acl .IsManagement ())
136
+ assert .True (acl .AllowAgentRead ())
137
+ assert .False (acl .AllowAgentWrite ())
138
+ assert .True (acl .AllowNodeRead ())
139
+ assert .False (acl .AllowNodeWrite ())
140
+ assert .True (acl .AllowOperatorRead ())
141
+ assert .False (acl .AllowOperatorWrite ())
142
+ assert .True (acl .AllowQuotaRead ())
143
+ assert .False (acl .AllowQuotaWrite ())
130
144
131
145
// Merge read + deny
132
146
p4 , err := Parse (denyAll )
133
- assert .Nil (t , err )
147
+ assert .Nil (err )
134
148
acl , err = NewACL (false , []* Policy {p1 , p4 })
135
- assert .Nil (t , err )
149
+ assert .Nil (err )
136
150
137
151
// Check default namespace rights
138
- assert .Equal ( t , false , acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
139
- assert .Equal ( t , false , acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
152
+ assert .False ( acl .AllowNamespaceOperation ("default" , NamespaceCapabilityListJobs ))
153
+ assert .False ( acl .AllowNamespaceOperation ("default" , NamespaceCapabilitySubmitJob ))
140
154
141
155
// Check non-specified namespace
142
- assert .Equal ( t , false , acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
156
+ assert .False ( acl .AllowNamespaceOperation ("foo" , NamespaceCapabilityListJobs ))
143
157
144
158
// Check the other simpler operations
145
- assert .Equal (t , false , acl .IsManagement ())
146
- assert .Equal (t , false , acl .AllowAgentRead ())
147
- assert .Equal (t , false , acl .AllowAgentWrite ())
148
- assert .Equal (t , false , acl .AllowNodeRead ())
149
- assert .Equal (t , false , acl .AllowNodeWrite ())
150
- assert .Equal (t , false , acl .AllowOperatorRead ())
151
- assert .Equal (t , false , acl .AllowOperatorWrite ())
159
+ assert .False (acl .IsManagement ())
160
+ assert .False (acl .AllowAgentRead ())
161
+ assert .False (acl .AllowAgentWrite ())
162
+ assert .False (acl .AllowNodeRead ())
163
+ assert .False (acl .AllowNodeWrite ())
164
+ assert .False (acl .AllowOperatorRead ())
165
+ assert .False (acl .AllowOperatorWrite ())
166
+ assert .False (acl .AllowQuotaRead ())
167
+ assert .False (acl .AllowQuotaWrite ())
152
168
}
153
169
154
170
var readAll = `
@@ -164,6 +180,9 @@ node {
164
180
operator {
165
181
policy = "read"
166
182
}
183
+ quota {
184
+ policy = "read"
185
+ }
167
186
`
168
187
169
188
var writeAll = `
@@ -179,6 +198,9 @@ node {
179
198
operator {
180
199
policy = "write"
181
200
}
201
+ quota {
202
+ policy = "write"
203
+ }
182
204
`
183
205
184
206
var denyAll = `
@@ -194,4 +216,49 @@ node {
194
216
operator {
195
217
policy = "deny"
196
218
}
219
+ quota {
220
+ policy = "deny"
221
+ }
197
222
`
223
+
224
+ func TestAllowNamespace (t * testing.T ) {
225
+ tests := []struct {
226
+ Policy string
227
+ Allow bool
228
+ }{
229
+ {
230
+ Policy : `namespace "foo" {}` ,
231
+ Allow : false ,
232
+ },
233
+ {
234
+ Policy : `namespace "foo" { policy = "deny" }` ,
235
+ Allow : false ,
236
+ },
237
+ {
238
+ Policy : `namespace "foo" { capabilities = ["deny"] }` ,
239
+ Allow : false ,
240
+ },
241
+ {
242
+ Policy : `namespace "foo" { capabilities = ["list-jobs"] }` ,
243
+ Allow : true ,
244
+ },
245
+ {
246
+ Policy : `namespace "foo" { policy = "read" }` ,
247
+ Allow : true ,
248
+ },
249
+ }
250
+
251
+ for _ , tc := range tests {
252
+ t .Run (tc .Policy , func (t * testing.T ) {
253
+ assert := assert .New (t )
254
+
255
+ policy , err := Parse (tc .Policy )
256
+ assert .Nil (err )
257
+
258
+ acl , err := NewACL (false , []* Policy {policy })
259
+ assert .Nil (err )
260
+
261
+ assert .Equal (tc .Allow , acl .AllowNamespace ("foo" ))
262
+ })
263
+ }
264
+ }
0 commit comments