From 54b1969c4b423436f184fc99e92e80e2f6fd9e43 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Sun, 3 Mar 2019 23:46:36 +0100 Subject: [PATCH] sharness: eliminate netcat Differences between bsd-netcat and gnu-netcat make it horrible tool License: MIT Signed-off-by: Jakub Sztandera --- test/sharness/t0060-daemon.sh | 6 +++--- test/sharness/t0061-daemon-opts.sh | 4 ++-- test/sharness/t0184-http-proxy-over-p2p.sh | 16 +++++++--------- test/sharness/t0235-cli-request.sh | 6 ++---- test/sharness/t0236-cli-api-dns-resolve.sh | 6 ++---- test/sharness/t0301-docker-migrate.sh | 2 +- .../t0600-issues-and-regressions-online.sh | 4 ++-- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index a33acb1eb..3a5910891 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -82,13 +82,13 @@ test_expect_success "ipfs help output looks good" ' ' # netcat (nc) is needed for the following test -test_expect_success "nc is available" ' - type nc >/dev/null +test_expect_success "socat is available" ' + type socat >/dev/null ' # check transport is encrypted test_expect_success "transport should be encrypted" ' - nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls && + socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls && grep -q "/secio" swarmnc && test_must_fail grep -q "/plaintext/1.0.0" swarmnc || test_fsh cat swarmnc diff --git a/test/sharness/t0061-daemon-opts.sh b/test/sharness/t0061-daemon-opts.sh index 78f711e26..227d4fa30 100755 --- a/test/sharness/t0061-daemon-opts.sh +++ b/test/sharness/t0061-daemon-opts.sh @@ -18,8 +18,8 @@ apiaddr=$API_ADDR # Odd. this fails here, but the inverse works on t0060-daemon. test_expect_success 'transport should be unencrypted' ' - nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls && - test_must_fail grep -q "/secio" swarmnc && + socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls && + grep -q -v "/secio" swarmnc && grep -q "/plaintext" swarmnc || test_fsh cat swarmnc ' diff --git a/test/sharness/t0184-http-proxy-over-p2p.sh b/test/sharness/t0184-http-proxy-over-p2p.sh index 15de5eac1..d647273f0 100755 --- a/test/sharness/t0184-http-proxy-over-p2p.sh +++ b/test/sharness/t0184-http-proxy-over-p2p.sh @@ -26,17 +26,14 @@ function show_logs() { function start_http_server() { REMOTE_SERVER_LOG="server.log" - rm -f $REMOTE_SERVER_LOG server_stdin + rm -f $REMOTE_SERVER_LOG - mkfifo server_stdin - nc -k -l 127.0.0.1 $WEB_SERVE_PORT 2>&1 > $REMOTE_SERVER_LOG < server_stdin & + touch response + socat tcp-listen:$WEB_SERVE_PORT,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat response'!!CREATE:$REMOTE_SERVER_LOG & REMOTE_SERVER_PID=$! - exec 7>server_stdin - rm server_stdin - while ! nc -z 127.0.0.1 $WEB_SERVE_PORT; do - go-sleep 100ms - done + socat /dev/null tcp:127.0.01:$WEB_SERVE_PORT,retry=10 + return $? } function teardown_remote_server() { @@ -49,7 +46,7 @@ function serve_content() { local body=$1 local status_code=${2:-"200 OK"} local length=$((1 + ${#body})) - echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" >&7 + echo -e "HTTP/1.1 $status_code\nContent-length: $length\n\n$body" > response } function curl_check_response_code() { @@ -82,6 +79,7 @@ function curl_send_proxy_request_and_check_response() { if [[ "$STATUS_CODE" -ne "$expected_status_code" ]]; then echo -e "Found status-code "$STATUS_CODE", expected "$expected_status_code + show_logs return 1 fi diff --git a/test/sharness/t0235-cli-request.sh b/test/sharness/t0235-cli-request.sh index 1c9e6151d..24bccd4d5 100755 --- a/test/sharness/t0235-cli-request.sh +++ b/test/sharness/t0235-cli-request.sh @@ -13,14 +13,12 @@ test_init_ipfs test_expect_success "start nc" ' rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp - nc -k -l 127.0.0.1 5005 nc_outp & + socat PIPE:nc_inp!!PIPE:nc_outp tcp-listen:5005,fork,max-children=1,bind=127.0.0.1 & NCPID=$! exec 6>nc_inp 7nc_outp & + socat PIPE:nc_inp!!PIPE:nc_outp tcp-listen:5006,fork,max-children=1,bind=127.0.0.1 & NCPID=$! exec 6>nc_inp 7