@cryptotaxi247 / kubo / commits / d8cab7998

update tests

License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Nov 12, 2018 at 16:10 UTC d8cab7998ed258d357fcd4b9d545d5b090bc4905
1 file changed +15 -13
test/sharness/t0184-http-proxy-over-p2p.sh
+15 -13
@@ -4,6 +4,8 @@ test_description="Test http proxy over p2p"
4
5 . lib/test-lib.sh
6 WEB_SERVE_PORT=5099
7 +IPFS_GATEWAY_PORT=5199
8 +SENDER_GATEWAY="http://127.0.0.1:$IPFS_GATEWAY_PORT"
9
10 function show_logs() {
11
@@ -41,8 +43,8 @@ function teardown_remote_server() {
43
44 function curl_check_response_code() {
45 local expected_status_code=$1
44 - local path_stub=${2:-http/$RECEIVER_ID/test/index.txt}
45 - local status_code=$(curl -s --write-out %{http_code} --output /dev/null $SENDER_URL/$path_stub)
46 + local path_stub=${2:-p2p/$RECEIVER_ID/http/index.txt}
47 + local status_code=$(curl -s --write-out %{http_code} --output /dev/null $SENDER_GATEWAY/$path_stub)
48
49 if [[ "$status_code" -ne "$expected_status_code" ]];
50 then
@@ -61,12 +63,12 @@ function curl_send_proxy_request_and_check_response() {
63 # make a request to SENDER_IPFS via the proxy endpoint
64 #
65 CONTENT_PATH="retrieved-file"
64 - STATUS_CODE=$(curl -s -o $CONTENT_PATH --write-out %{http_code} $SENDER_URL/$RECEIVER_ID/test/index.txt)
66 + STATUS_CODE="$(curl -s -o $CONTENT_PATH --write-out %{http_code} $SENDER_GATEWAY/p2p/$RECEIVER_ID/http/index.txt)"
67
68 #
69 # check status code
70 #
69 - if [[ $STATUS_CODE -ne $expected_status_code ]];
71 + if [[ "$STATUS_CODE" -ne "$expected_status_code" ]];
72 then
73 echo -e "Found status-code "$STATUS_CODE", expected "$expected_status_code
74 return 1
@@ -75,7 +77,7 @@ function curl_send_proxy_request_and_check_response() {
77 #
78 # check content
79 #
78 - RESPONSE_CONTENT=$(tail -n 1 $CONTENT_PATH)
80 + RESPONSE_CONTENT="$(tail -n 1 $CONTENT_PATH)"
81 if [[ "$RESPONSE_CONTENT" == "$expected_content" ]];
82 then
83 return 0
@@ -93,11 +95,11 @@ function curl_send_multipart_form_request() {
95 #
96 # send multipart form request
97 #
96 - STATUS_CODE=$(curl -v -F file=@$FILE_PATH $SENDER_URL/$RECEIVER_ID/test/index.txt)
98 + STATUS_CODE="$(curl -v -F file=@$FILE_PATH $SENDER_GATEWAY/p2p/$RECEIVER_ID/http/index.txt)"
99 #
100 # check status code
101 #
100 - if [[ $STATUS_CODE -ne $expected_status_code ]];
102 + if [[ "$STATUS_CODE" -ne "$expected_status_code" ]];
103 then
104 echo -e "Found status-code "$STATUS_CODE", expected "$expected_status_code
105 return 1
@@ -128,6 +130,7 @@ test_expect_success 'configure nodes' '
130 ipfsi 0 config --json Experimental.Libp2pStreamMounting true &&
131 ipfsi 1 config --json Experimental.Libp2pStreamMounting true &&
132 ipfsi 0 config --json Experimental.P2pHttpProxy true
133 + ipfsi 0 config --json Addresses.Gateway "[\"/ip4/127.0.0.1/tcp/$IPFS_GATEWAY_PORT\"]"
134 '
135
136 test_expect_success 'start and connect nodes' '
@@ -135,12 +138,11 @@ test_expect_success 'start and connect nodes' '
138 '
139
140 test_expect_success 'setup p2p listener on the receiver' '
138 - ipfsi 1 p2p listen --allow-custom-protocol test /ip4/127.0.0.1/tcp/$WEB_SERVE_PORT
141 + ipfsi 1 p2p listen --allow-custom-protocol /http /ip4/127.0.0.1/tcp/$WEB_SERVE_PORT
142 '
143
141 -test_expect_success 'setup environment variables' '
142 - RECEIVER_ID="$(iptb get id 1)" &&
143 - SENDER_URL="$(sed "s|^/ip[46]/\([^/]*\)/tcp/\([0-9]*\)\$|http://\\1:\\2/proxy/http|" < "$(iptb get path 0)/api")"
144 +test_expect_success 'setup environment' '
145 + RECEIVER_ID="$(iptb attr get 1 id)"
146 '
147
148 test_expect_success 'handle proxy http request propogates error response from remote' '
@@ -160,11 +162,11 @@ test_expect_success 'handle proxy http request ' '
162 teardown_remote_server
163
164 test_expect_success 'handle proxy http request invalid request' '
163 - curl_check_response_code 400 DERPDERPDERP
165 + curl_check_response_code 400 p2p/DERPDERPDERP
166 '
167
168 test_expect_success 'handle proxy http request unknown proxy peer ' '
167 - curl_check_response_code 502 unknown_peer/test/index.txt
169 + curl_check_response_code 502 p2p/unknown_peer/http/index.txt
170 '
171
172 test_expect_success 'handle multipart/form-data http request' '