aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIku Iwasa2019-04-07 17:59:59 +0900
committerDamien Cassou2019-06-24 09:15:40 +0200
commit2a0a05789d4734e4b3d18941346ecda9834e7cc9 (patch)
treee229d71f1d3f97f601a94c1ede4e631435221243
parenta63cbb56dfc6074189407e9e182e807ce058e618 (diff)
downloademacs-2a0a05789d4734e4b3d18941346ecda9834e7cc9.tar.gz
emacs-2a0a05789d4734e4b3d18941346ecda9834e7cc9.zip
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.
-rw-r--r--lisp/auth-source-pass.el17
-rw-r--r--test/lisp/auth-source-pass-tests.el11
2 files changed, 25 insertions, 3 deletions
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index 1fda6982328..626dbf842c1 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -49,6 +49,11 @@
49 :type 'directory 49 :type 'directory
50 :version "27.1") 50 :version "27.1")
51 51
52(defcustom auth-source-pass-port-separator ":"
53 "Separator string between host and port in entry filename."
54 :type 'string
55 :version "27.1")
56
52(cl-defun auth-source-pass-search (&rest spec 57(cl-defun auth-source-pass-search (&rest spec
53 &key backend type host user port 58 &key backend type host user port
54 &allow-other-keys) 59 &allow-other-keys)
@@ -254,9 +259,15 @@ return nil.
254 259
255HOSTNAME should not contain any username or port number." 260HOSTNAME should not contain any username or port number."
256 (or 261 (or
257 (and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user)) 262 (and user port (auth-source-pass--find-one-by-entry-name
258 (and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user)) 263 (format "%s@%s%s%s" user hostname auth-source-pass-port-separator port)
259 (and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil)) 264 user))
265 (and user (auth-source-pass--find-one-by-entry-name
266 (format "%s@%s" user hostname)
267 user))
268 (and port (auth-source-pass--find-one-by-entry-name
269 (format "%s%s%s" hostname auth-source-pass-port-separator port)
270 nil))
260 (auth-source-pass--find-one-by-entry-name hostname user) 271 (auth-source-pass--find-one-by-entry-name hostname user)
261 ;; if that didn't work, remove subdomain: foo.bar.com -> bar.com 272 ;; if that didn't work, remove subdomain: foo.bar.com -> bar.com
262 (let ((components (split-string hostname "\\."))) 273 (let ((components (split-string hostname "\\.")))
diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el
index ab9ef92c144..ae7a696bc66 100644
--- a/test/lisp/auth-source-pass-tests.el
+++ b/test/lisp/auth-source-pass-tests.el
@@ -186,6 +186,17 @@ This function is intended to be set to `auth-source-debug`."
186 (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil) 186 (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil)
187 "host.com")))) 187 "host.com"))))
188 188
189(ert-deftest auth-source-pass-find-host-with-port ()
190 (auth-source-pass--with-store '(("host.com:443"))
191 (should (equal (auth-source-pass--find-match "host.com" "someuser" "443")
192 "host.com:443"))))
193
194(ert-deftest auth-source-pass-find-host-with-custom-port-separator ()
195 (let ((auth-source-pass-port-separator "#"))
196 (auth-source-pass--with-store '(("host.com#443"))
197 (should (equal (auth-source-pass--find-match "host.com" "someuser" "443")
198 "host.com#443")))))
199
189(defmacro auth-source-pass--with-store-find-foo (store &rest body) 200(defmacro auth-source-pass--with-store-find-foo (store &rest body)
190 "Use STORE while executing BODY. \"foo\" is the matched entry." 201 "Use STORE while executing BODY. \"foo\" is the matched entry."
191 (declare (indent 1)) 202 (declare (indent 1))