@@ -18,41 +18,70 @@ test_init_ipfs
18
18
test_config_ipfs_cors_headers
19
19
test_launch_ipfs_daemon
20
20
21
- gwport=$GWAY_PORT
22
- apiport=$API_PORT
23
21
thash=' QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
24
22
25
23
# Gateway
26
24
27
25
# HTTP GET Request
28
26
test_expect_success " GET to Gateway succeeds" '
29
- curl -svX GET "http://127.0.0.1:$gwport/ipfs/$thash" 2>curl_output
27
+ curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" >/dev/null 2>curl_output &&
28
+ cat curl_output
30
29
'
31
30
32
- cat curl_output
33
31
# GET Response from Gateway should contain CORS headers
34
32
test_expect_success " GET response for Gateway resource looks good" '
35
- grep "Access-Control-Allow-Origin:" curl_output | grep "\*" &&
36
- grep "Access-Control-Allow-Methods:" curl_output | grep " GET\b" &&
37
- grep "Access-Control-Allow-Headers:" curl_output
33
+ grep "< Access-Control-Allow-Origin: \*" curl_output &&
34
+ grep "< Access-Control-Allow-Methods: GET" curl_output &&
35
+ grep "< Access-Control-Allow-Headers: Range" curl_output &&
36
+ grep "< Access-Control-Expose-Headers: Content-Range" curl_output
38
37
'
39
38
40
39
# HTTP OPTIONS Request
41
40
test_expect_success " OPTIONS to Gateway succeeds" '
42
- curl -svX OPTIONS "http://127.0.0.1:$gwport/ipfs/$thash" 2>curl_output
41
+ curl -svX OPTIONS "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output &&
42
+ cat curl_output
43
43
'
44
+
44
45
# OPTION Response from Gateway should contain CORS headers
45
46
test_expect_success " OPTIONS response for Gateway resource looks good" '
46
- grep "Access-Control-Allow-Origin:" curl_output | grep "\*" &&
47
- grep "Access-Control-Allow-Methods:" curl_output | grep " GET\b" &&
48
- grep "Access-Control-Allow-Headers:" curl_output
47
+ grep "< Access-Control-Allow-Origin: \*" curl_output &&
48
+ grep "< Access-Control-Allow-Methods: GET" curl_output &&
49
+ grep "< Access-Control-Allow-Headers: Range" curl_output &&
50
+ grep "< Access-Control-Expose-Headers: Content-Range" curl_output
51
+ '
52
+
53
+ test_kill_ipfs_daemon
54
+
55
+ # Change headers
56
+ test_expect_success " Can configure gateway headers" '
57
+ ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Headers "[\"X-Custom1\"]" &&
58
+ ipfs config --json Gateway.HTTPHeaders.Access-Control-Expose-Headers "[\"X-Custom2\"]" &&
59
+ ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin "[\"localhost\"]"
60
+ '
61
+
62
+ test_launch_ipfs_daemon
63
+
64
+ test_expect_success " OPTIONS to Gateway succeeds" '
65
+ curl -svX OPTIONS "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output &&
66
+ cat curl_output
67
+ '
68
+
69
+ test_expect_success " Access-Control-Allow-Headers extends" '
70
+ grep "< Access-Control-Allow-Headers: Range" curl_output &&
71
+ grep "< Access-Control-Allow-Headers: X-Custom1" curl_output &&
72
+ grep "< Access-Control-Expose-Headers: Content-Range" curl_output &&
73
+ grep "< Access-Control-Expose-Headers: X-Custom2" curl_output
74
+ '
75
+
76
+ test_expect_success " Access-Control-Allow-Origin replaces" '
77
+ grep "< Access-Control-Allow-Origin: localhost" curl_output
49
78
'
50
79
51
80
# Read-Only API (at the Gateway Port)
52
81
53
82
# HTTP GET Request
54
83
test_expect_success " GET to API succeeds" '
55
- curl -svX GET "http://127.0.0.1:$gwport /api/v0/cat?arg=$thash" 2>curl_output
84
+ curl -svX GET "http://127.0.0.1:$GWAY_PORT /api/v0/cat?arg=$thash" >/dev/null 2>curl_output
56
85
'
57
86
# GET Response from the API should NOT contain CORS headers
58
87
# Blacklisting: https://git.io/vzaj2
@@ -63,7 +92,7 @@ test_expect_success "OPTIONS response for API looks good" '
63
92
64
93
# HTTP OPTIONS Request
65
94
test_expect_success " OPTIONS to API succeeds" '
66
- curl -svX OPTIONS "http://127.0.0.1:$gwport /api/v0/cat?arg=$thash" 2>curl_output
95
+ curl -svX OPTIONS "http://127.0.0.1:$GWAY_PORT /api/v0/cat?arg=$thash" 2>curl_output
67
96
'
68
97
# OPTIONS Response from the API should NOT contain CORS headers
69
98
test_expect_success " OPTIONS response for API looks good" '
0 commit comments