#!/bin/sh # # do a validation - ONLY FOR DEVELOPMENT! # # it will not work, if /var/www/report is read-only (as for a production cd) # # use "--help" for a list of possible actions # # called by: # - /var/www/cgi-bin/validate.sh for conducting validation tests # set -eu # parse config file . /etc/cryptobox/cryptobox.conf function error_die() { echo "$2" >&2 exit $1 } function do_single() # Parameter: "test case dir" "output directory for results" { local TESTNAME=$(basename $1) curl --insecure --silent --output "${2}/${TESTNAME}.html" --config "$1/input.curl" # there is no status in certain cases - e.g. for error 404 if [ -e "${2}/${TESTNAME}.html" ] then sed "1,/CBOX-STATUS-begin/d; /CBOX-STATUS-end/,\$d" "${2}/${TESTNAME}.html" >"${2}/${TESTNAME}.status" # the diff option "-B" is required, because the status output of # the cryptobox.pl script contains some blank lines diff -NB "${2}/${TESTNAME}.status" "$1/output" >"${2}/${TESTNAME}.diff" || true rm "${2}/${TESTNAME}.status" fi cp "$1/description" "${2}/${TESTNAME}.desc" } function do_series() # parameter: name of the test case { [ -d "$REPORT_DIR/$1" ] && rm -r "$REPORT_DIR/$1" mkdir -p "$REPORT_DIR/$1" find "$TEST_CASES_DIR/$1" -type d -maxdepth 1 -mindepth 1 | grep -v "/\.\.*$" | sort | while read a do do_single "$a" "$REPORT_DIR/$1" done create_summary "$REPORT_DIR/$1" >"$REPORT_DIR/$1/summary.html" tar czf "$REPORT_DIR/${1}-results.tar.gz" -C "$REPORT_DIR" "$1" #echo "$REPORT_DIR/${1}-results.tar.gz" } create_summary() # parameter: directory of results { cat "$SUMMARY_TEMPLATE_DIR/header" find "$1" -type f -name \*.desc -maxdepth 1 | sort | while read a do TESTNAME=$(basename ${a%.desc}) TESTDESCRIPTION=$(cat $a) sed "s#_TESTNAME_#$TESTNAME#g; s/_TESTDESCRIPTION_/$TESTDESCRIPTION/" "$SUMMARY_TEMPLATE_DIR/single_header" local DIFF_FILE=${a%.desc}.diff if [ -s "$DIFF_FILE" ] then cat "$SUMMARY_TEMPLATE_DIR/result-error" sed 's#$#
#' "$DIFF_FILE" else cat "$SUMMARY_TEMPLATE_DIR/result-ok" echo "no differences found" # remove empty diff [ -e "$DIFF_FILE" ] && rm "$DIFF_FILE" fi cat "$SUMMARY_TEMPLATE_DIR/single_footer" # remove description file rm "$a" done cat "$SUMMARY_TEMPLATE_DIR/footer" } ACTION="--help" [ $# -gt 0 ] && ACTION=$1 case "$ACTION" in list ) find "$TEST_CASES_DIR" -type d -maxdepth 1 -mindepth 1 | grep -v "/\.\.*$" | sort | while read a do echo $(basename "$a") done ;; check ) [ $# -ne 2 ] && error_die 1 "Syntax: $(basename $0) check NAME" CASE_DIR="$TEST_CASES_DIR/$2" [ ! -d "$CASE_DIR" ] && error_die 2 "the test case was not found ($CASE_DIR)!" do_series "$2" ;; check_all ) "$0" list | sort | while read a do echo -n "Validating $a ..." "$0" check "$a" echo echo -n "Waiting 20 seconds ..." sleep 20 echo done ;; * ) echo "Syntax of $(basename $0)" echo -e "\t list \t\t - show a list of available test cases" echo -e "\t check NAME \t - execute a test case" echo -e "\t check_all \t - execute all test cases" echo -e "\t help \t\t - this syntax information" echo ;; esac