trap "rm -f key.$$ tc-server-key.$$ tc-client-key.$$ log.$$ ; trap 0 ; exit 77" 1 2 15
trap "rm -f key.$$ tc-server-key.$$ tc-client-key.$$ log.$$ ; exit 1" 0 3
+# verbosity, defaults to "1"
+V="${V:-1}"
+tests_passed=0
+tests_failed=0
+
+# ----------------------------------------------------------
+# helper functions
+# ----------------------------------------------------------
+
+# output progress information
+# depending on verbosity level, collect & print only on failure
+test_start()
+{
+ case $V in
+ 0) outbuf="" ;; # no per-test output at all
+ 1) outbuf="$@" ;; # compact, details only on failure
+ *) printf "$@" ;; # print all
+ esac
+}
+test_end()
+{
+ RC=$1 ; LOG=$2
+ if [ $RC != 0 ]
+ then
+ case $V in
+ 0) ;; # no per-test output
+ 1) echo "$outbuf" "FAIL (RC=$RC)"; cat $LOG ;;
+ *) echo "FAIL (RC=$RC)"; cat $LOG ;;
+ esac
+ e=1
+ tests_failed=$(( $tests_failed + 1 ))
+ else
+ case $V in
+ 0|1) ;; # no per-test output for 'OK'
+ *) echo "OK" # print all
+ esac
+ tests_passed=$(( $tests_passed + 1 ))
+ fi
+}
+
+# if running with V=1, give an indication what test runs now
+if [ "$V" = 1 ] ; then
+ echo "$0: running with V=$V, only printing test fails"
+fi
+
+
# Get list of supported ciphers from openvpn --show-ciphers output
CIPHERS=$(${top_builddir}/src/openvpn/openvpn --show-ciphers | \
sed -e '/The following/,/^$/d' -e s'/ .*//' -e '/^[[:space:]]*$/d')
for cipher in ${CIPHERS}
do
- printf "Testing cipher ${cipher}... "
+ test_start "Testing cipher ${cipher}... "
( "${top_builddir}/src/openvpn/openvpn" --test-crypto --secret key.$$ --cipher ${cipher} ) >log.$$ 2>&1
- if [ $? != 0 ] ; then
- echo "FAILED"
- cat log.$$
- e=1
- else
- echo "OK"
- fi
+ test_end $? log.$$
done
-printf "Testing tls-crypt-v2 server key generation... "
+test_start "Testing tls-crypt-v2 server key generation... "
"${top_builddir}/src/openvpn/openvpn" \
--genkey tls-crypt-v2-server tc-server-key.$$ >log.$$ 2>&1
-if [ $? != 0 ] ; then
- echo "FAILED"
- cat log.$$
- e=1
-else
- echo "OK"
-fi
+test_end $? log.$$
-printf "Testing tls-crypt-v2 key generation (no metadata)... "
+test_start "Testing tls-crypt-v2 key generation (no metadata)... "
"${top_builddir}/src/openvpn/openvpn" --tls-crypt-v2 tc-server-key.$$ \
--genkey tls-crypt-v2-client tc-client-key.$$ >log.$$ 2>&1
-if [ $? != 0 ] ; then
- echo "FAILED"
- cat log.$$
- e=1
-else
- echo "OK"
-fi
+test_end $? log.$$
# Generate max-length base64 metadata ('A' is 0b000000 in base64)
METADATA=""
METADATA="${METADATA}A"
i=$(expr $i + 1)
done
-printf "Testing tls-crypt-v2 key generation (max length metadata)... "
+test_start "Testing tls-crypt-v2 key generation (max length metadata)... "
"${top_builddir}/src/openvpn/openvpn" --tls-crypt-v2 tc-server-key.$$ \
--genkey tls-crypt-v2-client tc-client-key.$$ "${METADATA}" \
>log.$$ 2>&1
-if [ $? != 0 ] ; then
- echo "FAILED"
- cat log.$$
- e=1
-else
- echo "OK"
+test_end $? log.$$
+
+if [ "$V" -ge 1 ] ; then
+ echo "$0: tests passed: $tests_passed failed: $tests_failed"
fi
rm key.$$ tc-server-key.$$ tc-client-key.$$ log.$$