Support numeric port numbers in auth-source-macos-keychain
* lisp/auth-source.el (auth-source-macos-keychain-search): Support numeric port numbers (bug#68376). (auth-source-macos-keychain-search-items): Make regexp more robust. * test/lisp/auth-source-tests.el (test-macos-keychain-search): Extend test.
This commit is contained in:
parent
c7aa5c6d2b
commit
ef08f94cbe
2 changed files with 26 additions and 16 deletions
|
@ -1946,18 +1946,20 @@ entries for git.gnus.org:
|
|||
(returned-keys (delete-dups (append
|
||||
'(:host :login :port :secret)
|
||||
search-keys)))
|
||||
;; Extract host and port from spec
|
||||
;; Extract host, port and user from spec
|
||||
(hosts (plist-get spec :host))
|
||||
(hosts (if (and hosts (listp hosts)) hosts `(,hosts)))
|
||||
(hosts (if (consp hosts) hosts `(,hosts)))
|
||||
(ports (plist-get spec :port))
|
||||
(ports (if (and ports (listp ports)) ports `(,ports)))
|
||||
(ports (if (consp ports) ports `(,ports)))
|
||||
(users (plist-get spec :user))
|
||||
(users (if (and users (listp users)) users `(,users)))
|
||||
(users (if (consp users) users `(,users)))
|
||||
;; Loop through all combinations of host/port and pass each of these to
|
||||
;; auth-source-macos-keychain-search-items
|
||||
;; auth-source-macos-keychain-search-items. Convert numeric port to
|
||||
;; string (bug#68376).
|
||||
(items (catch 'match
|
||||
(dolist (host hosts)
|
||||
(dolist (port ports)
|
||||
(when (numberp port) (setq port (number-to-string port)))
|
||||
(dolist (user users)
|
||||
(let ((items (apply
|
||||
#'auth-source-macos-keychain-search-items
|
||||
|
@ -2019,7 +2021,7 @@ entries for git.gnus.org:
|
|||
(when port
|
||||
(if keychain-generic
|
||||
(setq args (append args (list "-s" port)))
|
||||
(setq args (append args (if (string-match "[0-9]+" port)
|
||||
(setq args (append args (if (string-match-p "\\`[[:digit:]]+\\'" port)
|
||||
(list "-P" port)
|
||||
(list "-r" (substring
|
||||
(format "%-4s" port)
|
||||
|
|
|
@ -442,18 +442,26 @@ machine c1 port c2 user c3 password c4\n"
|
|||
(cl-letf (((symbol-function 'call-process)
|
||||
(lambda (_program _infile _destination _display
|
||||
&rest args)
|
||||
;; Arguments must be all strings
|
||||
;; Arguments must be all strings.
|
||||
(should (cl-every #'stringp args))
|
||||
;; Argument number should be even
|
||||
;; Argument number should be even.
|
||||
(should (cl-evenp (length args)))
|
||||
(should (cond ((string= (car args) "find-internet-password")
|
||||
(let ((protocol (cl-member "-r" args :test #'string=)))
|
||||
(if protocol
|
||||
(= 4 (length (cadr protocol)))
|
||||
t)))
|
||||
((string= (car args) "find-generic-password")
|
||||
t))))))
|
||||
(auth-source-search :user '("a" "b") :host '("example.org") :port '("irc" "ftp" "https")))))
|
||||
(should
|
||||
(cond
|
||||
((string= (car args) "find-internet-password")
|
||||
(let ((protocol-r (cl-member "-r" args :test #'string=))
|
||||
(protocol-P (cl-member "-P" args :test #'string=)))
|
||||
(cond (protocol-r
|
||||
(= 4 (length (cadr protocol-r))))
|
||||
(protocol-P
|
||||
(string-match-p
|
||||
"\\`[[:digit:]]+\\'" (cadr protocol-P)))
|
||||
(t))))
|
||||
((string= (car args) "find-generic-password")
|
||||
t))))))
|
||||
(auth-source-search
|
||||
:user '("a" "b") :host '("example.org")
|
||||
:port '("irc" "ftp" "https" 123)))))
|
||||
|
||||
(provide 'auth-source-tests)
|
||||
;;; auth-source-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue