aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-02-11 15:59:41 -0500
committerNick Mathewson <nickm@torproject.org>2015-02-11 15:59:41 -0500
commitf794a091647050efa97719581f99c453b38074dd (patch)
tree719c797002a6a53419efd53fbadee0d62ec6b795 /src/test
parent99e915dbfea9b2b985a10368721d9c79b358abbe (diff)
parentdfb409b8b0b9bfcc4531e0a41b1924d55128c991 (diff)
downloadtor-f794a091647050efa97719581f99c453b38074dd.tar.gz
tor-f794a091647050efa97719581f99c453b38074dd.zip
Merge branch 'bug14478_squashed'
Diffstat (limited to 'src/test')
-rwxr-xr-xsrc/test/zero_length_keys.sh47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/test/zero_length_keys.sh b/src/test/zero_length_keys.sh
index 3a99ca1f1d..81ba3e0e17 100755
--- a/src/test/zero_length_keys.sh
+++ b/src/test/zero_length_keys.sh
@@ -13,10 +13,10 @@
# Check tor does not overwrite existing keys (existing behaviour)
#
# Exit Statuses:
-# -2: test failed - tor did not generate the key files on first run
-# -1: a command failed - the test could not be completed
# 0: test succeeded - tor regenerated/kept the files
# 1: test failed - tor did not regenerate/keep the files
+# 2: test failed - tor did not generate the key files on first run
+# 3: a command failed - the test could not be completed
#
if [ $# -lt 1 ]; then
@@ -25,14 +25,25 @@ if [ $# -lt 1 ]; then
exit $?
fi
-export DATA_DIR=`mktemp -d -t tor_zero_length_keys.XXXXXX`
+DATA_DIR=`mktemp -d -t tor_zero_length_keys.XXXXXX`
+if [ -z "$DATA_DIR" ]; then
+ echo "Failure: mktemp invocation returned empty string" >&2
+ exit 3
+fi
+if [ ! -d "$DATA_DIR" ]; then
+ echo "Failure: mktemp invocation result doesn't point to directory" >&2
+ exit 3
+fi
+trap "rm -rf '$DATA_DIR'" 0
+
# 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"
-if [ -s "$DATA_DIR"/keys/secret_id_key -a -s "$DATA_DIR"/keys/secret_onion_key -a -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
- echo "Failure: Previous tor keys present in tor data directory"
- exit -1
+if [ -s "$DATA_DIR"/keys/secret_id_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key ] &&
+ [ -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
+ echo "Failure: Previous tor keys present in tor data directory" >&2
+ exit 3
else
echo "Generating initial tor keys"
$TOR --DataDirectory "$DATA_DIR" --PidFile "$DATA_DIR"/pid &
@@ -43,15 +54,16 @@ else
wait $TOR_PID
# tor must successfully generate non-zero-length key files
- if [ -s "$DATA_DIR"/keys/secret_id_key -a -s "$DATA_DIR"/keys/secret_onion_key -a -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
+ if [ -s "$DATA_DIR"/keys/secret_id_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key ] &&
+ [ -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
true #echo "tor generated the initial key files"
else
echo "Failure: tor failed to generate the initial key files"
- exit -2
+ exit 2
fi
fi
-#ls -lh "$DATA_DIR"/keys/ || exit -1
+#ls -lh "$DATA_DIR"/keys/ || exit 3
# backup and keep/delete/create zero-length files for the keys
@@ -62,17 +74,17 @@ cp -r "$DATA_DIR"/keys "$DATA_DIR"/keys.old
# delete keys for -d or -z
if [ "$1" != "-e" ]; then
FILE_DESC="regenerates deleted"
- rm "$DATA_DIR"/keys/secret_id_key || exit -1
- rm "$DATA_DIR"/keys/secret_onion_key || exit -1
- rm "$DATA_DIR"/keys/secret_onion_key_ntor || exit -1
+ rm "$DATA_DIR"/keys/secret_id_key || exit 3
+ rm "$DATA_DIR"/keys/secret_onion_key || exit 3
+ rm "$DATA_DIR"/keys/secret_onion_key_ntor || exit 3
fi
# create empty files for -z
if [ "$1" = "-z" ]; then
FILE_DESC="regenerates zero-length"
- touch "$DATA_DIR"/keys/secret_id_key || exit -1
- touch "$DATA_DIR"/keys/secret_onion_key || exit -1
- touch "$DATA_DIR"/keys/secret_onion_key_ntor || exit -1
+ touch "$DATA_DIR"/keys/secret_id_key || exit 3
+ touch "$DATA_DIR"/keys/secret_onion_key || exit 3
+ touch "$DATA_DIR"/keys/secret_onion_key_ntor || exit 3
fi
echo "Running tor again to check if it $FILE_DESC keys"
@@ -83,10 +95,11 @@ sleep 5
kill $TOR_PID
wait $TOR_PID
-#ls -lh "$DATA_DIR"/keys/ || exit -1
+#ls -lh "$DATA_DIR"/keys/ || exit 3
# tor must always have non-zero-length key files
-if [ -s "$DATA_DIR"/keys/secret_id_key -a -s "$DATA_DIR"/keys/secret_onion_key -a -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
+if [ -s "$DATA_DIR"/keys/secret_id_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key ] &&
+ [ -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then
# check if the keys are different to the old ones
diff -q -r "$DATA_DIR"/keys "$DATA_DIR"/keys.old > /dev/null
SAME_KEYS=$?