MCPcopy Index your code
hub / github.com/coder/coder / TestOrgSharingPermissions

Function TestOrgSharingPermissions

coderd/rbac/roles_test.go:65–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestOrgSharingPermissions(t *testing.T) {
66 t.Parallel()
67
68 tests := []struct {
69 name string
70 permsFunc func(rbac.OrgSettings) rbac.OrgRolePermissions
71 mode rbac.ShareableWorkspaceOwners
72 orgReadMembers bool
73 orgReadGroups bool
74 orgNegateShare bool
75 memberNegateShare bool
76 }{
77 {"Member/Everyone", rbac.OrgMemberPermissions, rbac.ShareableWorkspaceOwnersEveryone, true, true, false, false},
78 {"Member/None", rbac.OrgMemberPermissions, rbac.ShareableWorkspaceOwnersNone, false, false, true, true},
79 {"Member/ServiceAccounts", rbac.OrgMemberPermissions, rbac.ShareableWorkspaceOwnersServiceAccounts, true, false, false, true},
80 {"ServiceAccount/Everyone", rbac.OrgServiceAccountPermissions, rbac.ShareableWorkspaceOwnersEveryone, true, true, false, false},
81 {"ServiceAccount/None", rbac.OrgServiceAccountPermissions, rbac.ShareableWorkspaceOwnersNone, false, false, true, false},
82 {"ServiceAccount/ServiceAccounts", rbac.OrgServiceAccountPermissions, rbac.ShareableWorkspaceOwnersServiceAccounts, true, true, false, false},
83 }
84
85 for _, tt := range tests {
86 t.Run(tt.name, func(t *testing.T) {
87 t.Parallel()
88
89 perms := tt.permsFunc(rbac.OrgSettings{
90 ShareableWorkspaceOwners: tt.mode,
91 })
92
93 assert.Equal(t, tt.orgReadMembers, permissionGranted(perms.Org, rbac.Permission{
94 ResourceType: rbac.ResourceOrganizationMember.Type,
95 Action: policy.ActionRead,
96 }), "org read members")
97
98 assert.Equal(t, tt.orgReadGroups, permissionGranted(perms.Org, rbac.Permission{
99 ResourceType: rbac.ResourceGroup.Type,
100 Action: policy.ActionRead,
101 }), "org read groups")
102
103 assert.Equal(t, tt.orgNegateShare, permissionGranted(perms.Org, rbac.Permission{
104 Negate: true,
105 ResourceType: rbac.ResourceWorkspace.Type,
106 Action: policy.ActionShare,
107 }), "org negate share")
108
109 assert.Equal(t, tt.memberNegateShare, permissionGranted(perms.Member, rbac.Permission{
110 Negate: true,
111 ResourceType: rbac.ResourceWorkspace.Type,
112 Action: policy.ActionShare,
113 }), "member negate share")
114 })
115 }
116}
117
118//nolint:tparallel,paralleltest
119func TestChatSharingPermissions(t *testing.T) {

Callers

nothing calls this directly

Calls 3

permissionGrantedFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected