aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2022-11-23 21:31:19 -0800
committerAmin Bandali2022-11-28 23:56:04 -0500
commit35e2b8a26be06ac1e563801eeb2193c57fd1189d (patch)
treefa180ea6e783e816f54700b1153f50c0cb506fbd
parent7336520fe774f7f7f5209c884e04911514bae796 (diff)
downloademacs-35e2b8a26be06ac1e563801eeb2193c57fd1189d.tar.gz
emacs-35e2b8a26be06ac1e563801eeb2193c57fd1189d.zip
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.
-rw-r--r--lisp/erc/erc-sasl.el10
-rw-r--r--test/lisp/erc/erc-sasl-tests.el31
2 files changed, 22 insertions, 19 deletions
diff --git a/lisp/erc/erc-sasl.el b/lisp/erc/erc-sasl.el
index 9084d873ce4..5ee7169de5f 100644
--- a/lisp/erc/erc-sasl.el
+++ b/lisp/erc/erc-sasl.el
@@ -137,10 +137,11 @@ PROMPT is passed to `read-passwd' if necessary."
137 ((found (pcase (alist-get 'password erc-sasl--options) 137 ((found (pcase (alist-get 'password erc-sasl--options)
138 (:password erc-session-password) 138 (:password erc-session-password)
139 ((and (pred stringp) v) (unless (string-empty-p v) v)) 139 ((and (pred stringp) v) (unless (string-empty-p v) v))
140 ((and (guard erc-sasl-auth-source-function) 140 ((and (let fn (alist-get 'authfn erc-sasl--options))
141 v (let host 141 (guard fn) v
142 (or v (erc-networks--id-given erc-networks--id)))) 142 (let host
143 (apply erc-sasl-auth-source-function 143 (or v (erc-networks--id-given erc-networks--id))))
144 (apply fn
144 :user (erc-sasl--get-user) 145 :user (erc-sasl--get-user)
145 (and host (list :host (symbol-name host)))))))) 146 (and host (list :host (symbol-name host))))))))
146 (copy-sequence (erc--unfun found)) 147 (copy-sequence (erc--unfun found))
@@ -293,6 +294,7 @@ PROMPT is passed to `read-passwd' if necessary."
293 `((user . ,erc-sasl-user) 294 `((user . ,erc-sasl-user)
294 (password . ,erc-sasl-password) 295 (password . ,erc-sasl-password)
295 (mechanism . ,erc-sasl-mechanism) 296 (mechanism . ,erc-sasl-mechanism)
297 (authfn . ,erc-sasl-auth-source-function)
296 (authzid . ,erc-sasl-authzid))))) 298 (authzid . ,erc-sasl-authzid)))))
297 299
298(defun erc-sasl--mechanism-offered-p (offered) 300(defun erc-sasl--mechanism-offered-p (offered)
diff --git a/test/lisp/erc/erc-sasl-tests.el b/test/lisp/erc/erc-sasl-tests.el
index 64593ca270c..3e6828ff644 100644
--- a/test/lisp/erc/erc-sasl-tests.el
+++ b/test/lisp/erc/erc-sasl-tests.el
@@ -42,17 +42,17 @@
42 (erc-sasl--options '((password . :password)))) 42 (erc-sasl--options '((password . :password))))
43 (should (string= (erc-sasl--read-password nil) "foo")))) 43 (should (string= (erc-sasl--read-password nil) "foo"))))
44 44
45 (ert-info ("Fallback to prompt skip auth-source") 45 (ert-info ("Prompt when no authfn and :password resolves to nil")
46 (should-not erc-sasl-auth-source-function) 46 (let ((erc-session-password nil)
47 (let ((erc-session-password "bar") 47 (erc-sasl--options
48 (erc-networks--id (erc-networks--id-create nil))) 48 '((password . :password) (user . :user) (authfn))))
49 (should (string= (ert-simulate-keys "bar\r" 49 (should (string= (ert-simulate-keys "bar\r"
50 (erc-sasl--read-password "?")) 50 (erc-sasl--read-password "?"))
51 "bar")))) 51 "bar"))))
52 52
53 (ert-info ("Prompt when auth-source fails and `erc-sasl-password' null") 53 (ert-info ("Prompt when auth-source fails and `erc-session-password' null")
54 (let ((erc-sasl--options '((password))) 54 (should-not erc-session-password)
55 (erc-sasl-auth-source-function #'ignore)) 55 (let ((erc-sasl--options '((password) (authfn . ignore))))
56 (should (string= (ert-simulate-keys "baz\r" 56 (should (string= (ert-simulate-keys "baz\r"
57 (erc-sasl--read-password "pwd:")) 57 (erc-sasl--read-password "pwd:"))
58 "baz"))))) 58 "baz")))))
@@ -71,36 +71,37 @@
71 (erc-session-port 6697) 71 (erc-session-port 6697)
72 (erc-networks--id (erc-networks--id-create nil)) 72 (erc-networks--id (erc-networks--id-create nil))
73 calls 73 calls
74 (erc-sasl-auth-source-function 74 (fn (lambda (&rest r)
75 (lambda (&rest r) 75 (push r calls)
76 (push r calls) 76 (apply #'erc-auth-source-search r)))
77 (apply #'erc--auth-source-search r)))
78 erc-server-announced-name ; too early 77 erc-server-announced-name ; too early
79 auth-source-do-cache) 78 auth-source-do-cache)
80 79
81 (ert-info ("Symbol as password specifies machine") 80 (ert-info ("Symbol as password specifies machine")
82 (let ((erc-sasl--options '((user . "bob") (password . FSF.chat))) 81 (let ((erc-sasl--options
82 `((user . "bob") (password . FSF.chat) (authfn . ,fn)))
83 (erc-networks--id (make-erc-networks--id))) 83 (erc-networks--id (make-erc-networks--id)))
84 (should (string= (erc-sasl--read-password nil) "sesame")) 84 (should (string= (erc-sasl--read-password nil) "sesame"))
85 (should (equal (pop calls) '(:user "bob" :host "FSF.chat"))))) 85 (should (equal (pop calls) '(:user "bob" :host "FSF.chat")))))
86 86
87 (ert-info ("ID for :host and `erc-session-username' for :user") ; *1 87 (ert-info ("ID for :host and `erc-session-username' for :user") ; *1
88 (let ((erc-session-username "bob") 88 (let ((erc-session-username "bob")
89 (erc-sasl--options '((user . :user) (password))) 89 (erc-sasl--options `((user . :user) (password) (authfn . ,fn)))
90 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 90 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
91 (should (string= (erc-sasl--read-password nil) "spam")) 91 (should (string= (erc-sasl--read-password nil) "spam"))
92 (should (equal (pop calls) '(:user "bob" :host "GNU/chat"))))) 92 (should (equal (pop calls) '(:user "bob" :host "GNU/chat")))))
93 93
94 (ert-info ("ID for :host and current nick for :user") ; *1 94 (ert-info ("ID for :host and current nick for :user") ; *1
95 (let ((erc-server-current-nick "bob") 95 (let ((erc-server-current-nick "bob")
96 (erc-sasl--options '((user . :nick) (password))) 96 (erc-sasl--options `((user . :nick) (password) (authfn . ,fn)))
97 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 97 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
98 (should (string= (erc-sasl--read-password nil) "spam")) 98 (should (string= (erc-sasl--read-password nil) "spam"))
99 (should (equal (pop calls) '(:user "bob" :host "GNU/chat"))))) 99 (should (equal (pop calls) '(:user "bob" :host "GNU/chat")))))
100 100
101 (ert-info ("Symbol as password, entry lacks user field") 101 (ert-info ("Symbol as password, entry lacks user field")
102 (let ((erc-server-current-nick "fake") 102 (let ((erc-server-current-nick "fake")
103 (erc-sasl--options '((user . :nick) (password . MyHost))) 103 (erc-sasl--options
104 `((user . :nick) (password . MyHost) (authfn . ,fn)))
104 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 105 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
105 (should (string= (erc-sasl--read-password nil) "123")) 106 (should (string= (erc-sasl--read-password nil) "123"))
106 (should (equal (pop calls) '(:user "fake" :host "MyHost")))))))) 107 (should (equal (pop calls) '(:user "fake" :host "MyHost"))))))))