2018-01-15 19:24:57 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
2017-12-15 14:25:17 +00:00
|
|
|
|
|
|
|
# Do all integration tests for all protocols
|
2017-12-18 05:56:57 +00:00
|
|
|
# To add tests for a new protocol, run `./integration_tests/new.sh <new_protocol>` and implement the appropriate test scripts.
|
2017-12-15 14:25:17 +00:00
|
|
|
|
2017-12-18 05:34:04 +00:00
|
|
|
# Run from root of project
|
|
|
|
TEST_DIR=$(dirname "$0")
|
2018-01-15 19:24:57 +00:00
|
|
|
ZGRAB_ROOT="$TEST_DIR/.."
|
|
|
|
cd "$ZGRAB_ROOT"
|
2017-12-15 14:25:17 +00:00
|
|
|
|
2018-01-15 19:24:57 +00:00
|
|
|
ZGRAB_OUTPUT="$ZGRAB_ROOT/zgrab-output"
|
2017-12-15 14:25:17 +00:00
|
|
|
|
|
|
|
pushd integration_tests
|
|
|
|
for mod in $(ls); do
|
|
|
|
if [ -d "$mod" ]; then
|
|
|
|
pushd $mod
|
|
|
|
for test in $(ls test*.sh); do
|
|
|
|
echo "Running integration_tests/$mod/$test"
|
|
|
|
./$test
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
|
2018-01-15 19:24:57 +00:00
|
|
|
status=0
|
|
|
|
failures=""
|
2017-12-15 21:57:04 +00:00
|
|
|
echo "Doing schema validation..."
|
|
|
|
for protocol in $(ls $ZGRAB_OUTPUT); do
|
|
|
|
for outfile in $(ls $ZGRAB_OUTPUT/$protocol); do
|
|
|
|
target="$ZGRAB_OUTPUT/$protocol/$outfile"
|
|
|
|
echo "Validating $target [{("
|
|
|
|
cat $target
|
|
|
|
echo ")}]:"
|
2018-01-15 19:24:57 +00:00
|
|
|
if ! python -m zschema validate schemas/__init__.py:zgrab2 $target; then
|
|
|
|
echo "Schema validation failed for $protocol/$outfile"
|
|
|
|
err="schema failure@$protocol/$outfile"
|
|
|
|
if [[ $status -eq 0 ]]; then
|
|
|
|
failures="$err"
|
|
|
|
else
|
|
|
|
failures="$failures, $err"
|
|
|
|
fi
|
|
|
|
status=1
|
|
|
|
else
|
|
|
|
echo "validation of $target succeeded."
|
|
|
|
scan_status=$($ZGRAB_ROOT/jp -u data.${protocol}.status < $target)
|
|
|
|
if ! [ $scan_status = "success" ]; then
|
|
|
|
echo "Scan returned success=$scan_status for $protocol/$outfile"
|
|
|
|
err="scan failure(${scan_status})@$protocol/$outfile"
|
|
|
|
if [[ $status -eq 0 ]]; then
|
|
|
|
failures="$err"
|
|
|
|
else
|
|
|
|
failures="$failures, $err"
|
|
|
|
fi
|
|
|
|
status=1
|
|
|
|
fi
|
|
|
|
fi
|
2017-12-15 14:25:17 +00:00
|
|
|
done
|
2017-12-15 21:57:04 +00:00
|
|
|
done
|
2018-01-15 19:24:57 +00:00
|
|
|
|
|
|
|
if [ -n "$failures" ]; then
|
|
|
|
echo "One or more schema validations failed: $failures"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $status
|