From 33cc12f0308624edd8ac85d59cbe78e18f157082 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 15 Jun 2020 23:57:39 +0000 Subject: [PATCH] Also run tests with standard input While there, add a explicit `-h sha1` to TOTP tests. --- run-tests.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 8560cda..bd459ca 100644 --- a/run-tests.sh +++ b/run-tests.sh @@ -31,6 +31,22 @@ case_eq() fi } +case_stdin_eq() +{ + _test_nr=$((_test_nr + 1)) + + expected=$1 + input=$2 + shift 2 + + got=$(printf "%s\n" "$input" | "$@") + if [ "$got" != "$expected" ]; then + printf "test %u: expected %s, got %s\n" \ + "$_test_nr" "$expected" "$got" >&2 + _test_rc=1 + fi +} + b="1234567890" HOTP_SECRET=$b$b TOTP_SECRET=$b$b @@ -48,25 +64,55 @@ case_eq 162583 ./otpcli -H 7 "$HOTP_SECRET" case_eq 399871 ./otpcli -H 8 "$HOTP_SECRET" case_eq 520489 ./otpcli -H 9 "$HOTP_SECRET" -case_eq 94287082 ./otpcli -d 8 -T 59 "$TOTP_SECRET" +case_stdin_eq 755224 "$HOTP_SECRET" ./otpcli -H 0 +case_stdin_eq 287082 "$HOTP_SECRET" ./otpcli -H 1 +case_stdin_eq 359152 "$HOTP_SECRET" ./otpcli -H 2 +case_stdin_eq 969429 "$HOTP_SECRET" ./otpcli -H 3 +case_stdin_eq 338314 "$HOTP_SECRET" ./otpcli -H 4 +case_stdin_eq 254676 "$HOTP_SECRET" ./otpcli -H 5 +case_stdin_eq 287922 "$HOTP_SECRET" ./otpcli -H 6 +case_stdin_eq 162583 "$HOTP_SECRET" ./otpcli -H 7 +case_stdin_eq 399871 "$HOTP_SECRET" ./otpcli -H 8 +case_stdin_eq 520489 "$HOTP_SECRET" ./otpcli -H 9 + +case_eq 94287082 ./otpcli -d 8 -h sha1 -T 59 "$TOTP_SECRET" case_eq 46119246 ./otpcli -d 8 -h sha256 -T 59 "$TOTP_SHA256_SECRET" case_eq 90693936 ./otpcli -d 8 -h sha512 -T 59 "$TOTP_SHA512_SECRET" -case_eq 07081804 ./otpcli -d 8 -T 1111111109 "$TOTP_SECRET" +case_eq 07081804 ./otpcli -d 8 -h sha1 -T 1111111109 "$TOTP_SECRET" case_eq 68084774 ./otpcli -d 8 -h sha256 -T 1111111109 "$TOTP_SHA256_SECRET" case_eq 25091201 ./otpcli -d 8 -h sha512 -T 1111111109 "$TOTP_SHA512_SECRET" -case_eq 14050471 ./otpcli -d 8 -T 1111111111 "$TOTP_SECRET" +case_eq 14050471 ./otpcli -d 8 -h sha1 -T 1111111111 "$TOTP_SECRET" case_eq 67062674 ./otpcli -d 8 -h sha256 -T 1111111111 "$TOTP_SHA256_SECRET" case_eq 99943326 ./otpcli -d 8 -h sha512 -T 1111111111 "$TOTP_SHA512_SECRET" -case_eq 89005924 ./otpcli -d 8 -T 1234567890 "$TOTP_SECRET" +case_eq 89005924 ./otpcli -d 8 -h sha1 -T 1234567890 "$TOTP_SECRET" case_eq 91819424 ./otpcli -d 8 -h sha256 -T 1234567890 "$TOTP_SHA256_SECRET" case_eq 93441116 ./otpcli -d 8 -h sha512 -T 1234567890 "$TOTP_SHA512_SECRET" -case_eq 69279037 ./otpcli -d 8 -T 2000000000 "$TOTP_SECRET" +case_eq 69279037 ./otpcli -d 8 -h sha1 -T 2000000000 "$TOTP_SECRET" case_eq 90698825 ./otpcli -d 8 -h sha256 -T 2000000000 "$TOTP_SHA256_SECRET" case_eq 38618901 ./otpcli -d 8 -h sha512 -T 2000000000 "$TOTP_SHA512_SECRET" -case_eq 65353130 ./otpcli -d 8 -T 20000000000 "$TOTP_SECRET" +case_eq 65353130 ./otpcli -d 8 -h sha1 -T 20000000000 "$TOTP_SECRET" case_eq 77737706 ./otpcli -d 8 -h sha256 -T 20000000000 "$TOTP_SHA256_SECRET" case_eq 47863826 ./otpcli -d 8 -h sha512 -T 20000000000 "$TOTP_SHA512_SECRET" +case_stdin_eq 94287082 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 59 +case_stdin_eq 46119246 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 59 +case_stdin_eq 90693936 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 59 +case_stdin_eq 07081804 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 1111111109 +case_stdin_eq 68084774 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 1111111109 +case_stdin_eq 25091201 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 1111111109 +case_stdin_eq 14050471 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 1111111111 +case_stdin_eq 67062674 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 1111111111 +case_stdin_eq 99943326 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 1111111111 +case_stdin_eq 89005924 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 1234567890 +case_stdin_eq 91819424 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 1234567890 +case_stdin_eq 93441116 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 1234567890 +case_stdin_eq 69279037 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 2000000000 +case_stdin_eq 90698825 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 2000000000 +case_stdin_eq 38618901 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 2000000000 +case_stdin_eq 65353130 "$TOTP_SECRET" ./otpcli -d 8 -h sha1 -T 20000000000 +case_stdin_eq 77737706 "$TOTP_SHA256_SECRET" ./otpcli -d 8 -h sha256 -T 20000000000 +case_stdin_eq 47863826 "$TOTP_SHA512_SECRET" ./otpcli -d 8 -h sha512 -T 20000000000 + if [ $_test_rc -eq 0 ]; then printf "All %u tests completed successfully!\n" "$_test_nr" >&2 else