Skip to content

Commit

Permalink
test: integration test for AMQP091
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed May 15, 2024
1 parent 6c4c8dd commit 10e4da6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
15 changes: 15 additions & 0 deletions integration_tests/amqp091/cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions integration_tests/amqp091/setup.sh
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions integration_tests/amqp091/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 10e4da6

Please sign in to comment.