From 72373e86cea699c5fb69cfff436e390186cc9e4e Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Sat, 18 Mar 2017 18:20:28 -0700 Subject: Add cmd_insert_uri; refactor tests --- test/setup.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/setup.sh') diff --git a/test/setup.sh b/test/setup.sh index f896382..b363e6d 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -33,12 +33,6 @@ export PASSWORD_STORE_ENABLE_EXTENSIONS=true export PASSWORD_STORE_EXTENSIONS_DIR="$EXT_HOME" export PASSWORD_STORE_DIR="$SHARNESS_TRASH_DIRECTORY/test-store" -rm -rf "$PASSWORD_STORE_DIR" -mkdir -p "$PASSWORD_STORE_DIR" -if [[ ! -d $PASSWORD_STORE_DIR ]]; then - echo "Could not create $PASSWORD_STORE_DIR" - exit 1 -fi export GIT_DIR="$PASSWORD_STORE_DIR/.git" export GIT_WORK_TREE="$PASSWORD_STORE_DIR" @@ -65,3 +59,13 @@ KEY2="D774A374" # pass test key 2 KEY3="EB7D54A8" # pass test key 3 KEY4="E4691410" # pass test key 4 KEY5="39E5020C" # pass test key 5 + +# Test helpers +test_pass_init() { + rm -rf "$PASSWORD_STORE_DIR" + "$PASS" init "$KEY1" +} + +test_faketty() { + script -qfc "$(printf "%q " "$@")" +} -- cgit v1.2.3 From 224c4dc57ee42215806c6fb8b92e64ddebaa7fd7 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Sun, 19 Mar 2017 23:48:03 -0700 Subject: Use expect for interactive tests --- .travis.yml | 1 + otp.bash | 14 ++++++-------- test/insert.t | 45 ++++++++++++++++++++++++++++++++++++++------- test/setup.sh | 6 ++---- 4 files changed, 47 insertions(+), 19 deletions(-) (limited to 'test/setup.sh') 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 diff --git a/otp.bash b/otp.bash index 8b80554..91661d8 100755 --- a/otp.bash +++ b/otp.bash @@ -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 <