@@ -47,6 +47,44 @@ func agplUserQuietHoursScheduleStore() *atomic.Pointer[agplschedule.UserQuietHou
47
47
func TestCreateWorkspace (t * testing.T ) {
48
48
t .Parallel ()
49
49
50
+ t .Run ("NoTemplateAccess" , func (t * testing.T ) {
51
+ t .Parallel ()
52
+
53
+ dv := coderdtest .DeploymentValues (t )
54
+ dv .Experiments = []string {string (codersdk .ExperimentMultiOrganization )}
55
+ client , first := coderdenttest .New (t , & coderdenttest.Options {
56
+ Options : & coderdtest.Options {
57
+ DeploymentValues : dv ,
58
+ },
59
+ LicenseOptions : & coderdenttest.LicenseOptions {
60
+ Features : license.Features {
61
+ codersdk .FeatureTemplateRBAC : 1 ,
62
+ codersdk .FeatureMultipleOrganizations : 1 ,
63
+ },
64
+ }})
65
+
66
+ other , _ := coderdtest .CreateAnotherUser (t , client , first .OrganizationID , rbac .RoleMember (), rbac .RoleOwner ())
67
+
68
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
69
+ defer cancel ()
70
+
71
+ org , err := other .CreateOrganization (ctx , codersdk.CreateOrganizationRequest {
72
+ Name : "another" ,
73
+ })
74
+ require .NoError (t , err )
75
+ version := coderdtest .CreateTemplateVersion (t , other , org .ID , nil )
76
+ template := coderdtest .CreateTemplate (t , other , org .ID , version .ID )
77
+
78
+ _ , err = client .CreateWorkspace (ctx , first .OrganizationID , codersdk .Me , codersdk.CreateWorkspaceRequest {
79
+ TemplateID : template .ID ,
80
+ Name : "workspace" ,
81
+ })
82
+ require .Error (t , err )
83
+ var apiErr * codersdk.Error
84
+ require .ErrorAs (t , err , & apiErr )
85
+ require .Equal (t , http .StatusForbidden , apiErr .StatusCode ())
86
+ })
87
+
50
88
// Test that a user cannot indirectly access
51
89
// a template they do not have access to.
52
90
t .Run ("Unauthorized" , func (t * testing.T ) {
0 commit comments