Add test cases for HOTP
This commit is contained in:
parent
92539dcf58
commit
84587a4c32
3
Makefile
3
Makefile
@ -32,6 +32,9 @@ otpcli: ${OBJ}
|
||||
clean:
|
||||
rm -f otpcli ${OBJ} ${P}-${V}.tgz
|
||||
|
||||
test: all run-tests.sh
|
||||
sh ./run-tests.sh
|
||||
|
||||
dist: clean
|
||||
pax -w -s '#^#${P}-${V}/#' ${DIST_FILES} | gzip >${P}-${V}.tgz
|
||||
|
||||
|
52
run-tests.sh
Normal file
52
run-tests.sh
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
# otpcli - command-line interface for HOTP and TOTP
|
||||
#
|
||||
# Written in 2020 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/>.
|
||||
|
||||
_test_rc=0
|
||||
_test_nr=0
|
||||
|
||||
case_eq()
|
||||
{
|
||||
_test_nr=$((_test_nr + 1))
|
||||
|
||||
expected=$1
|
||||
shift
|
||||
|
||||
got=$("$@")
|
||||
if [ "$got" != "$expected" ]; then
|
||||
printf "test %u: expected %s, got %s\n" \
|
||||
"$_test_nr" "$expected" "$got" >&2
|
||||
_test_rc=1
|
||||
fi
|
||||
}
|
||||
|
||||
HOTP_SECRET="12345678901234567890"
|
||||
|
||||
case_eq 755224 ./otpcli -H 0 "$HOTP_SECRET"
|
||||
case_eq 287082 ./otpcli -H 1 "$HOTP_SECRET"
|
||||
case_eq 359152 ./otpcli -H 2 "$HOTP_SECRET"
|
||||
case_eq 969429 ./otpcli -H 3 "$HOTP_SECRET"
|
||||
case_eq 338314 ./otpcli -H 4 "$HOTP_SECRET"
|
||||
case_eq 254676 ./otpcli -H 5 "$HOTP_SECRET"
|
||||
case_eq 287922 ./otpcli -H 6 "$HOTP_SECRET"
|
||||
case_eq 162583 ./otpcli -H 7 "$HOTP_SECRET"
|
||||
case_eq 399871 ./otpcli -H 8 "$HOTP_SECRET"
|
||||
case_eq 520489 ./otpcli -H 9 "$HOTP_SECRET"
|
||||
|
||||
if [ $_test_rc -eq 0 ]; then
|
||||
printf "All %u tests completed successfully!\n" "$_test_nr" >&2
|
||||
else
|
||||
printf "Some tests failed\n" >&2
|
||||
fi
|
||||
exit $_test_rc
|
Loading…
Reference in New Issue
Block a user