]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix auth-source-pass to search for hostname:port/username
authorKeith Amidon <camalot@picnicpark.org>
Thu, 14 Feb 2019 18:27:31 +0000 (10:27 -0800)
committerDamien Cassou <damien@cassou.me>
Mon, 24 Jun 2019 07:15:40 +0000 (09:15 +0200)
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
test/lisp/auth-source-pass-tests.el

index 626dbf842c11d979ed2f58bb7cac0e16031beb28..4aa0853be9434d14af517bd47495216bb278897a 100644 (file)
@@ -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))
index ae7a696bc6648571acad6bf9e736418eed76544c..1539d9611f6817f0a930beec9c2cbba6cefd5a71 100644 (file)
@@ -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)