From a886c558a109cb2ed7414c1d12c4174ba8171499 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 10:09:39 +0200 Subject: [PATCH] fix: split back the cors --- tests/path_gateway_cors_test.go | 56 +++++++++++++++++++++++++++++++ tests/path_gateway_unixfs_test.go | 48 -------------------------- 2 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 tests/path_gateway_cors_test.go diff --git a/tests/path_gateway_cors_test.go b/tests/path_gateway_cors_test.go new file mode 100644 index 000000000..563a2a71a --- /dev/null +++ b/tests/path_gateway_cors_test.go @@ -0,0 +1,56 @@ +package tests + +import ( + "testing" + + "github.com/ipfs/gateway-conformance/tooling/specs" + . "github.com/ipfs/gateway-conformance/tooling/test" +) + +func TestCors(t *testing.T) { + cidHello := "bafkqabtimvwgy3yk" // hello + + tests := SugarTests{ + { + Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", + Request: Request(). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + { + Name: "OPTIONS to Gateway succeeds", + Request: Request(). + Method("OPTIONS"). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + } + + RunWithSpecs(t, tests, specs.PathGatewayUnixFS) +} diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 980bf9a05..e0250809f 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -434,51 +434,3 @@ func TestGatewaySymlink(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS) } - -func TestCors(t *testing.T) { - cidHello := "bafkqabtimvwgy3yk" // hello - - tests := SugarTests{ - { - Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", - Request: Request(). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), - Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - "X-Chunked-Output", - "X-Stream-Output", - ), - ), - }, - { - Name: "OPTIONS to Gateway succeeds", - Request: Request(). - Method("OPTIONS"). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), - Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - "X-Chunked-Output", - "X-Stream-Output", - ), - ), - }, - } - - RunWithSpecs(t, tests, specs.PathGatewayUnixFS) -}