diff --git a/modules/tools/password-store/autoload.el b/modules/tools/password-store/autoload.el index 7f2f3279b..6705fa6a8 100644 --- a/modules/tools/password-store/autoload.el +++ b/modules/tools/password-store/autoload.el @@ -10,14 +10,19 @@ (t (pass)))) +;;;###autoload +(defalias '+pass--get-entry + (if (featurep 'auth-store-pass) + #'auth-source-pass-parse-entry + #'auth-pass-parse-entry)) + ;;;###autoload (defun +pass-get-field (entry fields) - (unless noninteractive - (if-let* ((data (if (listp entry) entry (auth-pass-parse-entry entry)))) - (cl-loop for key in (doom-enlist fields) - when (assoc key data) - return (cdr it)) - (error "Couldn't find entry: %s" entry)))) + (if-let* ((data (if (listp entry) entry (+pass--get-entry entry)))) + (cl-loop for key in (doom-enlist fields) + when (assoc key data) + return (cdr it)) + (error "Couldn't find entry: %s" entry))) ;;;###autoload (defun +pass-get-user (entry) @@ -35,7 +40,7 @@ (error "Username not found."))) (defun +pass-ivy-action--get-field (item) - (let* ((data (auth-pass-parse-entry item)) + (let* ((data (+pass--get-entry item)) (field (if data (completing-read "Field: " (mapcar #'car data) nil t)))) (if data (progn diff --git a/modules/tools/password-store/test/autoload-pass.el b/modules/tools/password-store/test/autoload-pass.el index 33d539259..083c2f0d8 100644 --- a/modules/tools/password-store/test/autoload-pass.el +++ b/modules/tools/password-store/test/autoload-pass.el @@ -1,10 +1,12 @@ ;; -*- no-byte-compile: t; -*- ;;; tools/password-store/test/autoload-pass.el +(load! ../autoload) + (defmacro -with-passwords! (buffer-args &rest body) (declare (indent defun)) `(cl-letf - (((symbol-function 'auth-pass-parse-entry) + (((symbol-function '+pass--get-entry) (lambda (entry) (when (equal entry "fake/source") '((secret . "defuse-account-gad") @@ -17,17 +19,22 @@ ;; (def-test! get-field (-with-passwords! - (should (equal (+pass-get-field "fake/source" "login") - "HL2532-GANDI")) - (should (equal (+pass-get-field "fake/source" "email") - "henrik@lissner.net")) - (should (equal (+pass-get-field "fake/source" '("alt-login" "email")) - "hlissner")) - (should (equal (+pass-get-field "fake/source" '("username" "email")) - "henrik@lissner.net")) - (should-not (+pass-get-field "fake/source" '("x" "y" "z"))) + (should (equal (+pass-get-field "fake/source" "login") + "HL2532-GANDI")) + (should (equal (+pass-get-field "fake/source" "email") + "henrik@lissner.net")) + (should (equal (+pass-get-field "fake/source" '("alt-login" "email")) + "hlissner")) + (should (equal (+pass-get-field "fake/source" '("username" "email")) + "henrik@lissner.net")))) - (should-error (+pass-get-field "nonexistent/source" "login")))) +(def-test! missing-fields-return-nil + (-with-passwords! + (should-not (+pass-get-field "fake/source" '("x" "y" "z"))))) + +(def-test! missing-entries-throw-error + (-with-passwords! + (should-error (+pass-get-field "nonexistent/source" "login")))) (def-test! get-login (-with-passwords!