diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/001-error-no-args.test/run.sh | 8 | ||||
-rw-r--r-- | test/001-error-no-args.test/stderr.expected | 2 | ||||
-rwxr-xr-x | test/002-test-key-name.test/run.sh | 34 | ||||
-rw-r--r-- | test/003-test-invalid-char.test/run.sh | 9 | ||||
-rw-r--r-- | test/003-test-invalid-char.test/stderr.expected | 2 | ||||
-rwxr-xr-x | test/run-tests.sh | 43 |
6 files changed, 98 insertions, 0 deletions
diff --git a/test/001-error-no-args.test/run.sh b/test/001-error-no-args.test/run.sh new file mode 100755 index 0000000..4e67e1d --- /dev/null +++ b/test/001-error-no-args.test/run.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +${EXECUTABLE} +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/001-error-no-args.test/stderr.expected b/test/001-error-no-args.test/stderr.expected new file mode 100644 index 0000000..32481e5 --- /dev/null +++ b/test/001-error-no-args.test/stderr.expected @@ -0,0 +1,2 @@ +usage: ../../sand-leek [-t threads] -s search +searches for keys for onion addresses beginning with `search` diff --git a/test/002-test-key-name.test/run.sh b/test/002-test-key-name.test/run.sh new file mode 100755 index 0000000..e4b4acb --- /dev/null +++ b/test/002-test-key-name.test/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +key="$(mktemp)" +stderr="$(mktemp)" + +# Four character search should be a < 1 second CPU burst for CI runner +${EXECUTABLE} -s site > $key 2>$stderr + +found="$(tr '\r' '\n' < $stderr | grep Found | cut -d ' ' -f 2)" + +echo "sand-leek says it found $found..." + +# Trick adapted to py3 from https://swehack.org/viewtopic.php?f=37&p=6978 +real="$( \ + openssl rsa -in $key -pubout -outform DER \ + | tail -c +23 \ + | shasum \ + | head -c 20 \ + | python -c "import base64,sys,codecs; print(base64.b32encode(codecs.decode(sys.stdin.readline().strip('\n'), 'hex')).decode().lower())").onion" + + +echo "Key analysis shows it's for ${real}" + +if [ "$found" = "$real" ] ; then + echo "It's a match, I'm happy" + rm $key + rm $stderr + exit 0 +else + echo "Error: No match" + exit 1 +fi diff --git a/test/003-test-invalid-char.test/run.sh b/test/003-test-invalid-char.test/run.sh new file mode 100644 index 0000000..a59b826 --- /dev/null +++ b/test/003-test-invalid-char.test/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +${EXECUTABLE} -s foovalid1not + +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/003-test-invalid-char.test/stderr.expected b/test/003-test-invalid-char.test/stderr.expected new file mode 100644 index 0000000..f1652b2 --- /dev/null +++ b/test/003-test-invalid-char.test/stderr.expected @@ -0,0 +1,2 @@ +Error: search contains non-base-32 character(s): 1 +I cannot search for something that will never occur diff --git a/test/run-tests.sh b/test/run-tests.sh new file mode 100755 index 0000000..07647dd --- /dev/null +++ b/test/run-tests.sh @@ -0,0 +1,43 @@ +#!/bin/sh + + +fail() +{ + echo -e '[\e[1;31mFAIL\e[0m] '$i: $@ + exit 1 +} + +pass() +{ + echo -e '[\e[0;32mPASS\e[0m] '$i +} + +check_expected() +{ + [ -z $1 ] && echo WARN: check_expected called with no argument + if [ -f $1.expected ] ; then + diff $1.expected $1.tmp >/dev/null + if [ $? -ne 0 ] ; then + fail "$1 didn't match expected" + fi + fi +} + +pushd $(dirname $0) >/dev/null +EXECUTABLE="../../sand-leek" +for i in *.test ; do + pushd ${i} >/dev/null + ( . ./run.sh ) 2>stderr.tmp >stdout.tmp + if [ $? -ne 0 ] ; then + fail "script had non-zero return code" + fi + + check_expected stdout + check_expected stderr + + pass $i + + rm std{err,out}.tmp + popd >/dev/null +done +popd >/dev/null |