diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 56321f21..caffbc9f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,7 @@ on: [pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: install test dependencies run: | diff --git a/test/Makefile b/test/Makefile index f7df3e92..ece7b56f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -37,17 +37,22 @@ $(footloose): rm -f .ssh/identity ssh-keygen -t $(KEY_TYPE) -b $(KEY_SIZE) -f .ssh/identity -N $(KEY_PASSPHRASE) +.PHONY: docker-network +docker-network: + docker network inspect footloose-cluster || docker network create footloose-cluster --subnet 172.16.86.0/24 --gateway 172.16.86.1 --attachable + footloose.yaml: .ssh/identity $(footloose) $(footloose) config create \ --config footloose.yaml \ --image quay.io/footloose/ubuntu18.04 \ --name rigtest \ --key .ssh/identity \ - --replicas $(REPLICAS) \ - --override + --networks footloose-cluster \ + --override \ + --replicas $(REPLICAS) .PHONY: create-host -create-host: footloose.yaml +create-host: footloose.yaml docker-network $(footloose) create -c footloose.yaml .PHONY: delete-host @@ -58,6 +63,7 @@ delete-host: footloose.yaml clean: delete-host rm -f footloose.yaml identity rigtest rm -rf .ssh + docker network rm footloose-cluster || true .PHONY: sshport sshport: diff --git a/test/test.sh b/test/test.sh index b3f40055..f7942498 100755 --- a/test/test.sh +++ b/test/test.sh @@ -10,6 +10,26 @@ ssh_port() { footloose show $1 -o json|grep hostPort|grep -oE "[0-9]+" } +sanity_check() { + color_echo "- Testing footloose machine connection" + make create-host + echo "* Footloose status" + footloose status + echo "* Docker ps" + docker ps + echo "* SSH port: $(ssh_port node0)" + echo "* Testing stock ssh" + ssh -vvv -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i .ssh/identity -p $(ssh_port node0) root@127.0.0.1 echo "test-conn" + set +e + echo "* Testing footloose ssh" + footloose ssh root@node0 echo test-conn | grep -q test-conn + local exit_code=$? + set -e + make clean + return $exit_code +} + + rig_test_agent_with_public_key() { color_echo "- Testing connection using agent and providing a path to public key" make create-host @@ -28,12 +48,12 @@ rig_test_agent_with_public_key() { rig_test_agent_with_private_key() { color_echo "- Testing connection using agent and providing a path to protected private key" - make create-host KEY_PASSPHRASE=foo + make create-host KEY_PASSPHRASE=testPhrase eval $(ssh-agent -s) expect -c ' spawn ssh-add .ssh/identity expect "?:" - send "foo\n" + send "testPhrase\n" expect eof" ' set +e @@ -90,7 +110,7 @@ rig_test_key_from_path() { rig_test_protected_key_from_path() { color_echo "- Testing regular keypath to encrypted key, two hosts" - make create-host KEY_PASSPHRASE=foo REPLICAS=2 + make create-host KEY_PASSPHRASE=testPhrase REPLICAS=2 set +e ssh_port node0 > .ssh/port_A ssh_port node1 > .ssh/port_B @@ -105,7 +125,7 @@ rig_test_protected_key_from_path() { spawn ./rigtest -host 127.0.0.1:$PORTA,127.0.0.1:$PORTB -user root -keypath .ssh/identity -askpass true expect "Password:" - send "foo\n" + send "testPhrase\n" expect eof" ' $port1 $port2 local exit_code=$? @@ -113,6 +133,11 @@ rig_test_protected_key_from_path() { return $exit_code } +if ! sanity_check; then + echo "Sanity check failed" + exit 1 +fi + for test in $(declare -F|grep rig_test_|cut -d" " -f3); do if [ "$FOCUS" != "" ] && [ "$FOCUS" != "$test" ]; then continue