mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-10 00:00:39 -08:00
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.
This commit is contained in:
parent
a63cbb56df
commit
2a0a05789d
2 changed files with 25 additions and 3 deletions
|
|
@ -49,6 +49,11 @@
|
||||||
:type 'directory
|
:type 'directory
|
||||||
:version "27.1")
|
:version "27.1")
|
||||||
|
|
||||||
|
(defcustom auth-source-pass-port-separator ":"
|
||||||
|
"Separator string between host and port in entry filename."
|
||||||
|
:type 'string
|
||||||
|
:version "27.1")
|
||||||
|
|
||||||
(cl-defun auth-source-pass-search (&rest spec
|
(cl-defun auth-source-pass-search (&rest spec
|
||||||
&key backend type host user port
|
&key backend type host user port
|
||||||
&allow-other-keys)
|
&allow-other-keys)
|
||||||
|
|
@ -254,9 +259,15 @@ return nil.
|
||||||
|
|
||||||
HOSTNAME should not contain any username or port number."
|
HOSTNAME should not contain any username or port number."
|
||||||
(or
|
(or
|
||||||
(and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user))
|
(and user port (auth-source-pass--find-one-by-entry-name
|
||||||
(and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user))
|
(format "%s@%s%s%s" user hostname auth-source-pass-port-separator port)
|
||||||
(and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil))
|
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)
|
(auth-source-pass--find-one-by-entry-name hostname user)
|
||||||
;; if that didn't work, remove subdomain: foo.bar.com -> bar.com
|
;; if that didn't work, remove subdomain: foo.bar.com -> bar.com
|
||||||
(let ((components (split-string hostname "\\.")))
|
(let ((components (split-string hostname "\\.")))
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,17 @@ This function is intended to be set to `auth-source-debug`."
|
||||||
(should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil)
|
(should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil)
|
||||||
"host.com"))))
|
"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)
|
(defmacro auth-source-pass--with-store-find-foo (store &rest body)
|
||||||
"Use STORE while executing BODY. \"foo\" is the matched entry."
|
"Use STORE while executing BODY. \"foo\" is the matched entry."
|
||||||
(declare (indent 1))
|
(declare (indent 1))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue