From 93902ce8c0a8523f2cd28f758b1202e1efe01ba2 Mon Sep 17 00:00:00 2001 From: Justin Bastress Date: Fri, 8 Dec 2017 14:34:27 -0500 Subject: [PATCH] add test scripts --- test_mysql_all.sh | 10 ++++++++ test_mysql_version.sh | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test_mysql_all.sh create mode 100644 test_mysql_version.sh diff --git a/test_mysql_all.sh b/test_mysql_all.sh new file mode 100644 index 0000000..0c70f0f --- /dev/null +++ b/test_mysql_all.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# These are all of the versions supported by https://hub.docker.com/_/mysql/ +VERSIONS="5.5 5.6 5.7 8.0" + +# Unfortunately, the 5.5/5.6 containers do not have TLS support built in, so for now we are constrained to checking the version string + +for version in $VERSIONS; do + ./test_mysql_version.sh "$version" +done diff --git a/test_mysql_version.sh b/test_mysql_version.sh new file mode 100644 index 0000000..d179659 --- /dev/null +++ b/test_mysql_version.sh @@ -0,0 +1,57 @@ +#!/bin/bash +if [ "$#" -ne 1 ]; then + echo "Usage:" + echo "" + echo " $0 [version]" + echo "" + echo "[version] should be one of the supported tags listed at https://hub.docker.com/_/mysql/" + echo "" + echo "Example:" + echo "" + echo " $0 5.5" + echo "" + exit 1 +fi + +SQL_VERSION="$1" +CONTAINER_NAME="testmysql-$SQL_VERSION" +OUTPUT_FILE="out-$SQL_VERSION.json" + +echo "Starting the mysql $SQL_VERSION container (forwarding localhost:3306 -> container:3306)..." +set -x +if ! docker run -itd -p 3306:3306 --rm --name $CONTAINER_NAME -e MYSQL_ROOT_PASSWORD=rootPassword mysql:$SQL_VERSION; then + echo "Error running mysql:$SQL_VERSION docker instance: $?" + exit 1 +fi +set +x + +function cleanup { + echo "Stopping $CONTAINER_NAME..." + docker stop $CONTAINER_NAME + echo "Stopped." +} + +trap cleanup EXIT + +set +e + +pushd cmd/zgrab2 +go build -o ../../zgrab2 +popd + +echo "Waiting for port 3306 to come up..." +while ! (netstat -n -a | grep 3306 | grep LISTENING > /dev/null); do sleep 1; done +# 5s seems to work more than half the time on my laptop, 10s seems to work all the time +sleep 10 + +set -x +echo "127.0.0.1" | ./zgrab2 mysql $* > $OUTPUT_FILE +set +x +SERVER_VERSION=$(jp data.mysql.result.handshake.parsed.server_version < $OUTPUT_FILE) + +if [[ "$SERVER_VERSION" =~ "$SQL_VERSION\..*" ]]; then + echo "Server version matches expected version: $SERVER_VERSION =~ $SQL_VERSION" +else + echo "Server versiom mismatch: Got $SERVER_VERSION, expected $SQL_VERSION.*" + exit 1 +fi