diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2502e0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# macOS +.DS_Store + +# zgrab +cmd/zgrab2/zgrab2 +zgrab-output/ + +# CI dependencies +jp diff --git a/.travis.yml b/.travis.yml index 3af9447..fd117dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,14 @@ before_install: # JMESPath is used to do context-specific validation of results - go get github.com/jmespath/jp && go build github.com/jmespath/jp - pip install --user zschema -- ./setup_integration_tests.sh +- ./integration_tests/setup.sh - docker ps -a install: - pushd cmd/zgrab2 && go build && popd script: -- ./integration_tests.sh +- ./integration_tests/test.sh after_script: -- ./cleanup_integration_tests.sh +- ./integration_tests/cleanup.sh notifications: email: - dev@censys.io diff --git a/cleanup_integration_tests.sh b/integration_tests/cleanup.sh similarity index 90% rename from cleanup_integration_tests.sh rename to integration_tests/cleanup.sh index dd6190b..6e193e7 100755 --- a/cleanup_integration_tests.sh +++ b/integration_tests/cleanup.sh @@ -6,6 +6,10 @@ set +e # Clean up after running the integration tests. # Drop your cleanup script(s) in integration_tests//cleanup(.*).sh +# Run from root of project +TEST_DIR=$(dirname "$0") +cd "$TEST_DIR/.." + echo "Cleaning up integration tests..." pushd integration_tests diff --git a/integration_tests/new.sh b/integration_tests/new.sh new file mode 100755 index 0000000..cb3793a --- /dev/null +++ b/integration_tests/new.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Utility script for scaffolding stub test files for a new protocol + +# Run from root of project +TEST_DIR=$(dirname "$0") +cd "$TEST_DIR/.." + +if [ "$#" -ne 1 ] +then + echo "Usage: ./integration_tests/new.sh " + exit 1 +fi + +module_name="$1" +module_path="integration_tests/$module_name" + +mkdir -p $module_path + +cat << EOF > $module_path/setup.sh +#!/usr/bin/env bash + +echo "Tests setup for $module_name" +EOF +chmod +x $module_path/setup.sh + +cat << EOF > $module_path/test.sh +#!/usr/bin/env bash + +echo "Tests runner for $module_name" +EOF +chmod +x $module_path/test.sh + +cat << EOF > $module_path/cleanup.sh +#!/usr/bin/env bash + +echo "Tests cleanup for $module_name" +EOF +chmod +x $module_path/cleanup.sh + +echo "Test files scafollded in $module_path" diff --git a/setup_integration_tests.sh b/integration_tests/setup.sh similarity index 87% rename from setup_integration_tests.sh rename to integration_tests/setup.sh index 5fd2acb..fae5663 100755 --- a/setup_integration_tests.sh +++ b/integration_tests/setup.sh @@ -3,6 +3,10 @@ # Set up the integration tests for all modules. # Drop your setup script(s) in integration_tests//setup(.*).sh +# Run from root of project +TEST_DIR=$(dirname "$0") +cd "$TEST_DIR/.." + echo "Setting up integration tests..." pushd integration_tests diff --git a/integration_tests.sh b/integration_tests/test.sh similarity index 82% rename from integration_tests.sh rename to integration_tests/test.sh index 5955848..3c1d00e 100755 --- a/integration_tests.sh +++ b/integration_tests/test.sh @@ -1,7 +1,11 @@ #!/bin/bash -e # Do all integration tests for all protocols -# To add tests for a new protocol, create a directory integration_tests/, and drop its setup.sh, test.sh, and cleanup.sh there. +# To add tests for a new protocol, run `./integration_tests/new.sh ` and implement the appropriate test scripts. + +# Run from root of project +TEST_DIR=$(dirname "$0") +cd "$TEST_DIR/.." # _integration_tests.sh should drop its output into $ZGRAB_OUTPUT//* so that it can be validated if [ -z $ZGRAB_OUTPUT ]; then