mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-03 10:31:37 -08:00
Fix auth-source-pass.el to properly handle special inputs
* lisp/auth-source-pass.el (auth-source-pass-search): Warn when passing multiple hosts in SPEC. Early return and warn when passing a wildcard as host in SPEC. Early return when host is nil. * test/lisp/auth-source-pass-tests.el (auth-source-pass-any-host, auth-source-pass-undefined-host): Add corresponding tests.
This commit is contained in:
parent
b43ed61ef9
commit
1d2551f8e7
2 changed files with 21 additions and 2 deletions
|
|
@ -45,10 +45,18 @@
|
||||||
See `auth-source-search' for details on SPEC."
|
See `auth-source-search' for details on SPEC."
|
||||||
(cl-assert (or (null type) (eq type (oref backend type)))
|
(cl-assert (or (null type) (eq type (oref backend type)))
|
||||||
t "Invalid password-store search: %s %s")
|
t "Invalid password-store search: %s %s")
|
||||||
(when (listp host)
|
(when (consp host)
|
||||||
|
(warn "auth-source-pass ignores all but first host in spec.")
|
||||||
;; Take the first non-nil item of the list of hosts
|
;; Take the first non-nil item of the list of hosts
|
||||||
(setq host (seq-find #'identity host)))
|
(setq host (seq-find #'identity host)))
|
||||||
(list (auth-source-pass--build-result host port user)))
|
(cond ((eq host t)
|
||||||
|
(warn "auth-source-pass does not handle host wildcards.")
|
||||||
|
nil)
|
||||||
|
((null host)
|
||||||
|
;; Do not build a result, as none will match when HOST is nil
|
||||||
|
nil)
|
||||||
|
(t
|
||||||
|
(list (auth-source-pass--build-result host port user)))))
|
||||||
|
|
||||||
(defun auth-source-pass--build-result (host port user)
|
(defun auth-source-pass--build-result (host port user)
|
||||||
"Build auth-source-pass entry matching HOST, PORT and USER."
|
"Build auth-source-pass entry matching HOST, PORT and USER."
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,17 @@ This function is intended to be set to `auth-source-debug`."
|
||||||
(auth-source-pass--debug-log nil))
|
(auth-source-pass--debug-log nil))
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
|
(ert-deftest auth-source-pass-any-host ()
|
||||||
|
(auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user"))
|
||||||
|
("bar"))
|
||||||
|
(should-not (auth-source-pass-search :host t))))
|
||||||
|
|
||||||
|
(ert-deftest auth-source-pass-undefined-host ()
|
||||||
|
(auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user"))
|
||||||
|
("bar"))
|
||||||
|
(should-not (auth-source-pass-search :host nil))))
|
||||||
|
|
||||||
|
|
||||||
(ert-deftest auth-source-pass-find-match-matching-at-entry-name ()
|
(ert-deftest auth-source-pass-find-match-matching-at-entry-name ()
|
||||||
(auth-source-pass--with-store '(("foo"))
|
(auth-source-pass--with-store '(("foo"))
|
||||||
(should (equal (auth-source-pass--find-match "foo" nil nil)
|
(should (equal (auth-source-pass--find-match "foo" nil nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue