diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rwxr-xr-x | otp.bash | 14 | ||||
-rwxr-xr-x | test/insert.t | 45 | ||||
-rw-r--r-- | test/setup.sh | 6 |
4 files changed, 47 insertions, 19 deletions
diff --git a/.travis.yml b/.travis.yml index cd537e0..4122f71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ addons: sources: - debian-sid packages: + - expect - oathtool - shellcheck @@ -121,16 +121,14 @@ cmd_otp_insert() { path="$1" if [[ -t 0 ]]; then if [[ $echo -eq 0 ]]; then - while true; do - read -r -p "Enter otpauth:// URI for $path: " -s uri || exit 1 - echo - read -r -p "Retype otpauth:// URI for $path: " -s uri_again || exit 1 - echo - [[ "$uri" == "$uri_again" ]] && break - die "Error: the entered URIs do not match." - done + read -r -p "Enter otpauth:// URI for $path: " -s uri || exit 1 + echo + read -r -p "Retype otpauth:// URI for $path: " -s uri_again || exit 1 + echo + [[ "$uri" == "$uri_again" ]] || die "Error: the entered URIs do not match." else read -r -p "Enter otpauth:// URI for $path: " -e uri + echo fi else read -r uri diff --git a/test/insert.t b/test/insert.t index 0c19d11..b4af4f5 100755 --- a/test/insert.t +++ b/test/insert.t @@ -16,9 +16,18 @@ test_expect_success 'Prompts before overwriting key URI' ' uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo" uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar" - test_pass_init && - "$PASS" otp insert "$uri1" passfile && - test_faketty "$PASS" otp insert "$uri2" passfile < <(echo n) && + test_pass_init + "$PASS" otp insert "$uri1" passfile + expect <<EOD + spawn "$PASS" otp insert "$uri2" passfile + expect { + "An entry already exists" { + send "n\r" + exp_continue + } + eof + } +EOD [[ $("$PASS" show passfile) == "$uri1" ]] ' @@ -43,16 +52,38 @@ test_expect_success 'Reads non-terminal input' ' test_expect_success 'Reads terminal input in noecho mode' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" - test_pass_init && - test_faketty "$PASS" otp insert passfile < <(echo -ne "$uri\n$uri\n") && + test_pass_init + expect <<EOD + spawn "$PASS" otp insert passfile + expect { + "Enter" { + send "$uri\r" + exp_continue + } + "Retype" { + send "$uri\r" + exp_continue + } + eof + } +EOD [[ $("$PASS" show passfile) == "$uri" ]] ' test_expect_success 'Reads terminal input in echo mode' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" - test_pass_init && - test_faketty "$PASS" otp insert -e passfile <<< "$uri" && + test_pass_init + expect <<EOD + spawn "$PASS" otp insert -e passfile + expect { + "Enter" { + send "$uri\r" + exp_continue + } + eof + } +EOD [[ $("$PASS" show passfile) == "$uri" ]] ' diff --git a/test/setup.sh b/test/setup.sh index b363e6d..f407164 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # This file should be sourced by all test-scripts # # This scripts sets the following: @@ -65,7 +67,3 @@ test_pass_init() { rm -rf "$PASSWORD_STORE_DIR" "$PASS" init "$KEY1" } - -test_faketty() { - script -qfc "$(printf "%q " "$@")" -} |