]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Integrate zero_length_keys test into the automake test suite.
authorcypherpunks <cypherpunks@torproject.org>
Thu, 5 Mar 2015 08:03:06 +0000 (09:03 +0100)
committerNick Mathewson <nickm@torproject.org>
Thu, 23 Apr 2015 13:56:12 +0000 (09:56 -0400)
The zero length keys test now requires the path to the Tor binary as the first
parameter to ensure the correct Tor binary is used without hard coding a path.

The wrapper script calls the zero length keys test for each test separately to
ensure the correct shell is used (as configured by autoconf). Another solution
would have been to place the tests into separate functions so multiple tests
could be run internally. This would have made a diff of considerable size and
frankly it is outside the scope of this fix.

.gitignore
configure.ac
src/test/include.am
src/test/test_zero_length_keys.sh.in [new file with mode: 0644]
src/test/zero_length_keys.sh

index 912b06e2c594f6d47b593fc50f7c7ba450b7a456..5fc000f1ab9554be89fea4f36bfb88734175d428 100644 (file)
@@ -174,6 +174,7 @@ cscope.*
 /src/test/test-child.exe
 /src/test/test-ntor-cl.exe
 /src/test/test_workqueue.exe
+/src/test/test_zero_length_keys.sh
 
 # /src/tools/
 /src/tools/tor-checkkey
index 2c9c7a343fe8d3ed970629ca5e2c913c7ca07e90..32afc1b6b58db4d8bbd1d66a84c72714adb75e2d 100644 (file)
@@ -1662,6 +1662,7 @@ AC_CONFIG_FILES([
         src/config/torrc.minimal
         scripts/maint/checkOptionDocs.pl
         scripts/maint/updateVersions.pl
+        src/test/test_zero_length_keys.sh
 ])
 
 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
index c857ec2f89ad3305c2d25443266c2f291524cd49..eba13abd24d0e26a447b0d3dc8f021a4016bf777 100644 (file)
@@ -1,4 +1,8 @@
-TESTS += src/test/test src/test/test-slow src/test/test-memwipe
+TESTS += src/test/test src/test/test-slow src/test/test-memwipe \
+       src/test/test_zero_length_keys.sh
+
+TEST_EXTENSIONS = .sh
+SH_LOG_COMPILER = $(SHELL)
 
 noinst_PROGRAMS+= src/test/bench
 if UNITTESTS_ENABLED
@@ -170,7 +174,6 @@ if USEPYTHON
        $(top_builddir)/src/test/test-bt-cl assert | $(PYTHON) $(top_srcdir)/src/test/bt_test.py
        $(top_builddir)/src/test/test-bt-cl crash | $(PYTHON) $(top_srcdir)/src/test/bt_test.py
 endif
-       $(SHELL) $(top_srcdir)/src/test/zero_length_keys.sh
 
 EXTRA_DIST += \
        src/test/bt_test.py \
diff --git a/src/test/test_zero_length_keys.sh.in b/src/test/test_zero_length_keys.sh.in
new file mode 100644 (file)
index 0000000..47467ba
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Check that tor regenerates keys when key files are zero-length
+
+exitcode=0
+
+@SHELL@ @abs_top_srcdir@/src/test/zero_length_keys.sh "@builddir@/src/or/tor" -z || exitcode=1
+@SHELL@ @abs_top_srcdir@/src/test/zero_length_keys.sh "@builddir@/src/or/tor" -d || exitcode=1
+@SHELL@ @abs_top_srcdir@/src/test/zero_length_keys.sh "@builddir@/src/or/tor" -e || exitcode=1
+
+exit ${exitcode}
index 2fd11d38bd3d8e597d78deff0a7dad2a9ce3108c..3c61f8d465777f2ca551d8b7dd37feb8c09980ac 100755 (executable)
@@ -3,13 +3,13 @@
 # Test for bug #13111 - Tor fails to start if onion keys are zero length
 #
 # Usage:
-#  ./zero_length_keys.sh
+#  ./zero_length_keys.sh PATH_TO_TOR
 #    Run all the tests below
-#  ./zero_length_keys.sh -z
+#  ./zero_length_keys.sh PATH_TO_TOR -z
 #    Check tor will launch and regenerate zero-length keys
-#  ./zero_length_keys.sh -d
+#  ./zero_length_keys.sh PATH_TO_TOR -d
 #    Check tor regenerates deleted keys (existing behaviour)
-#  ./zero_length_keys.sh -e
+#  ./zero_length_keys.sh PATH_TO_TOR -e
 #    Check tor does not overwrite existing keys (existing behaviour)
 #
 # Exit Statuses:
 #   3: a command failed - the test could not be completed
 #
 
-if [ $# -lt 1 ]; then
+if [ $# -eq 0 ] || [ ! -f ${1} ] || [ ! -x ${1} ]; then
+  echo "Usage: ${0} PATH_TO_TOR [-z|-d|-e]"
+  exit 1
+elif [ $# -eq 1 ]; then
   echo "Testing that tor correctly handles zero-length keys"
-  "$0" -z && "$0" -d && "$0" -e
+  "$0" "${1}" -z && "$0" "${1}" -d && "$0" "${1}" -e
   exit $?
+else #[$# -gt 1 ]; then
+  TOR_BINARY="${1}"
+  shift
 fi
 
 DATA_DIR=`mktemp -d -t tor_zero_length_keys.XXXXXX`
@@ -40,7 +46,7 @@ touch "$DATA_DIR"/empty_torrc
 
 # DisableNetwork means that the ORPort won't actually be opened.
 # 'ExitRelay 0' suppresses a warning.
-TOR="./src/or/tor --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0 -f $DATA_DIR/empty_torrc"
+TOR="${TOR_BINARY} --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0 -f $DATA_DIR/empty_torrc"
 
 if [ -s "$DATA_DIR"/keys/secret_id_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key ] &&
    [ -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then