From: Keith Amidon Date: Thu, 14 Feb 2019 18:27:31 +0000 (-0800) Subject: Fix auth-source-pass to search for hostname:port/username X-Git-Tag: emacs-27.0.90~2283 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=94c9eb81b8b265380345c36c0a481d9022435d89;p=emacs.git Fix auth-source-pass to search for hostname:port/username auth-source-pass supports entries with username either prefixed to the hostname with an @ as separator or in a subdirectory under the hostname. This was true when there was no port or service included in the name, but got broken with the introduction of auth-source-pass-port-separator. * lisp/auth-source-pass.el (auth-source-pass--find-match-unambiguous): Fix to match hostname:port/username. * test/lisp/auth-source-pass-tests.el: Add corresponding tests. --- diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 626dbf842c1..4aa0853be94 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -262,6 +262,9 @@ HOSTNAME should not contain any username or port number." (and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s%s%s" user hostname auth-source-pass-port-separator port) user)) + (and user port (auth-source-pass--find-one-by-entry-name + (format "%s%s%s" hostname auth-source-pass-port-separator port) + user)) (and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user)) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index ae7a696bc66..1539d9611f6 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -144,6 +144,17 @@ This function is intended to be set to `auth-source-debug`." (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) nil)))) +(ert-deftest auth-source-pass-find-match-matching-host-port-and-subdir-user () + (auth-source-pass--with-store '(("bar.com:443/someone")) + (should (equal (auth-source-pass--find-match "bar.com" "someone" "443") + "bar.com:443/someone")))) + +(ert-deftest auth-source-pass-find-match-matching-host-port-and-subdir-user-with-custom-separator () + (let ((auth-source-pass-port-separator "#")) + (auth-source-pass--with-store '(("bar.com#443/someone")) + (should (equal (auth-source-pass--find-match "bar.com" "someone" "443") + "bar.com#443/someone"))))) + (ert-deftest auth-source-pass-find-match-matching-extracting-user-from-host () (auth-source-pass--with-store '(("foo.com/bar")) (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil nil)