2017-06-14 20:26:17 +02:00
|
|
|
;; -*- no-byte-compile: t; -*-
|
|
|
|
;;; tools/password-store/test/autoload-pass.el
|
|
|
|
|
2017-12-10 15:37:01 -05:00
|
|
|
(load! ../autoload)
|
|
|
|
|
2017-12-31 11:45:02 -05:00
|
|
|
(defmacro with-passwords!! (buffer-args &rest body)
|
2017-06-14 20:26:17 +02:00
|
|
|
(declare (indent defun))
|
|
|
|
`(cl-letf
|
2017-12-10 15:37:01 -05:00
|
|
|
(((symbol-function '+pass--get-entry)
|
2017-06-14 20:26:17 +02:00
|
|
|
(lambda (entry)
|
|
|
|
(when (equal entry "fake/source")
|
|
|
|
'((secret . "defuse-account-gad")
|
|
|
|
("login" . "HL2532-GANDI")
|
|
|
|
("alt-login" . "hlissner")
|
|
|
|
("email" . "henrik@lissner.net")
|
|
|
|
("url" . "https://www.gandi.net/login"))))))
|
|
|
|
,@body))
|
|
|
|
|
|
|
|
;;
|
|
|
|
(def-test! get-field
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-passwords!!
|
2017-12-10 15:37:01 -05:00
|
|
|
(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"))))
|
|
|
|
|
|
|
|
(def-test! missing-fields-return-nil
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-passwords!!
|
2017-12-10 15:37:01 -05:00
|
|
|
(should-not (+pass-get-field "fake/source" '("x" "y" "z")))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
2017-12-10 15:37:01 -05:00
|
|
|
(def-test! missing-entries-throw-error
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-passwords!!
|
2017-12-10 15:37:01 -05:00
|
|
|
(should-error (+pass-get-field "nonexistent/source" "login"))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
|
|
|
(def-test! get-login
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-passwords!!
|
2017-06-14 20:26:17 +02:00
|
|
|
(should (equal (+pass-get-user "fake/source") "HL2532-GANDI"))
|
|
|
|
(should (equal (+pass-get-secret "fake/source") "defuse-account-gad"))))
|