aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2022-11-23 21:31:19 -0800
committerAmin Bandali2022-11-29 00:01:13 -0500
commit00de296d1b4f629fd828cdeff588bb4f742d9ffe (patch)
tree7b791016be2034d15c749ab0206957a164cbc389 /test
parent83b9496a193c41ed7e41b36838727e234c81a2d1 (diff)
downloademacs-00de296d1b4f629fd828cdeff588bb4f742d9ffe.tar.gz
emacs-00de296d1b4f629fd828cdeff588bb4f742d9ffe.zip
Simplify erc-sasl's auth-source API
* doc/misc/erc.texi: Revise descriptions in SASL chapter to reflect simplified auth-source options. * lisp/erc/erc-sasl.el (erc-sasl-password, erc-sasl-auth-source-function): Revise doc strings. (erc-sasl-auth-source-password-as-host): New function to serve as more useful choice for option `erc-sasl-auth-source-function'. (erc-sasl--read-password): Promote auth-source to pole position, above an explicit string and `:password'. * test/lisp/erc/erc-sasl-tests.el (erc-sasl--read-password--basic): Massage tests to conform to simplified `erc-sasl-password' API. (Bug#29108.)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-sasl-tests.el38
1 files changed, 26 insertions, 12 deletions
diff --git a/test/lisp/erc/erc-sasl-tests.el b/test/lisp/erc/erc-sasl-tests.el
index 3e6828ff644..0e5ea60e5f0 100644
--- a/test/lisp/erc/erc-sasl-tests.el
+++ b/test/lisp/erc/erc-sasl-tests.el
@@ -57,6 +57,8 @@
57 (erc-sasl--read-password "pwd:")) 57 (erc-sasl--read-password "pwd:"))
58 "baz"))))) 58 "baz")))))
59 59
60;; This mainly tests `erc-sasl-auth-source-password-as-host'.
61
60(ert-deftest erc-sasl--read-password--auth-source () 62(ert-deftest erc-sasl--read-password--auth-source ()
61 (ert-with-temp-file netrc-file 63 (ert-with-temp-file netrc-file
62 :text (string-join 64 :text (string-join
@@ -70,33 +72,42 @@
70 (erc-session-server "irc.gnu.org") 72 (erc-session-server "irc.gnu.org")
71 (erc-session-port 6697) 73 (erc-session-port 6697)
72 (erc-networks--id (erc-networks--id-create nil)) 74 (erc-networks--id (erc-networks--id-create nil))
73 calls
74 (fn (lambda (&rest r)
75 (push r calls)
76 (apply #'erc-auth-source-search r)))
77 erc-server-announced-name ; too early 75 erc-server-announced-name ; too early
78 auth-source-do-cache) 76 auth-source-do-cache
77 ;;
78 (fn #'erc-sasl-auth-source-password-as-host)
79 calls)
80
81 (advice-add 'erc-auth-source-search :before
82 (lambda (&rest r) (push r calls))
83 '((name . erc-sasl--read-password--auth-source)))
79 84
80 (ert-info ("Symbol as password specifies machine") 85 (ert-info ("Symbol as password specifies machine")
81 (let ((erc-sasl--options 86 (let ((erc-sasl--options
82 `((user . "bob") (password . FSF.chat) (authfn . ,fn))) 87 `((user . "bob") (password . FSF.chat) (authfn . ,fn))))
83 (erc-networks--id (make-erc-networks--id)))
84 (should (string= (erc-sasl--read-password nil) "sesame")) 88 (should (string= (erc-sasl--read-password nil) "sesame"))
85 (should (equal (pop calls) '(:user "bob" :host "FSF.chat"))))) 89 (should (equal (pop calls) '(:user "bob" :host "FSF.chat")))))
86 90
87 (ert-info ("ID for :host and `erc-session-username' for :user") ; *1 91 (ert-info (":password as password resolved to machine")
92 (let ((erc-session-password "FSF.chat")
93 (erc-sasl--options
94 `((user . "bob") (password . :password) (authfn . ,fn))))
95 (should (string= (erc-sasl--read-password nil) "sesame"))
96 (should (equal (pop calls) '(:user "bob" :host "FSF.chat")))))
97
98 (ert-info (":user resolved to `erc-session-username'") ; *1
88 (let ((erc-session-username "bob") 99 (let ((erc-session-username "bob")
89 (erc-sasl--options `((user . :user) (password) (authfn . ,fn))) 100 (erc-sasl--options `((user . :user) (password) (authfn . ,fn)))
90 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 101 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
91 (should (string= (erc-sasl--read-password nil) "spam")) 102 (should (string= (erc-sasl--read-password nil) "spam"))
92 (should (equal (pop calls) '(:user "bob" :host "GNU/chat"))))) 103 (should (equal (pop calls) '(:user "bob")))))
93 104
94 (ert-info ("ID for :host and current nick for :user") ; *1 105 (ert-info (":user resolved to current nick") ; *1
95 (let ((erc-server-current-nick "bob") 106 (let ((erc-server-current-nick "bob")
96 (erc-sasl--options `((user . :nick) (password) (authfn . ,fn))) 107 (erc-sasl--options `((user . :nick) (password) (authfn . ,fn)))
97 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 108 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
98 (should (string= (erc-sasl--read-password nil) "spam")) 109 (should (string= (erc-sasl--read-password nil) "spam"))
99 (should (equal (pop calls) '(:user "bob" :host "GNU/chat"))))) 110 (should (equal (pop calls) '(:user "bob")))))
100 111
101 (ert-info ("Symbol as password, entry lacks user field") 112 (ert-info ("Symbol as password, entry lacks user field")
102 (let ((erc-server-current-nick "fake") 113 (let ((erc-server-current-nick "fake")
@@ -104,7 +115,10 @@
104 `((user . :nick) (password . MyHost) (authfn . ,fn))) 115 `((user . :nick) (password . MyHost) (authfn . ,fn)))
105 (erc-networks--id (erc-networks--id-create 'GNU/chat))) 116 (erc-networks--id (erc-networks--id-create 'GNU/chat)))
106 (should (string= (erc-sasl--read-password nil) "123")) 117 (should (string= (erc-sasl--read-password nil) "123"))
107 (should (equal (pop calls) '(:user "fake" :host "MyHost")))))))) 118 (should (equal (pop calls) '(:user "fake" :host "MyHost")))))
119
120 (advice-remove 'erc-auth-source-search
121 'erc-sasl--read-password--auth-source))))
108 122
109(ert-deftest erc-sasl-create-client--plain () 123(ert-deftest erc-sasl-create-client--plain ()
110 (let* ((erc-session-password "password123") 124 (let* ((erc-session-password "password123")