>From f2107a0c03b2aa0421d5ee4e7ccc74c7cfd4371c Mon Sep 17 00:00:00 2001 From: Iku Iwasa Date: Sun, 7 Apr 2019 17:59:59 +0900 Subject: [PATCH 05/12] Add auth-source-pass-port-separator option * lisp/auth-source-pass.el (auth-source-pass-port-separator): New option to specify separator between host and port, default to colon (":"). (auth-source-pass--find-match-unambiguous): Adapt to make use of the new variable. * test/lisp/auth-source-pass-tests.el: Add corresponding tests. --- lisp/auth-source-pass.el | 16 +++++++++++++--- test/lisp/auth-source-pass-tests.el | 11 +++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index a029946f6c..e80149900b 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -47,6 +47,10 @@ auth-source-pass-path "Path to the password-store folder." :type 'directory) +(defcustom auth-source-pass-port-separator ":" + "Separator string between host and port in entry filename." + :type 'string) + (cl-defun auth-source-pass-search (&rest spec &key backend type host user port &allow-other-keys) @@ -252,9 +256,15 @@ auth-source-pass--find-match-unambiguous HOSTNAME should not contain any username or port number." (or - (and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user)) - (and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user)) - (and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil)) + (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 (auth-source-pass--find-one-by-entry-name + (format "%s@%s" user hostname) + user)) + (and port (auth-source-pass--find-one-by-entry-name + (format "%s%s%s" hostname auth-source-pass-port-separator port) + nil)) (auth-source-pass--find-one-by-entry-name hostname user) ;; if that didn't work, remove subdomain: foo.bar.com -> bar.com (let ((components (split-string hostname "\\."))) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index ab9ef92c14..ae7a696bc6 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -186,6 +186,17 @@ auth-source-pass--with-store (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil) "host.com")))) +(ert-deftest auth-source-pass-find-host-with-port () + (auth-source-pass--with-store '(("host.com:443")) + (should (equal (auth-source-pass--find-match "host.com" "someuser" "443") + "host.com:443")))) + +(ert-deftest auth-source-pass-find-host-with-custom-port-separator () + (let ((auth-source-pass-port-separator "#")) + (auth-source-pass--with-store '(("host.com#443")) + (should (equal (auth-source-pass--find-match "host.com" "someuser" "443") + "host.com#443"))))) + (defmacro auth-source-pass--with-store-find-foo (store &rest body) "Use STORE while executing BODY. \"foo\" is the matched entry." (declare (indent 1)) -- 2.21.0