Skip to content

Commit

Permalink
fix: restore t0112
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Jun 30, 2023
1 parent a692dc4 commit d0b13ac
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/sharness/t0112-gateway-cors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,59 @@ EOF
test_cmp expected actual
'

test_launch_ipfs_daemon

thash='bafkqabtimvwgy3yk' # hello

test_launch_ipfs_daemon
# Gateway

# HTTP GET Request
test_expect_success "GET to Gateway succeeds" '
curl -svX GET -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" >/dev/null 2>curl_output &&
cat curl_output
'

# GET Response from Gateway should contain CORS headers
test_expect_success "GET response for Gateway resource looks good" '
test_should_contain "< Access-Control-Allow-Origin: \*" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: GET" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: Range" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output
'
# HTTP OPTIONS Request
test_expect_success "OPTIONS to Gateway succeeds" '
curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output &&
cat curl_output
'

# OPTION Response from Gateway should contain CORS headers
test_expect_success "OPTIONS response for Gateway resource looks good" '
test_should_contain "< Access-Control-Allow-Origin: \*" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: GET" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output &&
test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: Range" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output &&
test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output &&
test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output
'

# HTTP OPTIONS Request on path → subdomain HTTP 301 redirect
# (regression test for https://github.com/ipfs/kubo/issues/9983#issuecomment-1599673976)
test_expect_success "OPTIONS to Gateway succeeds" '
Expand Down

0 comments on commit d0b13ac

Please sign in to comment.