@@ -85,6 +85,7 @@ func NewAuthTester(ctx context.Context, t *testing.T, options *Options) *AuthTes
85
85
Name :"some" ,
86
86
Type :"example" ,
87
87
Agents : []* proto.Agent {{
88
+ Name :"agent" ,
88
89
Id :"something" ,
89
90
Auth :& proto.Agent_Token {},
90
91
Apps : []* proto.App {{
@@ -119,22 +120,23 @@ func NewAuthTester(ctx context.Context, t *testing.T, options *Options) *AuthTes
119
120
require .NoError (t ,err ,"create template param" )
120
121
121
122
urlParameters := map [string ]string {
122
- "{organization}" :admin .OrganizationID .String (),
123
- "{user}" :admin .UserID .String (),
124
- "{organizationname}" :organization .Name ,
125
- "{workspace}" :workspace .ID .String (),
126
- "{workspacebuild}" :workspace .LatestBuild .ID .String (),
127
- "{workspacename}" :workspace .Name ,
128
- "{workspacebuildname}" :workspace .LatestBuild .Name ,
129
- "{workspaceagent}" :workspaceResources [0 ].Agents [0 ].ID .String (),
130
- "{buildnumber}" :strconv .FormatInt (int64 (workspace .LatestBuild .BuildNumber ),10 ),
131
- "{template}" :template .ID .String (),
132
- "{hash}" :file .Hash ,
133
- "{workspaceresource}" :workspaceResources [0 ].ID .String (),
134
- "{workspaceapp}" :workspaceResources [0 ].Agents [0 ].Apps [0 ].Name ,
135
- "{templateversion}" :version .ID .String (),
136
- "{jobID}" :templateVersionDryRun .ID .String (),
137
- "{templatename}" :template .Name ,
123
+ "{organization}" :admin .OrganizationID .String (),
124
+ "{user}" :admin .UserID .String (),
125
+ "{organizationname}" :organization .Name ,
126
+ "{workspace}" :workspace .ID .String (),
127
+ "{workspacebuild}" :workspace .LatestBuild .ID .String (),
128
+ "{workspacename}" :workspace .Name ,
129
+ "{workspacebuildname}" :workspace .LatestBuild .Name ,
130
+ "{workspaceagent}" :workspaceResources [0 ].Agents [0 ].ID .String (),
131
+ "{buildnumber}" :strconv .FormatInt (int64 (workspace .LatestBuild .BuildNumber ),10 ),
132
+ "{template}" :template .ID .String (),
133
+ "{hash}" :file .Hash ,
134
+ "{workspaceresource}" :workspaceResources [0 ].ID .String (),
135
+ "{workspaceapp}" :workspaceResources [0 ].Agents [0 ].Apps [0 ].Name ,
136
+ "{templateversion}" :version .ID .String (),
137
+ "{jobID}" :templateVersionDryRun .ID .String (),
138
+ "{templatename}" :template .Name ,
139
+ "{workspace_and_agent}" :workspace .Name + "." + workspaceResources [0 ].Agents [0 ].Name ,
138
140
// Only checking template scoped params here
139
141
"parameters/{scope}/{id}" :fmt .Sprintf ("parameters/%s/%s" ,
140
142
string (templateParam .Scope ),templateParam .ScopeID .String ()),
@@ -178,15 +180,6 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
178
180
"POST:/api/v2/csp/reports" : {NoAuthorize :true },
179
181
"GET:/api/v2/entitlements" : {NoAuthorize :true },
180
182
181
- "GET:/%40{user}/{workspacename}/apps/{workspaceapp}/*" : {
182
- AssertAction :rbac .ActionCreate ,
183
- AssertObject :workspaceExecObj ,
184
- },
185
- "GET:/@{user}/{workspacename}/apps/{workspaceapp}/*" : {
186
- AssertAction :rbac .ActionCreate ,
187
- AssertObject :workspaceExecObj ,
188
- },
189
-
190
183
// Has it's own auth
191
184
"GET:/api/v2/users/oauth2/github/callback" : {NoAuthorize :true },
192
185
"GET:/api/v2/users/oidc/callback" : {NoAuthorize :true },
@@ -399,6 +392,29 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
399
392
"POST:/api/v2/workspaces/{workspace}/builds" : {StatusCode :http .StatusBadRequest ,NoAuthorize :true },
400
393
"POST:/api/v2/organizations/{organization}/templateversions" : {StatusCode :http .StatusBadRequest ,NoAuthorize :true },
401
394
}
395
+
396
+ // Routes like proxy routes support all HTTP methods. A helper func to expand
397
+ // 1 url to all http methods.
398
+ assertAllHTTPMethods := func (url string ,check RouteCheck ) {
399
+ methods := []string {http .MethodGet ,http .MethodHead ,http .MethodPost ,
400
+ http .MethodPut ,http .MethodPatch ,http .MethodDelete ,
401
+ http .MethodConnect ,http .MethodOptions ,http .MethodTrace }
402
+
403
+ for _ ,method := range methods {
404
+ route := method + ":" + url
405
+ assertRoute [route ]= check
406
+ }
407
+ }
408
+
409
+ assertAllHTTPMethods ("/%40{user}/{workspace_and_agent}/apps/{workspaceapp}/*" ,RouteCheck {
410
+ AssertAction :rbac .ActionCreate ,
411
+ AssertObject :workspaceExecObj ,
412
+ })
413
+ assertAllHTTPMethods ("/@{user}/{workspace_and_agent}/apps/{workspaceapp}/*" ,RouteCheck {
414
+ AssertAction :rbac .ActionCreate ,
415
+ AssertObject :workspaceExecObj ,
416
+ })
417
+
402
418
return skipRoutes ,assertRoute
403
419
}
404
420
@@ -446,6 +462,7 @@ func (a *AuthTester) Test(ctx context.Context, assertRoute map[string]RouteCheck
446
462
a .t .Run (name ,func (t * testing.T ) {
447
463
a .authorizer .reset ()
448
464
routeKey := strings .TrimRight (name ,"/" )
465
+
449
466
routeAssertions ,ok := assertRoute [routeKey ]
450
467
if ! ok {
451
468
// By default, all omitted routes check for just "authorize" called