mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
sharness: eliminate netcat
Differences between bsd-netcat and gnu-netcat make it horrible tool License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
dc6423f7de
commit
54b1969c4b
@ -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
|
||||
|
||||
@ -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
|
||||
'
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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" '
|
||||
|
||||
@ -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" '
|
||||
|
||||
@ -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" '
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user