@@ -287,11 +287,9 @@ func TestCreateUserWorkspace(t *testing.T) {
287
287
OrganizationID : first .OrganizationID ,
288
288
})
289
289
290
- version := coderdtest .CreateTemplateVersion (t , admin , first .OrganizationID , nil )
291
- coderdtest .AwaitTemplateVersionJobCompleted (t , admin , version .ID )
292
- template := coderdtest .CreateTemplate (t , admin , first .OrganizationID , version .ID )
290
+ template , _ := coderdtest .DynamicParameterTemplate (t , admin , first .OrganizationID , coderdtest.DynamicParameterTemplateParams {})
293
291
294
- ctx = testutil .Context (t , testutil .WaitLong * 1000 ) // Reset the context to avoid timeouts.
292
+ ctx = <
EDBE
span class="pl-s1">testutil.Context (t , testutil .WaitLong )
295
293
296
294
wrk , err := creator .CreateUserWorkspace (ctx , adminID .ID .String (), codersdk.CreateWorkspaceRequest {
297
295
TemplateID : template .ID ,
@@ -306,6 +304,66 @@ func TestCreateUserWorkspace(t *testing.T) {
306
304
require .NoError (t , err )
307
305
})
308
306
307
+ t .Run ("ForANonOrgMember" , func (t * testing.T ) {
308
+ t .Parallel ()
309
+
310
+ owner , first := coderdenttest .New (t , & coderdenttest.Options {
311
+ Options : & coderdtest.Options {
312
+ IncludeProvisionerDaemon : true ,
313
+ },
314
+ LicenseOptions : & coderdenttest.LicenseOptions {
315
+ Features : license.Features {
316
+ codersdk .FeatureCustomRoles : 1 ,
317
+ codersdk .FeatureTemplateRBAC : 1 ,
318
+ codersdk .FeatureMultipleOrganizations : 1 ,
319
+ },
320
+ },
321
+ })
322
+ ctx := testutil .Context (t , testutil .WaitShort )
323
+ //nolint:gocritic // using owner to setup roles
324
+ r , err := owner .CreateOrganizationRole (ctx , codersdk.Role {
325
+ Name : "creator" ,
326
+ OrganizationID : first .OrganizationID .String (),
327
+ DisplayName : "Creator" ,
328
+ OrganizationPermissions : codersdk .CreatePermissions (map [codersdk.RBACResource ][]codersdk.RBACAction {
329
+ codersdk .ResourceWorkspace : {codersdk .ActionCreate , codersdk .ActionWorkspaceStart , codersdk .ActionUpdate , codersdk .ActionRead },
330
+ codersdk .ResourceOrganizationMember : {codersdk .ActionRead },
331
+ }),
332
+ })
333
+ require .NoError (t , err )
334
+
335
+ // user to make the workspace for, **note** the user is not a member of the first org.
336
+ // This is strange, but technically valid. The creator can create a workspace for
337
+ // this user in this org, even though the user cannot access the workspace.
338
+ secondOrg := coderdenttest .CreateOrganization (t , owner , coderdenttest.CreateOrganizationOptions {})
339
+ _ , forUser := coderdtest .CreateAnotherUser (t , owner , secondOrg .ID )
340
+
341
+ // try the test action with this user & custom role
342
+ creator , _ := coderdtest .CreateAnotherUser (t , owner , first .OrganizationID , rbac .RoleMember (),
343
+ rbac .RoleTemplateAdmin (), // Need site wide access to make workspace for non-org
344
+ rbac.RoleIdentifier {
345
+ Name : r .Name ,
346
+ OrganizationID : first .OrganizationID ,
347
+ },
348
+ )
349
+
350
+ template , _ := coderdtest .DynamicParameterTemplate (t , creator , first .OrganizationID , coderdtest.DynamicParameterTemplateParams {})
351
+
352
+ ctx = testutil .Context (t , testutil .WaitLong )
353
+
354
+ wrk , err := creator .CreateUserWorkspace (ctx , forUser .ID .String (), codersdk.CreateWorkspaceRequest {
355
+ TemplateID : template .ID ,
356
+ Name : "workspace" ,
357
+ })
358
+ require .NoError (t , err )
359
+ coderdtest .AwaitWorkspaceBuildJobCompleted (t , creator , wrk .LatestBuild .ID )
360
+
361
+ _ , err = creator .WorkspaceByOwnerAndName (ctx , forUser .Username , wrk .Name , codersdk.WorkspaceOptions {
362
+ IncludeDeleted : false ,
363
+ })
364
+ require .NoError (t , err )
365
+ })
366
+
309
367
// Asserting some authz calls when creating a workspace.
310
368
t .Run ("AuthzStory" , func (t * testing.T ) {
311
369
t .Parallel ()
0 commit comments