diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/code.t | 4 | ||||
-rwxr-xr-x | test/insert.t | 91 | ||||
-rwxr-xr-x | test/uri.t | 2 |
3 files changed, 61 insertions, 36 deletions
diff --git a/test/code.t b/test/code.t index 095cdd5..4faea03 100755 --- a/test/code.t +++ b/test/code.t @@ -8,7 +8,7 @@ test_expect_success 'Generates TOTP code' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && - "$PASS" otp insert "$uri" passfile && + "$PASS" otp insert passfile <<< "$uri" && code=$("$PASS" otp passfile) && [[ ${#code} -eq 6 ]] ' @@ -18,7 +18,7 @@ test_expect_success 'Generates HOTP code and increments counter' ' inc="otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=11&issuer=Example" test_pass_init && - "$PASS" otp insert "$uri" passfile && + "$PASS" otp insert passfile <<< "$uri" && code=$("$PASS" otp passfile) && [[ ${#code} -eq 6 ]] && [[ $("$PASS" otp uri passfile) == "$inc" ]] diff --git a/test/insert.t b/test/insert.t index b4af4f5..e0d2441 100755 --- a/test/insert.t +++ b/test/insert.t @@ -4,87 +4,112 @@ export test_description="Tests pass otp insert commands" . ./setup.sh -test_expect_success 'Inserts a key URI' ' +test_expect_success 'Reads non-terminal input' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && - "$PASS" otp insert "$uri" passfile && + "$PASS" otp insert passfile <<< "$uri" && [[ $("$PASS" show passfile) == "$uri" ]] ' -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_expect_success 'Reads terminal input in noecho mode' ' + uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init - "$PASS" otp insert "$uri1" passfile expect <<EOD - spawn "$PASS" otp insert "$uri2" passfile + spawn "$PASS" otp insert passfile expect { - "An entry already exists" { - send "n\r" + "Enter" { + send "$uri\r" + exp_continue + } + "Retype" { + send "$uri\r" exp_continue } eof } EOD - [[ $("$PASS" show passfile) == "$uri1" ]] -' - -test_expect_success 'Force overwrites 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 && - "$PASS" otp insert -f "$uri2" passfile && - [[ $("$PASS" show passfile) == "$uri2" ]] + [[ $("$PASS" show passfile) == "$uri" ]] ' -test_expect_success 'Reads non-terminal input' ' +test_expect_success 'Reads terminal input in echo mode' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" - test_pass_init && - "$PASS" otp insert 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" ]] ' -test_expect_success 'Reads terminal input in noecho mode' ' - uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" +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 passfile <<< "$uri1" || return 1 expect <<EOD - spawn "$PASS" otp insert passfile + spawn "$PASS" otp insert -e passfile expect { "Enter" { - send "$uri\r" + send "$uri2\r" exp_continue } - "Retype" { - send "$uri\r" + "An entry already exists" { + send "n\r" exp_continue } eof } EOD - [[ $("$PASS" show passfile) == "$uri" ]] + [[ $("$PASS" show passfile) == "$uri1" ]] ' -test_expect_success 'Reads terminal input in echo mode' ' +test_expect_success 'Generates default pass-name from label' ' + uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" + + test_pass_init + "$PASS" otp insert <<< "$uri" + [[ $("$PASS" show "Example/alice@google.com") == "$uri" ]] +' + +test_expect_success 'Prompts when inserting default pass-name from terminal' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init expect <<EOD - spawn "$PASS" otp insert -e passfile + spawn "$PASS" otp insert -e expect { "Enter" { send "$uri\r" exp_continue } + "Insert into Example/alice@google.com?" { + send "y\r" + exp_continue + } eof } EOD - [[ $("$PASS" show passfile) == "$uri" ]] + [[ $("$PASS" show "Example/alice@google.com") == "$uri" ]] +' + +test_expect_success 'Force overwrites 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 passfile <<< "$uri1" && + "$PASS" otp insert -f passfile <<< "$uri2" && + [[ $("$PASS" show passfile) == "$uri2" ]] ' test_done @@ -8,7 +8,7 @@ test_expect_success 'Shows key URI in single-line passfile' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && - "$PASS" otp insert "$uri" passfile && + "$PASS" otp insert passfile <<< "$uri" && [[ $("$PASS" otp uri passfile) == "$uri" ]] ' |