From 437845fb314694b2b31b5b128da5b5c7f3eaaf4c Mon Sep 17 00:00:00 2001 From: Keith Amidon Date: Thu, 14 Feb 2019 10:27:31 -0800 Subject: [PATCH 06/13] 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. --- lisp/auth-source-pass.el | 3 +++ test/lisp/auth-source-pass-tests.el | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 4dea6709b9..52ff312369 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -262,6 +262,9 @@ auth-source-pass--find-match-unambiguous (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 ae7a696bc6..1539d9611f 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -144,6 +144,17 @@ auth-source-pass--with-store (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) -- 2.21.0