Make docker-tests less verbose and easier to add new tests
parent
15602388f6
commit
8de1996a7a
|
@ -17,5 +17,5 @@ jobs:
|
|||
- name: Build the Docker images
|
||||
run: docker-tests/build-docker-images.sh
|
||||
- name: Run the Docker tests
|
||||
run: docker-tests/run-docker-tests.sh userspace
|
||||
run: docker-tests/run-docker-tests.sh --userspace --verbose
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
SELF_DIR="$(dirname "$0")"
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
cd "$SELF_DIR/.."
|
||||
|
||||
docker build -t innernet -f "$SELF_DIR/Dockerfile.innernet" .
|
||||
|
|
|
@ -2,29 +2,42 @@
|
|||
set -e
|
||||
shopt -s nocasematch
|
||||
|
||||
SELF_DIR="$(dirname "$0")"
|
||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
cd "$SELF_DIR/.."
|
||||
|
||||
if [[ $# -eq 1 ]]; then
|
||||
case "$1" in
|
||||
kernel)
|
||||
INNERNET_ARGS="-vvv"
|
||||
help() {
|
||||
cat >&2 <<-_EOF
|
||||
Usage: "${0##*/}" [options...] (<test>)
|
||||
--userspace Use userspace wireguard instead of kernel one
|
||||
--verbose Print verbose innernet logs
|
||||
_EOF
|
||||
}
|
||||
|
||||
TEST_FILTER=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--userspace)
|
||||
INNERNET_ARGS="$INNERNET_ARGS --backend userspace"
|
||||
shift
|
||||
;;
|
||||
userspace)
|
||||
INNERNET_ARGS="-vvv --backend userspace"
|
||||
--verbose)
|
||||
INNERNET_ARGS="$INNERNET_ARGS -vvv"
|
||||
CLIENT_ARGS="$CLIENT_ARGS --verbose"
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
help
|
||||
exit
|
||||
;;
|
||||
-*)
|
||||
echo "Invalid option."
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "invalid backend (must be kernel or userspace)"
|
||||
exit 1
|
||||
TEST_FILTER+=("$1")
|
||||
esac
|
||||
else
|
||||
cat >&2 <<-_EOF
|
||||
Usage: "${0##*/}" <BACKEND>
|
||||
|
||||
BACKEND: "kernel" or "userspace"
|
||||
_EOF
|
||||
exit
|
||||
fi
|
||||
done
|
||||
|
||||
cmd() {
|
||||
echo "[#] $*" >&2
|
||||
|
@ -63,17 +76,23 @@ info "server started as $SERVER_CONTAINER"
|
|||
info "Waiting for server to initialize."
|
||||
cmd sleep 5
|
||||
|
||||
create_peer_docker() {
|
||||
local IP=$1
|
||||
cmd docker create --rm -it \
|
||||
--network "$NETWORK" \
|
||||
--ip $IP \
|
||||
--volume /dev/net/tun:/dev/net/tun \
|
||||
--cap-add NET_ADMIN \
|
||||
--env RUST_LOG=trace \
|
||||
--env INTERFACE=evilcorp \
|
||||
--env INNERNET_ARGS="$INNERNET_ARGS" \
|
||||
--env CLIENT_ARGS="$CLIENT_ARGS" \
|
||||
innernet /app/start-client.sh
|
||||
}
|
||||
|
||||
info "Starting first peer."
|
||||
cmd docker cp "$SERVER_CONTAINER:/app/peer1.toml" "$tmp_dir"
|
||||
PEER1_CONTAINER=$(cmd docker create --rm -it \
|
||||
--network "$NETWORK" \
|
||||
--ip 172.18.1.2 \
|
||||
--volume /dev/net/tun:/dev/net/tun \
|
||||
--env INTERFACE=evilcorp \
|
||||
--env RUST_LOG=trace \
|
||||
--env INNERNET_ARGS="$INNERNET_ARGS" \
|
||||
--cap-add NET_ADMIN \
|
||||
innernet /app/start-client.sh)
|
||||
PEER1_CONTAINER=$(create_peer_docker 172.18.1.2)
|
||||
info "peer1 started as $PEER1_CONTAINER"
|
||||
cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml"
|
||||
cmd docker start -a "$PEER1_CONTAINER" | sed -e 's/^/\x1B[0;96mpeer 1\x1B[0m: /' &
|
||||
|
@ -106,19 +125,13 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
|||
cmd docker cp "$PEER1_CONTAINER:/app/peer2.toml" "$tmp_dir"
|
||||
|
||||
info "Starting second peer."
|
||||
PEER2_CONTAINER=$(docker create --rm -it \
|
||||
--network "$NETWORK" \
|
||||
--ip 172.18.1.3 \
|
||||
--volume /dev/net/tun:/dev/net/tun \
|
||||
--cap-add NET_ADMIN \
|
||||
--env INTERFACE=evilcorp \
|
||||
--env INNERNET_ARGS="$INNERNET_ARGS" \
|
||||
innernet /app/start-client.sh)
|
||||
PEER2_CONTAINER=$(create_peer_docker 172.18.1.3)
|
||||
info "peer2 started as $PEER2_CONTAINER"
|
||||
cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml"
|
||||
cmd docker start -a "$PEER2_CONTAINER" | sed -e 's/^/\x1B[0;93mpeer 2\x1B[0m: /' &
|
||||
sleep 10
|
||||
|
||||
test_short_lived_invitation() {
|
||||
info "Creating short-lived invitation for third peer."
|
||||
cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||
add-peer evilcorp \
|
||||
|
@ -143,12 +156,9 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
|||
--save-config "/app/peer3_2.toml" \
|
||||
--invite-expires "30m" \
|
||||
--yes
|
||||
}
|
||||
|
||||
info "peer2 started as $PEER2_CONTAINER"
|
||||
cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml"
|
||||
cmd docker start -a "$PEER2_CONTAINER" | sed -e 's/^/\x1B[0;93mpeer 2\x1B[0m: /' &
|
||||
sleep 10
|
||||
|
||||
test_simultaneous_redemption() {
|
||||
info "Creating invitation for fourth and fifth peer from first peer."
|
||||
cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||
add-peer evilcorp \
|
||||
|
@ -172,23 +182,9 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
|||
cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir"
|
||||
|
||||
info "Starting fourth and fifth peer and redeeming simultaneously."
|
||||
PEER4_CONTAINER=$(docker create --rm -it \
|
||||
--network "$NETWORK" \
|
||||
--ip 172.18.1.4 \
|
||||
--volume /dev/net/tun:/dev/net/tun \
|
||||
--cap-add NET_ADMIN \
|
||||
--env INTERFACE=evilcorp \
|
||||
--env INNERNET_ARGS="$INNERNET_ARGS" \
|
||||
innernet /app/start-client.sh)
|
||||
PEER4_CONTAINER=$(create_peer_docker 172.18.1.4)
|
||||
cmd docker cp "$tmp_dir/peer4.toml" "$PEER4_CONTAINER:/app/invite.toml"
|
||||
PEER5_CONTAINER=$(docker create --rm -it \
|
||||
--network "$NETWORK" \
|
||||
--ip 172.18.1.5 \
|
||||
--volume /dev/net/tun:/dev/net/tun \
|
||||
--cap-add NET_ADMIN \
|
||||
--env INTERFACE=evilcorp \
|
||||
--env INNERNET_ARGS="$INNERNET_ARGS" \
|
||||
innernet /app/start-client.sh)
|
||||
PEER5_CONTAINER=$(create_peer_docker 172.18.1.5)
|
||||
cmd docker cp "$tmp_dir/peer5.toml" "$PEER5_CONTAINER:/app/invite.toml"
|
||||
|
||||
cmd docker start -a "$PEER4_CONTAINER" | sed -e 's/^/\x1B[0;92mpeer 4\x1B[0m: /' &
|
||||
|
@ -199,6 +195,19 @@ info "peer5 started as $PEER5_CONTAINER"
|
|||
info "Checking connectivity betweeen peers."
|
||||
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1
|
||||
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1
|
||||
}
|
||||
|
||||
# Run tests (functions prefixed with test_) in alphabetical order.
|
||||
# Optional filter provided by positional arguments is applied.
|
||||
for func in $(declare -F | awk '{print $3}'); do
|
||||
echo '-'$func
|
||||
if [[ "$func" =~ ^test_ ]]; then
|
||||
echo '='$func
|
||||
if [ ${#TEST_FILTER[@]} -eq 0 ] || [[ "${TEST_FILTER[*]}" =~ "$func" ]]; then
|
||||
$func
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
info "test succeeded."
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
set -e
|
||||
|
||||
INTERFACE="${INTERFACE:-innernet}"
|
||||
|
||||
innernet $INNERNET_ARGS install \
|
||||
--name "$INTERFACE" \
|
||||
--delete-invite \
|
||||
|
@ -9,6 +10,10 @@ innernet $INNERNET_ARGS install \
|
|||
/app/invite.toml
|
||||
|
||||
while true; do
|
||||
if [[ $CLIENT_ARGS =~ --verbose ]]; then
|
||||
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE"
|
||||
else
|
||||
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE" > /dev/null
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue