sharness: eliminate netcat
Differences between bsd-netcat and gnu-netcat make it horrible tool License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Mar 3, 2019 at 23:46 UTC
54b1969c4b423436f184fc99e92e80e2f6fd9e43
7 files changed
+19
-25
test/sharness/t0060-daemon.sh
+3
-3
@@ -82,13 +82,13 @@ test_expect_success "ipfs help output looks good" '
82
'
83
84
# netcat (nc) is needed for the following test
85
-test_expect_success "nc is available" '
86
- type nc >/dev/null
85
+test_expect_success "socat is available" '
86
+ type socat >/dev/null
87
'
88
89
# check transport is encrypted
90
test_expect_success "transport should be encrypted" '
91
- nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls &&
91
+ socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls &&
92
grep -q "/secio" swarmnc &&
93
test_must_fail grep -q "/plaintext/1.0.0" swarmnc ||
94
test_fsh cat swarmnc
test/sharness/t0061-daemon-opts.sh
+2
-2
@@ -18,8 +18,8 @@ apiaddr=$API_ADDR
18
19
# Odd. this fails here, but the inverse works on t0060-daemon.
20
test_expect_success 'transport should be unencrypted' '
21
- nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls &&
22
- test_must_fail grep -q "/secio" swarmnc &&
21
+ socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls &&
22
+ grep -q -v "/secio" swarmnc &&
23
grep -q "/plaintext" swarmnc ||
24
test_fsh cat swarmnc
25
'
test/sharness/t0184-http-proxy-over-p2p.sh
+7
-9
@@ -26,17 +26,14 @@ function show_logs() {
26
27
function start_http_server() {
28
REMOTE_SERVER_LOG="server.log"
29
- rm -f $REMOTE_SERVER_LOG server_stdin
29
+ rm -f $REMOTE_SERVER_LOG
30
31
- mkfifo server_stdin
32
- nc -k -l 127.0.0.1 $WEB_SERVE_PORT 2>&1 > $REMOTE_SERVER_LOG < server_stdin &
31
+ touch response
32
+ socat tcp-listen:$WEB_SERVE_PORT,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat response'!!CREATE:$REMOTE_SERVER_LOG &
33
REMOTE_SERVER_PID=$!
34
- exec 7>server_stdin
35
- rm server_stdin
34
37
- while ! nc -z 127.0.0.1 $WEB_SERVE_PORT; do
38
- go-sleep 100ms
39
- done
35
+ socat /dev/null tcp:127.0.01:$WEB_SERVE_PORT,retry=10
36
+ return $?
37
}
38
39
function teardown_remote_server() {
@@ -49,7 +46,7 @@ function serve_content() {
46
local body=$1
47
local status_code=${2:-"200 OK"}
48
local length=$((1 + ${#body}))
52
- echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" >&7
49
+ echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" > response
50
}
51
52
function curl_check_response_code() {
@@ -82,6 +79,7 @@ function curl_send_proxy_request_and_check_response() {
79
if [[ "$STATUS_CODE" -ne "$expected_status_code" ]];
80
then
81
echo -e "Found status-code "$STATUS_CODE", expected "$expected_status_code
82
+ show_logs
83
return 1
84
fi
85
test/sharness/t0235-cli-request.sh
+2
-4
@@ -13,14 +13,12 @@ test_init_ipfs
13
test_expect_success "start nc" '
14
rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
15
16
- nc -k -l 127.0.0.1 5005 <nc_inp >nc_outp &
16
+ socat PIPE:nc_inp!!PIPE:nc_outp tcp-listen:5005,fork,max-children=1,bind=127.0.0.1 &
17
NCPID=$!
18
19
exec 6>nc_inp 7<nc_outp
20
21
- while ! nc -z 127.0.0.1 5005; do
22
- go-sleep 100ms
23
- done
21
+ socat /dev/null tcp:127.0.01:5005,retry=10
22
'
23
24
test_expect_success "can make http request against nc server" '
test/sharness/t0236-cli-api-dns-resolve.sh
+2
-4
@@ -13,14 +13,12 @@ test_init_ipfs
13
test_expect_success "start nc" '
14
rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
15
16
- nc -k -l 127.0.0.1 5006 <nc_inp >nc_outp &
16
+ socat PIPE:nc_inp!!PIPE:nc_outp tcp-listen:5006,fork,max-children=1,bind=127.0.0.1 &
17
NCPID=$!
18
19
exec 6>nc_inp 7<nc_outp
20
21
- while ! nc -z 127.0.0.1 5006; do
22
- go-sleep 100ms
23
- done
21
+ socat /dev/null tcp:127.0.01:5006,retry=10
22
'
23
24
test_expect_success "can make http request against dns resolved nc server" '
test/sharness/t0301-docker-migrate.sh
+1
-1
@@ -39,7 +39,7 @@ test_expect_success "setup http response" '
39
'
40
41
pretend_server() {
42
- cat vers_resp | nc -l -i 1 -p 17233
42
+ socat tcp-listen:17233,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat cers_resp'!!STDERR &
43
}
44
45
test_expect_success "startup fake dists server" '
test/sharness/t0600-issues-and-regressions-online.sh
+2
-2
@@ -47,8 +47,8 @@ test_expect_success "pin add api looks right - #3753" '
47
'
48
49
test_expect_success "no daemon crash on improper file argument - #4003" '
50
- FNC=$(echo $API_ADDR | awk -F: '\''{ printf "%s %s", $1, $2 }'\'') &&
51
- printf "POST /api/v0/add?pin=true HTTP/1.1\r\nHost: $API_ADDR\r\nContent-Type: multipart/form-data; boundary=Pyw9xQLtiLPE6XcI\r\nContent-Length: 22\r\n\r\n\r\n--Pyw9xQLtiLPE6XcI\r\n" | nc -v $FNC | grep -m1 "500 Internal Server Error"
50
+ FNC=$(echo $API_ADDR | awk -F: '\''{ printf "%s:%s", $1, $2 }'\'') &&
51
+ printf "POST /api/v0/add?pin=true HTTP/1.1\r\nHost: $API_ADDR\r\nContent-Type: multipart/form-data; boundary=Pyw9xQLtiLPE6XcI\r\nContent-Length: 22\r\n\r\n\r\n--Pyw9xQLtiLPE6XcI\r\n" | socat STDIO tcp-connect:$FNC | grep -m1 "500 Internal Server Error"
52
'
53
54
test_kill_ipfs_daemon