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/insert.t | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'test/insert.t') diff --git a/test/insert.t b/test/insert.t index a78971f..e04914e 100755 --- a/test/insert.t +++ b/test/insert.t @@ -4,16 +4,44 @@ export test_description="Tests pass otp insert commands" . ./setup.sh +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 && + test_faketty "echo n | $PASS otp insert $uri2 passfile" && + [[ $("$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 'Inserts a basic TOTP key' ' - "$PASS" init $KEY1 && - "$PASS" otp insert totp -s AAAAAAAAAAAAAAAAAAAAA totp-secret + test_pass_init && + "$PASS" otp insert totp -s AAAAAAAAAAAAAAAAAAAAA passfile ' 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_pass_init && + pass git init && + "$PASS" otp insert totp -s AAAAAAAAAAAAAAAAAAAAA passfile && + git log --no-decorate -1 | grep "Add given OTP secret for passfile to store." ' test_done -- cgit v1.2.3