((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))
`((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)
(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")))))
(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"))))))))