-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(gw): improve CORS tests #8718
Conversation
' | ||
# OPTIONS Response from the API should NOT contain CORS headers | ||
test_expect_success "OPTIONS response for API looks good" ' | ||
test_expect_success "OPTIONS response from {gw}/api/v0 has no CORS header" ' | ||
cat curl_output && | ||
grep -q "Access-Control-Allow-" curl_output && false || true | ||
' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests for the examples you have provided here : #7667
# HTTP OPTIONS Request
test_expect_success "OPTIONS to {gw}/api/v0 succeeds" '
curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" 2>curl_output
'
# OPTIONS Response from the API should NOT contain CORS headers
test_expect_success "OPTIONS response from {gw}/api/v0 has no CORS header" '
cat curl_output &&
grep -q "Access-Control-Allow-" curl_output && false || true
'
test_kill_ipfs_daemon
# Test CORS safelisting of standard headers
test_expect_success "Can configure standard CORS headers" '
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Headers "[\"Content-Disposition\"]" &&
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"https://example.com\"]" &&
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"POST\"]"
'
test_launch_ipfs_daemon
# HTTP OPTIONS POST Request
test_expect_success "OPTIONS to {gw}/api/v0 CORS headers" '
curl -svX OPTIONS -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: Content-Disposition" -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" 2>curl_output
'
# OPTIONS POST Response from the API should contain custom CORS headers
test_expect_success "OPTIONS response from {gw}/api/v0 has custom CORS header" '
test_expect_code 1 grep "< Access-Control-Allow-Headers: Content-Disposition" curl_output
'
# OPTIONS POST Response from the API should contain default CORS headers
test_expect_success "OPTIONS response from {gw}/api/v0 has default CORS headers " '
grep "< Access-Control-Allow-Methods: POST" curl_output &&
grep "< Access-Control-Allow-Origin: https://example.com" curl_output
'
test/sharness/t0112-gateway-cors.sh
Outdated
grep "< Access-Control-Allow-Origin: localhost" curl_output | ||
' | ||
|
||
# Read-Only API (at the Gateway Port) | ||
# Read-Only /api/v0 RPC API (exposed on the Gateway Port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_expect_success "OPTIONS to RPC API (exposed on the Gateway Port) with a custom header succeeds" '
curl -svX OPTIONS -H "Origin: https://example.com" -H "Access-Control-Request-Headers: Content-Disposition" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?args=$thash" 2>curl_output &&
cat curl_output
'
test_expect_success "Access-Control-Allow-Headers extends the previous implicit list" '
test_expect_code 1 grep "< Access-Control-Allow-Headers: Content-Disposition" curl_output
'
c413030
to
81e2477
Compare
I've rebased this to get more confidence around CORS behavior ( Thank you for submitting tests in comments, they will be useful when someone has time for #7667 |
81e2477
to
a08fffc
Compare
a08fffc
to
f2fd841
Compare
This cleans up old CORS tests and adds more resolution (proper Origin test, testing custom header behavior) It also adds basic regression tests for /api/v0 subset exposed on Gateway port.
f2fd841
to
7b01368
Compare
This PR cleans up old CORS tests and adds more resolution:
CORS on API port: fix CORS preflight requests to RPC API with custom headers #7667