Skip to content

Commit

Permalink
sharness: eliminate netcat
Browse files Browse the repository at this point in the history
Differences between bsd-netcat and gnu-netcat make it horrible tool

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu committed Mar 5, 2019
1 parent dc6423f commit 54b1969
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
6 changes: 3 additions & 3 deletions test/sharness/t0060-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0061-daemon-opts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
Expand Down
16 changes: 7 additions & 9 deletions test/sharness/t0184-http-proxy-over-p2p.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions test/sharness/t0235-cli-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_inp >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 7<nc_outp
while ! nc -z 127.0.0.1 5005; do
go-sleep 100ms
done
socat /dev/null tcp:127.0.01:5005,retry=10
'

test_expect_success "can make http request against nc server" '
Expand Down
6 changes: 2 additions & 4 deletions test/sharness/t0236-cli-api-dns-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 5006 <nc_inp >nc_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<nc_outp
while ! nc -z 127.0.0.1 5006; do
go-sleep 100ms
done
socat /dev/null tcp:127.0.01:5006,retry=10
'

test_expect_success "can make http request against dns resolved nc server" '
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0301-docker-migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test_expect_success "setup http response" '
'

pretend_server() {
cat vers_resp | nc -l -i 1 -p 17233
socat tcp-listen:17233,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat cers_resp'!!STDERR &
}

test_expect_success "startup fake dists server" '
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0600-issues-and-regressions-online.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ test_expect_success "pin add api looks right - #3753" '
'

test_expect_success "no daemon crash on improper file argument - #4003" '
FNC=$(echo $API_ADDR | awk -F: '\''{ printf "%s %s", $1, $2 }'\'') &&
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"
FNC=$(echo $API_ADDR | awk -F: '\''{ printf "%s:%s", $1, $2 }'\'') &&
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"
'

test_kill_ipfs_daemon
Expand Down

0 comments on commit 54b1969

Please sign in to comment.