Use nc6 in MSP tests instead of nc

On OS-X (BSD), nc6 appears to be the only available variant of
netcat that matches the Linux version.

Introduces a guard function to catch invocations of nc6 when
setup_netcat6 has not been called in the fixture.  Introduce
guard functions to prevent invocations of nc and netcat.
This commit is contained in:
Andrew Bettison 2016-02-15 17:18:36 +10:30
parent 2da3f12cfa
commit 3e4470bf4a
2 changed files with 41 additions and 6 deletions

View File

@ -903,7 +903,39 @@ setup_curl() {
;;
esac
fail "curl(1) version $2 is not adequate (expecting $minversion or higher)"
}
# Setup function:
# - ensure that the netcat6 nc6(1) utility is available
setup_netcat6() {
NETCAT6=$(type -P nc6) || error "nc6(1) command is not present"
local minversion="${1:-1.0}"
local ver="$("$NETCAT6" --version | tr '\n' ' ')"
case "$ver" in
nc6\ version\ *)
set -- $ver
tfw_cmp_version "$3" "$minversion"
case $? in
0|2)
export NETCAT6
return 0
;;
esac
error "$NETCAT6 version $3 is not adequate (expecting $minversion or higher)"
;;
esac
fail "cannot parse output of curl --version: $ver"
error "cannot parse output of $NETCAT6 --version: $ver"
}
# Guard functions.
NETCAT6=
nc6() {
[ -x "$NETCAT6" ] || error "missing call to setup_netcat6 in the fixture"
"$NETCAT6" "$@"
}
nc() {
error "do not use nc; instead use nc6(1) after calling setup_netcat6 in the fixture"
}
netcat() {
error "do not use netcat; instead use nc6(1) after calling setup_netcat6 in the fixture"
}

View File

@ -181,6 +181,7 @@ test_keep_alive() {
doc_forward="Forward TCP connections to a remote server"
setup_forward() {
setup_common
setup_netcat6
start_servald_instances +A +B
}
client_forward() {
@ -194,7 +195,7 @@ test_forward() {
set_instance +B
fork %connect client_forward 2048 $SIDA
sleep 1
executeOk nc -q 30 -v 127.0.0.1 2048 < <(echo "Hello from the client")
executeOk nc6 -q 30 -v 127.0.0.1 2048 < <(echo "Hello from the client")
assertStdoutGrep --matches=1 "^Hello from the server$"
fork_wait %listen %connect
}
@ -202,6 +203,7 @@ test_forward() {
doc_tcp_tunnel="Tunnel a tcp connection"
setup_tcp_tunnel() {
setup_common
setup_netcat6
start_servald_instances +A +B
}
server_forward() {
@ -210,7 +212,7 @@ server_forward() {
tfw_cat --stderr
}
nc_listen() {
execute nc -q -1 -v -l -p $1 < <(echo "Hello from the server")
execute nc6 -q -1 -v -l -p $1 < <(echo "Hello from the server")
tfw_cat --stdout --stderr
}
test_tcp_tunnel() {
@ -220,7 +222,7 @@ test_tcp_tunnel() {
set_instance +B
fork %client client_forward 6001 $SIDA
sleep 1
executeOk nc -q 10 -v 127.0.0.1 6001 < <(echo "Hello from the client")
executeOk nc6 -q 10 -v 127.0.0.1 6001 < <(echo "Hello from the client")
tfw_cat --stdout --stderr
assertStdoutGrep --matches=1 "^Hello from the server$"
fork_wait %listen %server %client
@ -285,6 +287,7 @@ test_refused(){
doc_terminate="Terminate a connection mid stream"
setup_terminate() {
setup_common
setup_netcat6
start_servald_instances +A +B
}
client_terminate() {
@ -303,8 +306,8 @@ test_terminate() {
set_instance +B
fork %mspconnect client_terminate
sleep 1
# todo capture nc output nicely, while still being able to terminate it
fork %ncconnect nc -q 0 -v 127.0.0.1 3001
# todo capture nc6 output nicely, while still being able to terminate it
fork %ncconnect nc6 -q 0 -v 127.0.0.1 3001
fork_terminate %ncconnect
fork_wait %msplisten %mspconnect %ncconnect
}