Skip to content

Commit

Permalink
fix: split back the cors
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Jun 30, 2023
1 parent fc12109 commit a886c55
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
56 changes: 56 additions & 0 deletions tests/path_gateway_cors_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
48 changes: 0 additions & 48 deletions tests/path_gateway_unixfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a886c55

Please sign in to comment.