@@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/coder/coder/coderd/coderdtest"
27
27
"github.com/coder/coder/coderd/rbac"
28
+ "github.com/coder/coder/coderd/util/slice"
28
29
"github.com/coder/coder/coderd/workspaceapps"
29
30
"github.com/coder/coder/codersdk"
30
31
"github.com/coder/coder/testutil"
@@ -928,7 +929,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
928
929
forceURLTransport (t , client )
929
930
930
931
// Create workspace.
931
- port := appServer (t )
932
+ port := appServer (t , nil )
932
933
workspace , _ = createWorkspaceWithApps (t , client , user .OrganizationIDs [0 ], user , port )
933
934
934
935
// Verify that the apps have the correct sharing levels set.
@@ -1260,4 +1261,61 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1260
1261
})
1261
1262
}
1262
1263
})
1264
+
1265
+ t .Run ("CORSHeadersStripped" , func (t * testing.T ) {
1266
+ t .Parallel ()
1267
+
1268
+ appDetails := setupProxyTest (t , & DeploymentOptions {
1269
+ headers : http.Header {
1270
+ "X-Foobar" : []string {"baz" },
1271
+ "Access-Control-Allow-Origin" : []string {"http://localhost" },
1272
+ "access-control-allow-origin" : []string {"http://localhost" },
1273
+ "Access-Control-Allow-Credentials" : []string {"true" },
1274
+ "Access-Control-Allow-Methods" : []string {"PUT" },
1275
+ "Access-Control-Allow-Headers" : []string {"X-Foobar" },
1276
+ "Vary" : []string {
1277
+ "Origin" ,
1278
+ "origin" ,
1279
+ "Access-Control-Request-Headers" ,
1280
+ "access-Control-request-Headers" ,
1281
+ "Access-Control-Request-Methods" ,
1282
+ "ACCESS-CONTROL-REQUEST-METHODS" ,
1283
+ "X-Foobar" ,
1284
+ },
1285
+ },
1286
+ })
1287
+
1288
+ appURL := appDetails .SubdomainAppURL (appDetails .Apps .Owner )
1289
+
1290
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1291
+ defer cancel ()
1292
+
1293
+ resp , err := requestWithRetries (ctx , t , appDetails .AppClient (t ), http .MethodGet , appURL .String (), nil )
1294
+ require .NoError (t , err )
1295
+ defer resp .Body .Close ()
1296
+
1297
+ require .Equal (t , http .StatusOK , resp .StatusCode )
1298
+ require .Equal (t , []string (nil ), resp .Header .Values ("Access-Control-Allow-Origin" ))
1299
+ require .Equal (t , []string (nil ), resp .Header .Values ("Access-Control-Allow-Credentials" ))
1300
+ require .Equal (t , []string (nil ), resp .Header .Values ("Access-Control-Allow-Methods" ))
1301
+ require .Equal (t , []string (nil ), resp .Header .Values ("Access-Control-Allow-Headers" ))
1302
+ // Somehow there are two "Origin"s in Vary even though there should only be
1303
+ // one (from the CORS middleware), even if you remove the headers being sent
1304
+ // above. When I do nothing else but change the expected value below to
1305
+ // have two "Origin"s suddenly Vary only has one. It is somehow always the
1306
+ // opposite of whatever I put for the expected. So, reluctantly, remove
1307
+ // duplicate "Origin" values.
1308
+ var deduped []string
1309
+ var addedOrigin bool
1310
+ for _ , value := range resp .Header .Values ("Vary" ) {
1311
+ if value != "Origin" || ! addedOrigin {
1312
+ if value == "Origin" {
1313
+ addedOrigin = true
1314
+ }
1315
+ deduped = append (deduped , value )
1316
+ }
1317
+ }
1318
+ require .Equal (t , []string {"Origin" , "X-Foobar" }, deduped )
1319
+ require .Equal (t , []string {"baz" }, resp .Header .Values ("X-Foobar" ))
1320
+ })
1263
1321
}
0 commit comments