[http_proxy_over_p2p] url-decode the proxy name and fix test
License: MIT Signed-off-by: Chris Boddy <chris@boddy.im>
Chris Boddy committed
Oct 24, 2018 at 09:00 UTC
3f6b866edca6368cd1fb5edde6778596d6aca38e
2 files changed
+31
-17
core/corehttp/proxy.go
+6
-1
@@ -57,8 +57,13 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {
57
if len(split) < 6 {
58
return nil, fmt.Errorf("Invalid request path '%s'", path)
59
}
60
+ //url-decode the name
61
+ decodedName, err := url.PathUnescape(split[4])
62
+ if err != nil {
63
+ return nil, err
64
+ }
65
61
- return &proxyRequest{split[3], protocol.ID(split[4]), split[5]}, nil
66
+ return &proxyRequest{split[3], protocol.ID(decodedName), split[5]}, nil
67
}
68
69
func handleError(w http.ResponseWriter, msg string, err error, code int) {
test/sharness/t0184-http-proxy-over-p2p.sh
+25
-16
@@ -5,26 +5,41 @@ test_description="Test http proxy over p2p"
5
. lib/test-lib.sh
6
WEB_SERVE_PORT=5099
7
8
+function show_logs() {
9
+
10
+ echo "*****************"
11
+ echo " RECEIVER LOG "
12
+ echo "*****************"
13
+ cat $RECEIVER_LOG
14
+ echo "*****************"
15
+ echo " SENDER LOG "
16
+ echo "*****************"
17
+ cat $SENDER_LOG
18
+ echo "*****************"
19
+ echo "REMOTE_SERVER LOG"
20
+ echo $REMOTE_SERVER_LOG
21
+ echo "*****************"
22
+ cat $REMOTE_SERVER_LOG
23
+}
24
+
25
function serve_http_once() {
26
#
27
# one shot http server (via nc) with static body
28
#
29
local body=$1
30
local status_code=${2:-"200 OK"}
14
- local length=$(expr 1 + ${#body})
31
+ local length=$((1 + ${#body}))
32
REMOTE_SERVER_LOG=$(mktemp)
16
- echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" | nc -l $WEB_SERVE_PORT > $REMOTE_SERVER_LOG &
33
+ echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" | nc -l $WEB_SERVE_PORT 2>&1 > $REMOTE_SERVER_LOG &
34
REMOTE_SERVER_PID=$!
35
}
36
20
-
37
function setup_receiver_ipfs() {
38
#
39
# setup RECEIVER IPFS daemon
40
#
41
local IPFS_PATH=$(mktemp -d)
42
RECEIVER_LOG=$IPFS_PATH/ipfs.log
27
-
43
ipfs init >> $RECEIVER_LOG 2>&1
44
ipfs config --json Experimental.Libp2pStreamMounting true >> $RECEIVER_LOG 2>&1
45
ipfs config --json Addresses.API "\"/ip4/127.0.0.1/tcp/6001\"" >> $RECEIVER_LOG 2>&1
@@ -34,7 +49,7 @@ function setup_receiver_ipfs() {
49
RECEIVER_PID=$!
50
# wait for daemon to start.. maybe?
51
# ipfs id returns empty string if we don't wait here..
37
- sleep 5
52
+ sleep 10
53
RECEIVER_ID=$(ipfs id -f "<id>")
54
#
55
# start a p2p listener on RECIVER to the HTTP server with our content
@@ -54,7 +69,7 @@ function setup_sender_ipfs() {
69
ipfs config --json Experimental.P2pHttpProxy true >> $RECEIVER_LOG 2>&1
70
ipfs daemon >> $SENDER_LOG 2>&1 &
71
SENDER_PID=$!
57
- sleep 5
72
+ sleep 10
73
}
74
75
function setup_sender_and_receiver_ipfs() {
@@ -125,7 +140,7 @@ function curl_send_multipart_form_request() {
140
#
141
# send multipart form request
142
#
128
- STATUS_CODE=$(curl -s -F file=@$FILE_PATH http://localhost:5001/proxy/http/$RECEIVER_ID/test/index.txt)
143
+ STATUS_CODE=$(curl -v -F file=@$FILE_PATH http://localhost:5001/proxy/http/$RECEIVER_ID/test/index.txt)
144
#
145
# check status code
146
#
@@ -140,14 +155,7 @@ function curl_send_multipart_form_request() {
155
if ! grep "POST /index.txt" $REMOTE_SERVER_LOG > /dev/null;
156
then
157
echo "Remote server request method/resource path was incorrect"
143
- return 1
144
- fi
145
- #
146
- # check content received
147
- #
148
- if ! grep "$FILE_CONTENT" $REMOTE_SERVER_LOG > /dev/null;
149
- then
150
- echo "form-data-content was not correct"
158
+ show_logs
159
return 1
160
fi
161
#
@@ -156,12 +164,12 @@ function curl_send_multipart_form_request() {
164
if ! grep "Content-Type: multipart/form-data;" $REMOTE_SERVER_LOG > /dev/null;
165
then
166
echo "Request content-type was not multipart/form-data"
167
+ show_logs
168
return 1
169
fi
170
return 0
171
}
172
164
-teardown_sender_and_receiver
173
test_expect_success 'handle proxy http request propogates error response from remote' '
174
serve_http_once "SORRY GUYS, I LOST IT" "404 Not Found" &&
175
setup_sender_and_receiver_ipfs &&
@@ -182,6 +190,7 @@ serve_http_once "THE WOODS ARE LOVELY DARK AND DEEP" &&
190
curl_send_proxy_request_and_check_response 200 "THE WOODS ARE LOVELY DARK AND DEEP"
191
'
192
teardown_sender_and_receiver
193
+teardown_remote_server
194
195
test_expect_success 'handle proxy http request invalid request' '
196
setup_sender_and_receiver_ipfs &&