@@ -265,7 +265,7 @@ func TestRolePermissions(t *testing.T) {
265
265
},
266
266
{
267
267
Name : "APIKey" ,
268
- Actions : []policy.Action {policy .ActionCreate , policy .ActionRead , policy .ActionUpdate , policy . ActionDelete },
268
+ Actions : []policy.Action {policy .ActionCreate , policy .ActionRead , policy .ActionDelete },
269
269
Resource : rbac .ResourceApiKey .WithID (apiKeyID ).WithOwner (currentUser .String ()),
270
270
AuthorizeMap : map [bool ][]authSubject {
271
271
true : {owner , orgMemberMe , memberMe },
@@ -332,7 +332,16 @@ func TestRolePermissions(t *testing.T) {
332
332
},
333
333
{
334
334
Name : "WorkspaceDormant" ,
335
- Actions : rbac .AllActions (),
335
+ Actions : crud ,
336
+ Resource : rbac .ResourceWorkspaceDormant .WithID (uuid .New ()).InOrg (orgID ).WithOwner (memberMe .Actor .ID ),
337
+ AuthorizeMap : map [bool ][]authSubject {
338
+ true : {orgMemberMe , orgAdmin , owner },
339
+ false : {userAdmin , otherOrgAdmin , otherOrgMember , memberMe , templateAdmin },
340
+ },
341
+ },
342
+ {
343
+ Name : "WorkspaceDormantUse" ,
344
+ Actions : []policy.Action {policy .ActionWorkspaceBuild , policy .ActionApplicationConnect , policy .ActionSSH },
336
345
Resource : rbac .ResourceWorkspaceDormant .WithID (uuid .New ()).InOrg (orgID ).WithOwner (memberMe .Actor .ID ),
337
346
AuthorizeMap : map [bool ][]authSubject {
338
347
true : {},
@@ -478,7 +487,7 @@ func TestRolePermissions(t *testing.T) {
478
487
},
479
488
{
480
489
Name : "Oauth2Token" ,
481
- Actions : crud ,
490
+ Actions : []policy. Action { policy . ActionCreate , policy . ActionRead , policy . ActionDelete } ,
482
491
Resource : rbac .ResourceOauth2AppCodeToken ,
483
492
AuthorizeMap : map [bool ][]authSubject {
484
493
true : {owner },
@@ -514,6 +523,7 @@ func TestRolePermissions(t *testing.T) {
514
523
}
515
524
}
516
525
526
+ passed := true
517
527
for _ , c := range testCases {
518
528
c := c
519
529
// nolint:tparallel -- These share the same remainingPermissions map
@@ -524,6 +534,13 @@ func TestRolePermissions(t *testing.T) {
524
534
}
525
535
526
536
for _ , action := range c .Actions {
537
+ err := c .Resource .ValidAction (action )
538
+ ok := assert .NoError (t , err , "%q is not a valid action for type %q" , action , c .Resource .Type )
539
+ if ! ok {
540
+ passed = passed && assert .NoError (t , err , "%q is not a valid action for type %q" , action , c .Resource .Type )
541
+ continue
542
+ }
543
+
527
544
for result , subjs := range c .AuthorizeMap {
528
545
for _ , subj := range subjs {
529
546
delete (remainingSubjs , subj .Name )
@@ -538,9 +555,9 @@ func TestRolePermissions(t *testing.T) {
538
555
delete (remainingPermissions [c .Resource .Type ], action )
539
556
err := auth .Authorize (context .Background (), actor , action , c .Resource )
540
557
if result {
541
- assert .NoError (t , err , fmt .Sprintf ("Should pass: %s" , msg ))
558
+ passed = passed && assert .NoError (t , err , fmt .Sprintf ("Should pass: %s" , msg ))
542
559
} else {
543
- assert .ErrorContains (t , err , "forbidden" , fmt .Sprintf ("Should fail: %s" , msg ))
560
+ passed = passed && assert .ErrorContains (t , err , "forbidden" , fmt .Sprintf ("Should fail: %s" , msg ))
544
561
}
545
562
}
546
563
}
@@ -549,13 +566,16 @@ func TestRolePermissions(t *testing.T) {
549
566
})
550
567
}
551
568
552
- for rtype , v := range remainingPermissions {
553
- // nolint:tparallel -- Making a subtest for easier diagnosing failures.
554
- t .Run (fmt .Sprintf ("%s-AllActions" , rtype ), func (t * testing.T ) {
555
- if len (v ) > 0 {
556
- assert .Equal (t , map [policy.Action ]bool {}, v , "remaining permissions should be empty for type %q" , rtype )
557
- }
558
- })
569
+ // Only run these if the tests on top passed. Otherwise, the error output is too noisy.
570
+ if passed {
571
+ for rtype , v := range remainingPermissions {
572
+ // nolint:tparallel -- Making a subtest for easier diagnosing failures.
573
+ t .Run (fmt .Sprintf ("%s-AllActions" , rtype ), func (t * testing.T ) {
574
+ if len (v ) > 0 {
575
+ assert .Equal (t , map [policy.Action ]bool {}, v , "remaining permissions should be empty for type %q" , rtype )
576
+ }
577
+ })
578
+ }
559
579
}
560
580
}
561
581
0 commit comments