@@ -131,15 +131,7 @@ func Test_PolicyFromYAML(t *testing.T) {
131
131
require .Equal (t , "role:unknown" , dRole )
132
132
require .Empty (t , matchMode )
133
133
require .True (t , checkPolicy ("my-org:team-qa" , "update" , "project" , "foo" ,
134
- "" , uPol , dRole , matchMode , true , nil ))
135
- }
136
-
137
- func trueLogRbacEnforce () bool {
138
- return true
139
- }
140
-
141
- func falseLogRbacEnforce () bool {
142
- return false
134
+ "" , uPol , dRole , matchMode , true ))
143
135
}
144
136
145
137
func Test_PolicyFromK8s (t * testing.T ) {
@@ -163,105 +155,63 @@ func Test_PolicyFromK8s(t *testing.T) {
163
155
require .Equal (t , "" , matchMode )
164
156
165
157
t .Run ("get applications" , func (t * testing.T ) {
166
- ok := checkPolicy ("role:user" , "get" , "applications" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
158
+ ok := checkPolicy ("role:user" , "get" , "applications" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
167
159
require .True (t , ok )
168
160
})
169
161
t .Run ("get clusters" , func (t * testing.T ) {
170
- ok := checkPolicy ("role:user" , "get" , "clusters" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
162
+ ok := checkPolicy ("role:user" , "get" , "clusters" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
171
163
require .True (t , ok )
172
164
})
173
165
t .Run ("get certificates" , func (t * testing.T ) {
174
- ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
166
+ ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
175
167
require .False (t , ok )
176
168
})
177
169
t .Run ("get certificates by default role" , func (t * testing.T ) {
178
- ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , assets .BuiltinPolicyCSV , uPol , "role:readonly" , "glob" , true , nil )
170
+ ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , assets .BuiltinPolicyCSV , uPol , "role:readonly" , "glob" , true )
179
171
require .True (t , ok )
180
172
})
181
173
t .Run ("get certificates by default role without builtin policy" , func (t * testing.T ) {
182
- ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , "" , uPol , "role:readonly" , "glob" , true , nil )
174
+ ok := checkPolicy ("role:user" , "get" , "certificates" , "*" , "" , uPol , "role:readonly" , "glob" , true )
183
175
require .False (t , ok )
184
176
})
185
177
t .Run ("use regex match mode instead of glob" , func (t * testing.T ) {
186
- ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , assets .BuiltinPolicyCSV , uPol , "role:readonly" , "regex" , true , nil )
178
+ ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , assets .BuiltinPolicyCSV , uPol , "role:readonly" , "regex" , true )
187
179
require .False (t , ok )
188
180
})
189
181
t .Run ("get logs" , func (t * testing.T ) {
190
- ok := checkPolicy ("role:test" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
182
+ ok := checkPolicy ("role:test" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
191
183
require .True (t , ok )
192
184
})
193
- // no function is provided to check if logs rbac is enforced or not, so the policy permissions are queried to determine if no-such-user can get logs
194
185
t .Run ("no-such-user get logs" , func (t * testing.T ) {
195
- ok := checkPolicy ("no-such-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
196
- require .False (t , ok )
197
- })
198
- // logs rbac policy is enforced, and no-such-user is not granted logs permission in user policy, so the result should be false (cannot get logs)
199
- t .Run ("no-such-user get logs rbac enforced" , func (t * testing.T ) {
200
- ok := checkPolicy ("no-such-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , trueLogRbacEnforce )
186
+ ok := checkPolicy ("no-such-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
201
187
require .False (t , ok )
202
188
})
203
- // no-such-user is not granted logs permission in user policy, but logs rbac policy is not enforced, so logs permission is open to all
204
- t .Run ("no-such-user get logs rbac not enforced" , func (t * testing.T ) {
205
- ok := checkPolicy ("no-such-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , falseLogRbacEnforce )
206
- require .True (t , ok )
207
- })
208
- // no function is provided to check if logs rbac is enforced or not, so the policy permissions are queried to determine if log-deny-user can get logs
209
189
t .Run ("log-deny-user get logs" , func (t * testing.T ) {
210
- ok := checkPolicy ("log-deny-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
211
- require .False (t , ok )
212
- })
213
- // logs rbac policy is enforced, and log-deny-user is denied logs permission in user policy, so the result should be false (cannot get logs)
214
- t .Run ("log-deny-user get logs rbac enforced" , func (t * testing.T ) {
215
- ok := checkPolicy ("log-deny-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , trueLogRbacEnforce )
190
+ ok := checkPolicy ("log-deny-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
216
191
require .False (t , ok )
217
192
})
218
- // log-deny-user is denied logs permission in user policy, but logs rbac policy is not enforced, so logs permission is open to all
219
- t .Run ("log-deny-user get logs rbac not enforced" , func (t * testing.T ) {
220
- ok := checkPolicy ("log-deny-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , falseLogRbacEnforce )
221
- require .True (t , ok )
222
- })
223
- // no function is provided to check if logs rbac is enforced or not, so the policy permissions are queried to determine if log-allow-user can get logs
224
193
t .Run ("log-allow-user get logs" , func (t * testing.T ) {
225
- ok := checkPolicy ("log-allow-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
226
- require .True (t , ok )
227
- })
228
- // logs rbac policy is enforced, and log-allow-user is granted logs permission in user policy, so the result should be true (can get logs)
229
- t .Run ("log-allow-user get logs rbac enforced" , func (t * testing.T ) {
230
- ok := checkPolicy ("log-allow-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , trueLogRbacEnforce )
231
- require .True (t , ok )
232
- })
233
- // log-allow-user is granted logs permission in user policy, and logs rbac policy is not enforced, so logs permission is open to all
234
- t .Run ("log-allow-user get logs rbac not enforced" , func (t * testing.T ) {
235
- ok := checkPolicy ("log-allow-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , falseLogRbacEnforce )
194
+ ok := checkPolicy ("log-allow-user" , "get" , "logs" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
236
195
require .True (t , ok )
237
196
})
238
197
t .Run ("get logs" , func (t * testing.T ) {
239
- ok := checkPolicy ("role:test" , "get" , "logs" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
198
+ ok := checkPolicy ("role:test" , "get" , "logs" , "*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
240
199
require .True (t , ok )
241
200
})
242
201
t .Run ("get logs" , func (t * testing.T ) {
243
- ok := checkPolicy ("role:test" , "get" , "logs" , "" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
202
+ ok := checkPolicy ("role:test" , "get" , "logs" , "" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
244
203
require .True (t , ok )
245
204
})
246
205
t .Run ("create exec" , func (t * testing.T ) {
247
- ok := checkPolicy ("role:test" , "create" , "exec" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
206
+ ok := checkPolicy ("role:test" , "create" , "exec" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
248
207
require .True (t , ok )
249
208
})
250
209
t .Run ("create applicationsets" , func (t * testing.T ) {
251
- ok := checkPolicy ("role:user" , "create" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
252
- require .True (t , ok )
253
- })
254
- // trueLogRbacEnforce or falseLogRbacEnforce should not affect non-logs resources
255
- t .Run ("create applicationsets with trueLogRbacEnforce" , func (t * testing.T ) {
256
- ok := checkPolicy ("role:user" , "create" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , trueLogRbacEnforce )
257
- require .True (t , ok )
258
- })
259
- t .Run ("create applicationsets with falseLogRbacEnforce" , func (t * testing.T ) {
260
- ok := checkPolicy ("role:user" , "create" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , trueLogRbacEnforce )
210
+ ok := checkPolicy ("role:user" , "create" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
261
211
require .True (t , ok )
262
212
})
263
213
t .Run ("delete applicationsets" , func (t * testing.T ) {
264
- ok := checkPolicy ("role:user" , "delete" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true , nil )
214
+ ok := checkPolicy ("role:user" , "delete" , "applicationsets" , "*/*" , assets .BuiltinPolicyCSV , uPol , dRole , "" , true )
265
215
require .True (t , ok )
266
216
})
267
217
}
@@ -301,49 +251,49 @@ p, role:readonly, certificates, get, .*, allow
301
251
p, role:, certificates, get, .*, allow`
302
252
303
253
t .Run ("get applications" , func (t * testing.T ) {
304
- ok := checkPolicy ("role:user" , "get" , "applications" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
254
+ ok := checkPolicy ("role:user" , "get" , "applications" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true )
305
255
require .True (t , ok )
306
256
})
307
257
t .Run ("get clusters" , func (t * testing.T ) {
308
- ok := checkPolicy ("role:user" , "get" , "clusters" , ".*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
258
+ ok := checkPolicy ("role:user" , "get" , "clusters" , ".*" , builtInPolicy , uPol , dRole , "regex" , true )
309
259
require .True (t , ok )
310
260
})
311
261
t .Run ("get certificates" , func (t * testing.T ) {
312
- ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
262
+ ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , builtInPolicy , uPol , dRole , "regex" , true )
313
263
require .False (t , ok )
314
264
})
315
265
t .Run ("get certificates by default role" , func (t * testing.T ) {
316
- ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , builtInPolicy , uPol , "role:readonly" , "regex" , true , nil )
266
+ ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , builtInPolicy , uPol , "role:readonly" , "regex" , true )
317
267
require .True (t , ok )
318
268
})
319
269
t .Run ("get certificates by default role without builtin policy" , func (t * testing.T ) {
320
- ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , "" , uPol , "role:readonly" , "regex" , true , nil )
270
+ ok := checkPolicy ("role:user" , "get" , "certificates" , ".*" , "" , uPol , "role:readonly" , "regex" , true )
321
271
require .False (t , ok )
322
272
})
323
273
t .Run ("use glob match mode instead of regex" , func (t * testing.T ) {
324
- ok := checkPolicy ("role:user" , "get" , "certificates" , ".+" , builtInPolicy , uPol , dRole , "glob" , true , nil )
274
+ ok := checkPolicy ("role:user" , "get" , "certificates" , ".+" , builtInPolicy , uPol , dRole , "glob" , true )
325
275
require .False (t , ok )
326
276
})
327
277
t .Run ("get logs via glob match mode" , func (t * testing.T ) {
328
- ok := checkPolicy ("role:user" , "get" , "logs" , ".*/.*" , builtInPolicy , uPol , dRole , "glob" , true , nil )
278
+ ok := checkPolicy ("role:user" , "get" , "logs" , ".*/.*" , builtInPolicy , uPol , dRole , "glob" , true )
329
279
require .True (t , ok )
330
280
})
331
281
t .Run ("create exec" , func (t * testing.T ) {
332
- ok := checkPolicy ("role:user" , "create" , "exec" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
282
+ ok := checkPolicy ("role:user" , "create" , "exec" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true )
333
283
require .True (t , ok )
334
284
})
335
285
t .Run ("create applicationsets" , func (t * testing.T ) {
336
- ok := checkPolicy ("role:user" , "create" , "applicationsets" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
286
+ ok := checkPolicy ("role:user" , "create" , "applicationsets" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true )
337
287
require .True (t , ok )
338
288
})
339
289
t .Run ("delete applicationsets" , func (t * testing.T ) {
340
- ok := checkPolicy ("role:user" , "delete" , "applicationsets" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true , nil )
290
+ ok := checkPolicy ("role:user" , "delete" , "applicationsets" , ".*/.*" , builtInPolicy , uPol , dRole , "regex" , true )
341
291
require .True (t , ok )
342
292
})
343
293
}
344
294
345
295
func TestNewRBACCanCommand (t * testing.T ) {
346
- command := NewRBACCanCommand (& settingsOpts {} )
296
+ command := NewRBACCanCommand ()
347
297
348
298
require .NotNil (t , command )
349
299
assert .Equal (t , "can" , command .Name ())
0 commit comments