@@ -788,6 +788,76 @@ func TestAuthorizeScope(t *testing.T) {
788
788
{resource : ResourceWorkspaceApplicationConnect .InOrg (unusedID ).WithOwner ("not-me" ), actions : []Action {ActionCreate }, allow : false },
789
789
},
790
790
)
791
+
792
+ workspaceID := uuid .New ()
793
+ user = subject {
794
+ UserID : "me" ,
795
+ Roles : []Role {
796
+ must (RoleByName (RoleMember ())),
797
+ must (RoleByName (RoleOrgMember (defOrg ))),
798
+ },
799
+ Scope : ScopeRole {
800
+ Role : Role {
801
+ Name : "workspace_agent" ,
802
+ DisplayName : "Workspace Agent" ,
803
+ Site : permissions (map [string ][]Action {
804
+ // Only read access for workspaces.
805
+ ResourceWorkspace .Type : {ActionRead },
806
+ }),
807
+ Org : map [string ][]Permission {},
808
+ User : []Permission {},
809
+ },
810
+ AllowIDList : []string {workspaceID .String ()},
811
+ },
812
+ }
813
+
814
+ testAuthorize (t , "User_WorkspaceAgent" , user ,
815
+ // Test all cases with the workspace id
816
+ cases (func (c authTestCase ) authTestCase {
817
+ c .actions = []Action {ActionCreate , ActionUpdate , ActionDelete }
818
+ c .allow = false
819
+ c .resource .WithID (workspaceID )
820
+ return c
821
+ }, []authTestCase {
822
+ {resource : ResourceWorkspace .InOrg (defOrg ).WithOwner (user .UserID )},
823
+ {resource : ResourceWorkspace .InOrg (defOrg )},
824
+ {resource : ResourceWorkspace .WithOwner (user .UserID )},
825
+ {resource : ResourceWorkspace .All ()},
826
+ {resource : ResourceWorkspace .InOrg (unusedID ).WithOwner (user .UserID )},
827
+ {resource : ResourceWorkspace .InOrg (unusedID )},
828
+ {resource : ResourceWorkspace .InOrg (defOrg ).WithOwner ("not-me" )},
829
+ {resource : ResourceWorkspace .WithOwner ("not-me" )},
830
+ {resource : ResourceWorkspace .InOrg (unusedID ).WithOwner ("not-me" )},
831
+ {resource : ResourceWorkspace .InOrg (unusedID )},
832
+ {resource : ResourceWorkspace .WithOwner ("not-me" )},
833
+ }),
834
+ // Test cases with random ids. These should always fail from the scope.
835
+ cases (func (c authTestCase ) authTestCase {
836
+ c .actions = []Action {ActionRead , ActionCreate , ActionUpdate , ActionDelete }
837
+ c .allow = false
838
+ c .resource .WithID (uuid .New ())
839
+ return c
840
+ }, []authTestCase {
841
+ {resource : ResourceWorkspace .InOrg (defOrg ).WithOwner (user .UserID )},
842
+ {resource : ResourceWorkspace .InOrg (defOrg )},
843
+ {resource : ResourceWorkspace .WithOwner (user .UserID )},
844
+ {resource : ResourceWorkspace .All ()},
845
+ {resource : ResourceWorkspace .InOrg (unusedID ).WithOwner (user .UserID )},
846
+ {resource : ResourceWorkspace .InOrg (unusedID )},
847
+ {resource : ResourceWorkspace .InOrg (defOrg ).WithOwner ("not-me" )},
848
+ {resource : ResourceWorkspace .WithOwner ("not-me" )},
849
+ {resource : ResourceWorkspace .InOrg (unusedID ).WithOwner ("not-me" )},
850
+ {resource : ResourceWorkspace .InOrg (unusedID )},
851
+ {resource : ResourceWorkspace .WithOwner ("not-me" )},
852
+ }),
853
+ // Allowed by scope:
854
+ []authTestCase {
855
+ {resource : ResourceWorkspace .WithID (workspaceID ).InOrg (defOrg ).WithOwner (user .UserID ), actions : []Action {ActionRead }, allow : true },
856
+ // The scope will return true, but the user perms return false for resources not owned by the user.
857
+ {resource : ResourceWorkspace .WithID (workspaceID ).InOrg (defOrg ).WithOwner ("not-me" ), actions : []Action {ActionRead }, allow : false },
858
+ {resource : ResourceWorkspace .WithID (workspaceID ).InOrg (unusedID ).WithOwner ("not-me" ), actions : []Action {ActionRead }, allow : false },
859
+ },
860
+ )
791
861
}
792
862
793
863
// cases applies a given function to all test cases. This makes generalities easier to create.
0 commit comments