diff --git a/integration_tests/amqp091/cleanup.sh b/integration_tests/amqp091/cleanup.sh new file mode 100755 index 00000000..a80456c1 --- /dev/null +++ b/integration_tests/amqp091/cleanup.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# Keep cleaning up even if something fails +set +e + +# Stop all MySQL containers. + +VERSIONS="3.12.14 3.13.2" + +for version in $MYSQL_VERSIONS; do + CONTAINER_NAME="zgrab_amqp091-$version" + echo "amqp091/cleanup: Stopping $CONTAINER_NAME..." + docker stop $CONTAINER_NAME + echo "amqp091/cleanup: ...stopped." +done diff --git a/integration_tests/amqp091/setup.sh b/integration_tests/amqp091/setup.sh new file mode 100755 index 00000000..ddf52e9c --- /dev/null +++ b/integration_tests/amqp091/setup.sh @@ -0,0 +1,37 @@ +#!/bin/bash -e + +VERSIONS="3.12.14 3.13.2" + +function launch() { + VERSION=$1 + CONTAINER_NAME="zgrab_amqp091-$VERSION" + if docker ps --filter "name=$CONTAINER_NAME" | grep -q $CONTAINER_NAME; then + echo "amqp091/setup: Container $CONTAINER_NAME already running -- skipping launch..." + return + fi + docker run -td --rm --name $CONTAINER_NAME rabbitmq:$VERSION +} + +function waitFor() { + VERSION=$1 + CONTAINER_NAME=zgrab_amqp091-$VERSION + echo "amqp091/setup: Waiting for $CONTAINER_NAME to become ready..." + while ! (docker logs --tail all $CONTAINER_NAME | grep -q "started TCP listener on"); do + echo -n "." + sleep 1 + done + for i in $(seq 1 5); do + echo -n "*" + sleep 1 + done + echo "...ok." +} + +echo "amqp091/setup: Launching docker containers..." +for version in $VERSIONS; do + launch $version +done + +for version in $VERSIONS; do + waitFor $version +done diff --git a/integration_tests/amqp091/test.sh b/integration_tests/amqp091/test.sh new file mode 100755 index 00000000..7a669278 --- /dev/null +++ b/integration_tests/amqp091/test.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -e + +VERSIONS="3.12.14 3.13.2" + +# Run the AMQP-specific integration tests: +# 1. Run zgrab2 on the container +# 2. Check that data.amqp091.result.server_properties.version matches $MQ_VERSION + +MODULE_DIR=$(dirname $0) +TEST_ROOT=$MODULE_DIR/.. +ZGRAB_ROOT=$MODULE_DIR/../.. +ZGRAB_OUTPUT=$ZGRAB_ROOT/zgrab-output + +status=0 + +function doTest() { + MQ_VERSION=$1 + CONTAINER_NAME="zgrab_amqp091-$MQ_VERSION" + OUTPUT_FILE="$ZGRAB_OUTPUT/amqp091/$MQ_VERSION.json" + echo "amqp091/test: Testing MySQL Version $MQ_VERSION..." + CONTAINER_NAME=$CONTAINER_NAME $ZGRAB_ROOT/docker-runner/docker-run.sh amqp091 --timeout 10s >$OUTPUT_FILE + SERVER_VERSION=$(jp -u data.amqp091.result.server_properties.version <$OUTPUT_FILE) + if [[ "$SERVER_VERSION" == "$MQ_VERSION."* ]]; then + echo "amqp091/test: Server version matches expected version: $SERVER_VERSION == $MQ_VERSION.*" + else + echo "amqp091/test: Server version mismatch: Got $SERVER_VERSION, expected $MQ_VERSION.*. Full output: [[" + cat $OUTPUT_FILE + echo "]]" + status=1 + fi + echo "amqp091/test: BEGIN docker+amqp091 logs from $CONTAINER_NAME [{(" + docker logs --tail all $CONTAINER_NAME + echo ")}] END docker+amqp091 logs from $CONTAINER_NAME" +} + +mkdir -p $ZGRAB_OUTPUT/amqp091 + +for version in $VERSIONS; do + doTest $version +done + +exit $status