1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-05 11:45:45 +00:00

Add erc-sasl-auth-source-function to cached options

* lisp/erc/erc-sasl.el (erc-sasl--read-password): Consult cached
options instead of `erc-sasl-auth-source-function'.
(erc-sasl--init): Add `erc-sasl-auth-source-function' to
`erc-sasl--options'.

* test/lisp/erc/erc-sasl-tests.el (erc-sasl--read-password--basic,
erc-sasl--read-password--auth-source): Look for original value of
`erc-sasl-auth-source-function' in `erc-sasl--options' under the
`authfn' key.
This commit is contained in:
F. Jason Park 2022-11-23 21:31:19 -08:00 committed by Amin Bandali
parent 7336520fe7
commit 35e2b8a26b
2 changed files with 22 additions and 19 deletions

View File

@ -137,10 +137,11 @@ PROMPT is passed to `read-passwd' if necessary."
((found (pcase (alist-get 'password erc-sasl--options)
(:password erc-session-password)
((and (pred stringp) v) (unless (string-empty-p v) v))
((and (guard erc-sasl-auth-source-function)
v (let host
(or v (erc-networks--id-given erc-networks--id))))
(apply erc-sasl-auth-source-function
((and (let fn (alist-get 'authfn erc-sasl--options))
(guard fn) v
(let host
(or v (erc-networks--id-given erc-networks--id))))
(apply fn
:user (erc-sasl--get-user)
(and host (list :host (symbol-name host))))))))
(copy-sequence (erc--unfun found))
@ -293,6 +294,7 @@ PROMPT is passed to `read-passwd' if necessary."
`((user . ,erc-sasl-user)
(password . ,erc-sasl-password)
(mechanism . ,erc-sasl-mechanism)
(authfn . ,erc-sasl-auth-source-function)
(authzid . ,erc-sasl-authzid)))))
(defun erc-sasl--mechanism-offered-p (offered)

View File

@ -42,17 +42,17 @@
(erc-sasl--options '((password . :password))))
(should (string= (erc-sasl--read-password nil) "foo"))))
(ert-info ("Fallback to prompt skip auth-source")
(should-not erc-sasl-auth-source-function)
(let ((erc-session-password "bar")
(erc-networks--id (erc-networks--id-create nil)))
(ert-info ("Prompt when no authfn and :password resolves to nil")
(let ((erc-session-password nil)
(erc-sasl--options
'((password . :password) (user . :user) (authfn))))
(should (string= (ert-simulate-keys "bar\r"
(erc-sasl--read-password "?"))
"bar"))))
(ert-info ("Prompt when auth-source fails and `erc-sasl-password' null")
(let ((erc-sasl--options '((password)))
(erc-sasl-auth-source-function #'ignore))
(ert-info ("Prompt when auth-source fails and `erc-session-password' null")
(should-not erc-session-password)
(let ((erc-sasl--options '((password) (authfn . ignore))))
(should (string= (ert-simulate-keys "baz\r"
(erc-sasl--read-password "pwd:"))
"baz")))))
@ -71,36 +71,37 @@
(erc-session-port 6697)
(erc-networks--id (erc-networks--id-create nil))
calls
(erc-sasl-auth-source-function
(lambda (&rest r)
(push r calls)
(apply #'erc--auth-source-search r)))
(fn (lambda (&rest r)
(push r calls)
(apply #'erc-auth-source-search r)))
erc-server-announced-name ; too early
auth-source-do-cache)
(ert-info ("Symbol as password specifies machine")
(let ((erc-sasl--options '((user . "bob") (password . FSF.chat)))
(let ((erc-sasl--options
`((user . "bob") (password . FSF.chat) (authfn . ,fn)))
(erc-networks--id (make-erc-networks--id)))
(should (string= (erc-sasl--read-password nil) "sesame"))
(should (equal (pop calls) '(:user "bob" :host "FSF.chat")))))
(ert-info ("ID for :host and `erc-session-username' for :user") ; *1
(let ((erc-session-username "bob")
(erc-sasl--options '((user . :user) (password)))
(erc-sasl--options `((user . :user) (password) (authfn . ,fn)))
(erc-networks--id (erc-networks--id-create 'GNU/chat)))
(should (string= (erc-sasl--read-password nil) "spam"))
(should (equal (pop calls) '(:user "bob" :host "GNU/chat")))))
(ert-info ("ID for :host and current nick for :user") ; *1
(let ((erc-server-current-nick "bob")
(erc-sasl--options '((user . :nick) (password)))
(erc-sasl--options `((user . :nick) (password) (authfn . ,fn)))
(erc-networks--id (erc-networks--id-create 'GNU/chat)))
(should (string= (erc-sasl--read-password nil) "spam"))
(should (equal (pop calls) '(:user "bob" :host "GNU/chat")))))
(ert-info ("Symbol as password, entry lacks user field")
(let ((erc-server-current-nick "fake")
(erc-sasl--options '((user . :nick) (password . MyHost)))
(erc-sasl--options
`((user . :nick) (password . MyHost) (authfn . ,fn)))
(erc-networks--id (erc-networks--id-create 'GNU/chat)))
(should (string= (erc-sasl--read-password nil) "123"))
(should (equal (pop calls) '(:user "fake" :host "MyHost"))))))))