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

Function TestWorkspaceSharingDisabled

coderd/workspaces_test.go:6009–6081  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // Subtests modify a package global (rbac.workspaceACLDisabled).

(t *testing.T)

Source from the content-addressed store, hash-verified

6007
6008// nolint:tparallel,paralleltest // Subtests modify a package global (rbac.workspaceACLDisabled).
6009func TestWorkspaceSharingDisabled(t *testing.T) {
6010 t.Run("CanAccessWhenEnabled", func(t *testing.T) {
6011 var (
6012 client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{
6013 DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
6014 // DisableWorkspaceSharing is false (default)
6015 }),
6016 })
6017 admin = coderdtest.CreateFirstUser(t, client)
6018 _, wsOwner = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
6019 userClient, user = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
6020 )
6021
6022 ctx := testutil.Context(t, testutil.WaitMedium)
6023
6024 // Create workspace with ACL granting access to user
6025 ws := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
6026 OwnerID: wsOwner.ID,
6027 OrganizationID: admin.OrganizationID,
6028 UserACL: database.WorkspaceACL{
6029 user.ID.String(): database.WorkspaceACLEntry{
6030 Permissions: []policy.Action{
6031 policy.ActionRead, policy.ActionSSH, policy.ActionApplicationConnect,
6032 },
6033 },
6034 },
6035 }).Do().Workspace
6036
6037 // User SHOULD be able to access workspace when sharing is enabled
6038 fetchedWs, err := userClient.Workspace(ctx, ws.ID)
6039 require.NoError(t, err)
6040 require.Equal(t, ws.ID, fetchedWs.ID)
6041 })
6042
6043 t.Run("NoAccessWhenDisabled", func(t *testing.T) {
6044 t.Cleanup(func() {
6045 rbac.ReloadBuiltinRoles(nil)
6046 })
6047
6048 var (
6049 client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{
6050 DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
6051 dv.DisableWorkspaceSharing = true
6052 }),
6053 })
6054 admin = coderdtest.CreateFirstUser(t, client)
6055 _, wsOwner = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
6056 userClient, user = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
6057 )
6058
6059 ctx := testutil.Context(t, testutil.WaitMedium)
6060
6061 // Create workspace with ACL granting access to user directly in DB
6062 ws := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
6063 OwnerID: wsOwner.ID,
6064 OrganizationID: admin.OrganizationID,
6065 UserACL: database.WorkspaceACL{
6066 user.ID.String(): database.WorkspaceACLEntry{

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewWithDatabaseFunction · 0.92
DeploymentValuesFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
WorkspaceBuildFunction · 0.92
ReloadBuiltinRolesFunction · 0.92
WorkspaceMethod · 0.80
RunMethod · 0.65
DoMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected