aboutsummaryrefslogtreecommitdiff
path: root/test/insert.t
diff options
context:
space:
mode:
authorTad Fisher <tadfisher@gmail.com>2017-03-20 10:01:26 -0700
committerGitHub <noreply@github.com>2017-03-20 10:01:26 -0700
commit310322fdeee57330e92afdf0810ac5200163d08d (patch)
tree262111fc810123e3b0123b5e19a0219a54b8639d /test/insert.t
parentdb2baf62a27d5a657d0477d928f21a739981dc46 (diff)
parentd9c681a8fbb70d40e14079e5f1a8b4aaee0b0d08 (diff)
Merge pull request #17 from tadfisher/key-uri
Handle OTP key URIs
Diffstat (limited to 'test/insert.t')
-rwxr-xr-xtest/insert.t87
1 files changed, 79 insertions, 8 deletions
diff --git a/test/insert.t b/test/insert.t
index a78971f..b4af4f5 100755
--- a/test/insert.t
+++ b/test/insert.t
@@ -4,16 +4,87 @@ export test_description="Tests pass otp insert commands"
. ./setup.sh
-test_expect_success 'Inserts a basic TOTP key' '
- "$PASS" init $KEY1 &&
- "$PASS" otp insert totp -s AAAAAAAAAAAAAAAAAAAAA totp-secret
+test_expect_success 'Inserts a key URI' '
+ uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
+
+ test_pass_init &&
+ "$PASS" otp insert "$uri" passfile &&
+ [[ $("$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_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" ]]
+'
+
+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" ]]
'
-test_expect_success 'Commits insert to git' '
- git init "$PASSWORD_STORE_DIR" &&
- "$PASS" init $KEY1 &&
- "$PASS" otp insert totp -s AAAAAAAAAAAAAAAAAAAAA totp-secret2 &&
- git log --no-decorate -1 | grep "Add given OTP secret for totp-secret2 to store."
+test_expect_success 'Reads non-terminal input' '
+ uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
+
+ test_pass_init &&
+ "$PASS" otp insert passfile <<< "$uri" &&
+ [[ $("$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_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
+ expect <<EOD
+ spawn "$PASS" otp insert -e passfile
+ expect {
+ "Enter" {
+ send "$uri\r"
+ exp_continue
+ }
+ eof
+ }
+EOD
+ [[ $("$PASS" show passfile) == "$uri" ]]
'
test_done