diff options
-rwxr-xr-x | otp.bash | 8 | ||||
-rwxr-xr-x | test/code.t | 10 |
2 files changed, 14 insertions, 4 deletions
@@ -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 <<EOF foo bar baz zab rab oof -$uri1 +$uri baz bar foo EOF read -r -d "" expected <<EOF foo bar baz zab rab oof -$uri2 +$inc baz bar foo EOF |