@@ -396,7 +396,7 @@ func setupFakeClient(role client.Object) client.Client {
396396func TestPreAuthorize_Success (t * testing.T ) {
397397 t .Run ("preauthorize succeeds with no missing rbac rules" , func (t * testing.T ) {
398398 fakeClient := setupFakeClient (privilegedClusterRole )
399- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ( "create" ) )
399+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ))
400400 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
401401 require .NoError (t , err )
402402 require .Equal (t , []ScopedPolicyRules {}, missingRules )
@@ -406,7 +406,7 @@ func TestPreAuthorize_Success(t *testing.T) {
406406func TestPreAuthorize_MissingRBAC (t * testing.T ) {
407407 t .Run ("preauthorize fails and finds missing rbac rules" , func (t * testing.T ) {
408408 fakeClient := setupFakeClient (limitedClusterRole )
409- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ( "create" ) )
409+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ))
410410 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
411411 require .NoError (t , err )
412412 require .Equal (t , expectedSingleNamespaceMissingRules , missingRules )
@@ -416,7 +416,7 @@ func TestPreAuthorize_MissingRBAC(t *testing.T) {
416416func TestPreAuthorizeMultiNamespace_MissingRBAC (t * testing.T ) {
417417 t .Run ("preauthorize fails and finds missing rbac rules in multiple namespaces" , func (t * testing.T ) {
418418 fakeClient := setupFakeClient (limitedClusterRole )
419- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ( "create" ) )
419+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ))
420420 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifestMultiNamespace ))
421421 require .NoError (t , err )
422422 require .Equal (t , expectedMultiNamespaceMissingRules , missingRules )
@@ -426,7 +426,7 @@ func TestPreAuthorizeMultiNamespace_MissingRBAC(t *testing.T) {
426426func TestPreAuthorize_CheckEscalation (t * testing.T ) {
427427 t .Run ("preauthorize succeeds with no missing rbac rules" , func (t * testing.T ) {
428428 fakeClient := setupFakeClient (escalatingClusterRole )
429- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ( "create" ) )
429+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ))
430430 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
431431 require .NoError (t , err )
432432 require .Equal (t , []ScopedPolicyRules {}, missingRules )
@@ -436,7 +436,7 @@ func TestPreAuthorize_CheckEscalation(t *testing.T) {
436436func TestPreAuthorize_AdditionalRequiredPerms_MissingRBAC (t * testing.T ) {
437437 t .Run ("preauthorize fails and finds missing rbac rules coming from the additional required permissions" , func (t * testing.T ) {
438438 fakeClient := setupFakeClient (escalatingClusterRole )
439- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ( "create" ) )
439+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ))
440440 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ), func (user user.Info ) []authorizer.AttributesRecord {
441441 return []authorizer.AttributesRecord {
442442 {
@@ -468,8 +468,8 @@ func TestPreAuthorize_AdditionalRequiredPerms_MissingRBAC(t *testing.T) {
468468func TestPreAuthorize_WithClusterCollectionVerbs (t * testing.T ) {
469469 // expectedNamespacedMissingRules are the missing rules expected in the "test-namespace"
470470 // namespace regardless of cluster collection verb configuration. These come from object
471- // verbs (get, patch, update, delete), namespaced collection verbs ( create), and the
472- // escalation check for the role/rolebinding in the manifest.
471+ // verbs (get, patch, update, delete, create) and the escalation check for the
472+ // role/rolebinding in the manifest.
473473 expectedNamespacedMissingRules := ScopedPolicyRules {
474474 Namespace : "test-namespace" ,
475475 MissingRules : []rbacv1.PolicyRule {
@@ -514,7 +514,7 @@ func TestPreAuthorize_WithClusterCollectionVerbs(t *testing.T) {
514514
515515 t .Run ("no cluster collection verbs option omits cluster-scoped collection rules" , func (t * testing.T ) {
516516 fakeClient := setupFakeClient (limitedClusterRole )
517- preAuth := NewRBACPreAuthorizer (fakeClient , WithNamespacedCollectionVerbs ( "create" ) )
517+ preAuth := NewRBACPreAuthorizer (fakeClient )
518518 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
519519 require .NoError (t , err )
520520 // With no cluster collection verbs, there should be no cluster-scoped (namespace="") missing rules
@@ -557,7 +557,7 @@ func TestPreAuthorize_WithClusterCollectionVerbs(t *testing.T) {
557557
558558 t .Run ("privileged user with no cluster collection verbs succeeds" , func (t * testing.T ) {
559559 fakeClient := setupFakeClient (privilegedClusterRole )
560- preAuth := NewRBACPreAuthorizer (fakeClient , WithNamespacedCollectionVerbs ( "create" ) )
560+ preAuth := NewRBACPreAuthorizer (fakeClient )
561561 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
562562 require .NoError (t , err )
563563 require .Equal (t , []ScopedPolicyRules {}, missingRules )
@@ -635,7 +635,7 @@ func TestPreAuthorize_WithNamespacedCollectionVerbs(t *testing.T) {
635635
636636 t .Run ("namespaced collection verbs option checks those verbs per namespace" , func (t * testing.T ) {
637637 fakeClient := setupFakeClient (limitedClusterRole )
638- preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ("create" , " deletecollection" ))
638+ preAuth := NewRBACPreAuthorizer (fakeClient , WithClusterCollectionVerbs ("list" , "watch" ), WithNamespacedCollectionVerbs ("deletecollection" ))
639639 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
640640 require .NoError (t , err )
641641 // Should have cluster-scoped missing rules plus namespaced rules with both create and deletecollection.
@@ -689,7 +689,7 @@ func TestPreAuthorize_WithNamespacedCollectionVerbs(t *testing.T) {
689689
690690 t .Run ("privileged user with custom namespaced collection verbs succeeds" , func (t * testing.T ) {
691691 fakeClient := setupFakeClient (privilegedClusterRole )
692- preAuth := NewRBACPreAuthorizer (fakeClient , WithNamespacedCollectionVerbs ("create" , " deletecollection" ))
692+ preAuth := NewRBACPreAuthorizer (fakeClient , WithNamespacedCollectionVerbs ("deletecollection" ))
693693 missingRules , err := preAuth .PreAuthorize (context .TODO (), testUser , strings .NewReader (testManifest ))
694694 require .NoError (t , err )
695695 require .Equal (t , []ScopedPolicyRules {}, missingRules )
0 commit comments