@@ -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,23 +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 ,
138
- "workspacename_and_agent" : workspace .Name + "." + workspaceResources [0 ].Agents [0 ].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
+ "{ workspacename_and_agent} " : workspace .Name + "." + workspaceResources [0 ].Agents [0 ].Name ,
139
140
// Only checking template scoped params here
140
141
"parameters/{scope}/{id}" : fmt .Sprintf ("parameters/%s/%s" ,
141
142
string (templateParam .Scope ), templateParam .ScopeID .String ()),
@@ -179,15 +180,6 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
179
180
"POST:/api/v2/csp/reports" : {NoAuthorize : true },
180
181
"GET:/api/v2/entitlements" : {NoAuthorize : true },
181
182
182
- "GET:/%40{user}/{workspacename_and_agent}/apps/{workspaceapp}/*" : {
183
- AssertAction : rbac .ActionCreate ,
184
- AssertObject : workspaceExecObj ,
185
- },
186
- "GET:/@{user}/{workspacename_and_agent}/apps/{workspaceapp}/*" : {
187
- AssertAction : rbac .ActionCreate ,
188
- AssertObject : workspaceExecObj ,
189
- },
190
-
191
183
// Has it's own auth
192
184
"GET:/api/v2/users/oauth2/github/callback" : {NoAuthorize : true },
193
185
"GET:/api/v2/users/oidc/callback" : {NoAuthorize : true },
@@ -400,6 +392,29 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
400
392
"POST:/api/v2/workspaces/{workspace}/builds" : {StatusCode : http .StatusBadRequest , NoAuthorize : true },
401
393
"POST:/api/v2/organizations/{organization}/templateversions" : {StatusCode : http .StatusBadRequest , NoAuthorize : true },
402
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}/{workspacename_and_agent}/apps/{workspaceapp}/*" , RouteCheck {
410
+ AssertAction : rbac .ActionCreate ,
411
+ AssertObject : workspaceExecObj ,
412
+ })
413
+ assertAllHTTPMethods ("/@{user}/{workspacename_and_agent}/apps/{workspaceapp}/*" , RouteCheck {
414
+ AssertAction : rbac .ActionCreate ,
415
+ AssertObject : workspaceExecObj ,
416
+ })
417
+
403
418
return skipRoutes , assertRoute
404
419
}
405
420
@@ -447,6 +462,7 @@ func (a *AuthTester) Test(ctx context.Context, assertRoute map[string]RouteCheck
447
462
a .t .Run (name , func (t * testing.T ) {
448
463
a .authorizer .reset ()
449
464
routeKey := strings .TrimRight (name , "/" )
465
+
450
466
routeAssertions , ok := assertRoute [routeKey ]
451
467
if ! ok {
452
468
// By default, all omitted routes check for just "authorize" called
0 commit comments