Rework tests
Split along multiple files, produce TAP output, rely on Perl's prove for running them. Improves clarity and hopefully makes it easier to add new tests in the future.
This commit is contained in:
parent
3093486c9f
commit
2fe090286d
7 changed files with 138 additions and 123 deletions
24
t/0000-RFC-4226-Test-Vectors.t
Normal file
24
t/0000-RFC-4226-Test-Vectors.t
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh
|
||||
[ -n "${0%/*}" ] && cd "${0%/*}"
|
||||
. ./lib.sh
|
||||
|
||||
if [ ! -x ../otpcli ]; then
|
||||
plan 0 "skip: build otpcli first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# base32("12345678901234567890")
|
||||
key=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
|
||||
|
||||
plan 10
|
||||
|
||||
check "counter 0" 755224 ../otpcli -H 0 "$key"
|
||||
check "counter 1" 287082 ../otpcli -H 1 "$key"
|
||||
check "counter 2" 359152 ../otpcli -H 2 "$key"
|
||||
check "counter 3" 969429 ../otpcli -H 3 "$key"
|
||||
check "counter 4" 338314 ../otpcli -H 4 "$key"
|
||||
check "counter 5" 254676 ../otpcli -H 5 "$key"
|
||||
check "counter 6" 287922 ../otpcli -H 6 "$key"
|
||||
check "counter 7" 162583 ../otpcli -H 7 "$key"
|
||||
check "counter 8" 399871 ../otpcli -H 8 "$key"
|
||||
check "counter 9" 520489 ../otpcli -H 9 "$key"
|
20
t/0001-RFC-6238-SHA-1-Test-Vectors.t
Normal file
20
t/0001-RFC-6238-SHA-1-Test-Vectors.t
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
[ -n "${0%/*}" ] && cd "${0%/*}"
|
||||
. ./lib.sh
|
||||
|
||||
if [ ! -x ../otpcli ]; then
|
||||
plan 0 "skip: build otpcli first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plan 6
|
||||
|
||||
# base32("12345678901234567890")
|
||||
key=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
|
||||
|
||||
check "time 59" 94287082 ../otpcli -d 8 -a sha1 -T 59 "$key"
|
||||
check "time 1111111109" 07081804 ../otpcli -d 8 -a sha1 -T 1111111109 "$key"
|
||||
check "time 1111111111" 14050471 ../otpcli -d 8 -a sha1 -T 1111111111 "$key"
|
||||
check "time 1234567890" 89005924 ../otpcli -d 8 -a sha1 -T 1234567890 "$key"
|
||||
check "time 2000000000" 69279037 ../otpcli -d 8 -a sha1 -T 2000000000 "$key"
|
||||
check "time 20000000000" 65353130 ../otpcli -d 8 -a sha1 -T 20000000000 "$key"
|
20
t/0002-RFC-6238-SHA-256-Test-Vectors.t
Normal file
20
t/0002-RFC-6238-SHA-256-Test-Vectors.t
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
[ -n "${0%/*}" ] && cd "${0%/*}"
|
||||
. ./lib.sh
|
||||
|
||||
if [ ! -x ../otpcli ]; then
|
||||
plan 0 "skip: build otpcli first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plan 6
|
||||
|
||||
# base32("12345678901234567890123456789012")
|
||||
key=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA
|
||||
|
||||
check "time 59" 46119246 ../otpcli -d 8 -a sha256 -T 59 "$key"
|
||||
check "time 1111111109" 68084774 ../otpcli -d 8 -a sha256 -T 1111111109 "$key"
|
||||
check "time 1111111111" 67062674 ../otpcli -d 8 -a sha256 -T 1111111111 "$key"
|
||||
check "time 1234567890" 91819424 ../otpcli -d 8 -a sha256 -T 1234567890 "$key"
|
||||
check "time 2000000000" 90698825 ../otpcli -d 8 -a sha256 -T 2000000000 "$key"
|
||||
check "time 20000000000" 77737706 ../otpcli -d 8 -a sha256 -T 20000000000 "$key"
|
20
t/0003-RFC-6238-SHA-512-Test-Vectors.t
Normal file
20
t/0003-RFC-6238-SHA-512-Test-Vectors.t
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
[ -n "${0%/*}" ] && cd "${0%/*}"
|
||||
. ./lib.sh
|
||||
|
||||
if [ ! -x ../otpcli ]; then
|
||||
plan 0 "skip: build otpcli first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plan 6
|
||||
|
||||
# base32("1234567890123456789012345678901234567890123456789012345678901234")
|
||||
key=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA
|
||||
|
||||
check "time 59" 90693936 ../otpcli -d 8 -a sha512 -T 59 "$key"
|
||||
check "time 1111111109" 25091201 ../otpcli -d 8 -a sha512 -T 1111111109 "$key"
|
||||
check "time 1111111111" 99943326 ../otpcli -d 8 -a sha512 -T 1111111111 "$key"
|
||||
check "time 1234567890" 93441116 ../otpcli -d 8 -a sha512 -T 1234567890 "$key"
|
||||
check "time 2000000000" 38618901 ../otpcli -d 8 -a sha512 -T 2000000000 "$key"
|
||||
check "time 20000000000" 47863826 ../otpcli -d 8 -a sha512 -T 20000000000 "$key"
|
52
t/lib.sh
Normal file
52
t/lib.sh
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/sh
|
||||
# otpcli - command-line interface for HOTP and TOTP
|
||||
#
|
||||
# Written in 2021 by Lucas
|
||||
#
|
||||
# To the extent possible under law, the author(s) have dedicated all
|
||||
# copyright and related and neighboring rights to this software to the
|
||||
# public domain worldwide. This software is distributed without any
|
||||
# warranty.
|
||||
#
|
||||
# You should have received a copy of the CC0 Public Domain Dedication
|
||||
# along with this software. If not, see
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
# Produces TAP (Test Anything Protocol) output
|
||||
|
||||
# plan number_of_tests [directive]
|
||||
plan()
|
||||
{
|
||||
_n=$1
|
||||
shift
|
||||
|
||||
if [ -n "$*" ]; then
|
||||
printf "1..%u # %s\n" "$_n" "$*"
|
||||
else
|
||||
printf "1..%u\n" "$_n"
|
||||
fi
|
||||
|
||||
_counter=1
|
||||
}
|
||||
|
||||
# check description expected command [args...]
|
||||
check()
|
||||
{
|
||||
_description=$1 _expected=$2
|
||||
shift 2
|
||||
_got=$("${@:-:}")
|
||||
|
||||
_rc=0
|
||||
if [ "$_got" != "$_expected" ]; then
|
||||
printf "not ok %u - %s\n" "$_counter" "$_description"
|
||||
printf " # Failed test at %s.\n" "$0"
|
||||
printf " # got: '%s'\n" "$_got"
|
||||
printf " # expected: '%s'\n" "$_expected"
|
||||
_rc=1
|
||||
else
|
||||
printf "ok %u - %s\n" "$_counter" "$_description"
|
||||
fi
|
||||
|
||||
_counter=$(($_counter + 1))
|
||||
return $_rc
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue