From b8009511b32a5d502148ad8a8397c9cfd7c75a40 Mon Sep 17 00:00:00 2001 From: Osamu Matsumoto Date: Mon, 22 Jan 2018 06:23:32 +0900 Subject: Add secret option (#43) * Support insert/append secret directly * Validate issuer and accout name option in secret directly mode * Add test for secret option * Fix up docs --- test/append.t | 11 +++++++++++ test/insert.t | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'test') diff --git a/test/append.t b/test/append.t index bba3c60..7f6d0af 100755 --- a/test/append.t +++ b/test/append.t @@ -14,6 +14,17 @@ test_expect_success 'Reads non-terminal input' ' [[ $("$PASS" otp uri passfile) == "$uri" ]] ' +test_expect_success 'Read secret non-terminal input' ' + existing="foo bar baz" + secret=JBSWY3DPEHPK3PXP + uri="otpauth://totp/Example:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" + + test_pass_init && + "$PASS" insert -e passfile <<< "$existing" && + "$PASS" otp append -s -i Example -a alice@google.com -e passfile <<< "$secret" && + [[ $("$PASS" otp uri passfile) == "$uri" ]] +' + test_expect_success 'Reads terminal input in noecho mode' ' existing="foo bar baz" uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" diff --git a/test/insert.t b/test/insert.t index e0d2441..1c8ddb2 100755 --- a/test/insert.t +++ b/test/insert.t @@ -112,4 +112,22 @@ test_expect_success 'Force overwrites key URI' ' [[ $("$PASS" show passfile) == "$uri2" ]] ' +test_expect_success 'Insert passfile from secret with options(issuer, accountname)' ' + secret="JBSWY3DPEHPK3PXP" + uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" + + test_pass_init && + "$PASS" otp insert -s -i Example -a alice@google.com passfile <<< "$secret" && + echo [[ $("$PASS" show passfile) == "$uri" ]] +' + +test_expect_success 'Insert from secret without passfile' ' + secret="JBSWY3DPEHPK3PXP" + uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" + + test_pass_init && + "$PASS" otp insert -s -i Example -a alice@google.com <<< "$secret" && + echo [[ $("$PASS" show Example/alice@google.com) == "$uri" ]] +' + test_done -- cgit v1.2.3 From c6da46e99c679eaad18772ce2693811e918ae57b Mon Sep 17 00:00:00 2001 From: Philip Rinn Date: Sat, 3 Mar 2018 23:05:17 +0100 Subject: Remove gnupg/random_seed on clean (#52) --- test/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/Makefile b/test/Makefile index 39f1df2..45882e7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -47,6 +47,7 @@ clean-except-prove-cache: clean: clean-except-prove-cache $(RM) .prove + $(RM) gnupg/random_seed aggregate-results-and-cleanup: $(T) $(MAKE) aggregate-results -- cgit v1.2.3 From 948c2f04cbaf2f065b0c21b80de82f1f0c946e54 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Sun, 4 Mar 2018 11:23:14 -0800 Subject: Fail for `otp code` on missing secret (#46) --- otp.bash | 8 ++++++-- test/code.t | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/otp.bash b/otp.bash index f0f4d0d..447af1e 100755 --- a/otp.bash +++ b/otp.bash @@ -304,7 +304,7 @@ cmd_otp_code() { local path="${1%/}" local passfile="$PREFIX/$path.gpg" check_sneaky_paths "$path" - [[ ! -f $passfile ]] && die "Passfile not found" + [[ ! -f $passfile ]] && die "$path: passfile not found." contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile") while read -r -a line; do @@ -330,9 +330,13 @@ cmd_otp_code() { [[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits" cmd+=" $otp_secret" ;; + + *) + die "$path: OTP secret not found." + ;; esac - local out; out=$($cmd) || die "Failed to generate OTP code for $path" + local out; out=$($cmd) || die "$path: failed to generate OTP code." if [[ "$otp_type" == "hotp" ]]; then # Increment HOTP counter in-place diff --git a/test/code.t b/test/code.t index 02bd086..39310fb 100755 --- a/test/code.t +++ b/test/code.t @@ -4,6 +4,12 @@ export test_description='Tests pass otp code generation' . ./setup.sh +test_expect_success 'Fails for missing secret' ' + test_pass_init && + "$PASS" insert passfile <<< "12345" + test_expect_code 1 pass otp passfile +' + test_expect_success 'Generates TOTP code' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" @@ -31,14 +37,14 @@ test_expect_success 'HOTP counter increments and preserves multiline contents' ' read -r -d "" existing <