mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-10 01:17:19 +00:00
Refactor: move code for obtaining totp tokens to tests/lib/totp.sh
This commit is contained in:
parent
c0431474c9
commit
752da93a37
@ -16,4 +16,5 @@
|
|||||||
|
|
||||||
. "$1/populate.sh" || exit 7
|
. "$1/populate.sh" || exit 7
|
||||||
. "$1/installed-state.sh" || exit 8
|
. "$1/installed-state.sh" || exit 8
|
||||||
|
. "$1/totp.sh" || exit 9
|
||||||
|
|
||||||
|
21
tests/lib/totp.sh
Normal file
21
tests/lib/totp.sh
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#
|
||||||
|
# requires:
|
||||||
|
# mailinabox's python installed with pyotp module at
|
||||||
|
# /usr/local/lib/mailinabox/env
|
||||||
|
#
|
||||||
|
|
||||||
|
totp_current_token() {
|
||||||
|
# given a secret, get the current token
|
||||||
|
# token written to stdout
|
||||||
|
# error message to stderr
|
||||||
|
# return 0 if successful
|
||||||
|
# non-zero if an error occured
|
||||||
|
local secret="$1"
|
||||||
|
/usr/local/lib/mailinabox/env/bin/python -c "import pyotp; totp=pyotp.TOTP(r'$secret'); print(totp.now());"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
@ -195,9 +195,9 @@ mgmt_get_totp_token() {
|
|||||||
local count=0
|
local count=0
|
||||||
|
|
||||||
while [ -z "$TOTP_TOKEN" -a $count -lt 10 ]; do
|
while [ -z "$TOTP_TOKEN" -a $count -lt 10 ]; do
|
||||||
TOTP_TOKEN="$(/usr/local/lib/mailinabox/env/bin/python -c "import pyotp; totp=pyotp.TOTP(r'$secret'); print(totp.now());" 2>>"$TEST_OF")"
|
TOTP_TOKEN="$(totp_current_token "$secret" 2>>"$TEST_OF")"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
record "Failed: Could not generate a TOTP token !"
|
record "Failed: Could not get the TOTP token !"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user