>From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 16 Aug 2021 04:46:25 -0700 Subject: [PATCH 20/28] Make auth-source searches session-ID aware in ERC XXX this commit was split off from the previous one, entitled something like "Standardize auth-source queries in ERC", so that the latter could be applied independently, and not be tied to all this session-ID/buffer-naming stuff. But if that commit ends up remaining the parent of this one, there's no reason this can't be squashed into it. * lisp/erc/erc.el(erc--auth-source-determine-params): Now prioritizes session IDs over announced servers and dialed endpoints. (erc-connect-auth-source-host): Change network-oriented choice to favor session-id over server * lisp/erc/erc-join.el (erc-autojoin--join): Don't pass session-like entity from erc-autojoin-alist match to erc-server-join-channel. Allow that function to decide for itself which host to look up if necessary. * test/lisp/erc/erc-tests.el: Update tests to use session ID. * lisp/erc/erc-services.el (erc-nickserv-get-password): pass effective session ID when looking up password in erc-nickserv-passwords and when formatting prompt for user input. (erc-nickserv-passwords): add comment to custom option definition type tag. * test/lisp/erc/erc-services-tests.el (erc-nickserv-get-password): adjust test for above changes. --- lisp/erc/erc-join.el | 2 +- lisp/erc/erc-services.el | 4 +-- lisp/erc/erc.el | 10 ++++--- test/lisp/erc/erc-services-tests.el | 8 ++++- test/lisp/erc/erc-tests.el | 45 +++++++++++++++++++++-------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el index ab2ffc9f72..3921694d4d 100644 --- a/lisp/erc/erc-join.el +++ b/lisp/erc/erc-join.el @@ -144,7 +144,7 @@ erc-autojoin--join (when-let ((match (erc-autojoin-server-match name))) (dolist (chan channels) (unless (erc-get-buffer chan erc-server-process) - (erc-server-join-channel match chan)))))) + (erc-server-join-channel nil chan)))))) (defun erc-autojoin-after-ident (_network _nick) "Autojoin channels in `erc-autojoin-channels-alist'. diff --git a/lisp/erc/erc-services.el b/lisp/erc/erc-services.el index b0c58ae0ce..0171a01cfe 100644 --- a/lisp/erc/erc-services.el +++ b/lisp/erc/erc-services.el @@ -202,7 +202,7 @@ erc-nickserv-passwords (const QuakeNet) (const Rizon) (const SlashNET) - (symbol :tag "Network name")) + (symbol :tag "Network name or session ID")) (repeat :tag "Nickname and password" (cons :tag "Identity" (string :tag "Nick") @@ -432,7 +432,7 @@ erc-nickserv-get-password is empty). Otherwise, no corresponding password was found, and it returns nil." (when-let* - ((esid (erc-network)) + ((esid (erc--sid-symbol erc--session)) (ret (or (when erc-nickserv-passwords (assoc-default nick (cadr (assq esid erc-nickserv-passwords)))) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 8ebe50fa89..a9986574d6 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -246,6 +246,7 @@ erc-connect-auth-source-host :type '(choice (const :tag "Don't query auth-source" nil) (const :tag "Dialed host name or IP address" server) (const :tag "Prompt for a machine/host value" prompt) + (const :tag "Session ID, if set, otherwise server" t) (string :tag "Literal value to use for :host"))) (defcustom erc-warn-about-blank-lines t @@ -3378,10 +3379,11 @@ 'erc-cmd-H (defun erc--auth-source-determine-params () "Return a plist of default args to pass to `auth-source-search'. -Favor a discovered network name over an announced server unless -`erc--buffer-target' is a local channel. Consider the dialed server -address as a fallback for the announced name in both cases." - (let* ((net (and-let* ((net (erc-network))) (symbol-name net))) +Favor a session ID over an announced server unless `erc--buffer-target' +is a local channel. Treat the dialed server address as a fallback for +the announced name in both cases." + (let* ((net (and-let* ((esid (erc--sid-symbol erc--session)) + ((symbol-name esid))))) (localp (and erc--buffer-target (erc--target-local-p erc--buffer-target))) (hosts (if localp diff --git a/test/lisp/erc/erc-services-tests.el b/test/lisp/erc/erc-services-tests.el index c646b1c69d..f1c9dca196 100644 --- a/test/lisp/erc/erc-services-tests.el +++ b/test/lisp/erc/erc-services-tests.el @@ -38,6 +38,8 @@ erc-nickserv-get-password (erc-session-server "irc.gnu.org") (erc-server-announced-name "west.gnu.org") (erc-network 'FSF.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil)) (erc-session-port 6697)) (ert-info ("Lookup custom option") @@ -47,7 +49,11 @@ erc-nickserv-get-password (ert-info ("Auth source") (ert-info ("Network") - (should (string= (erc-nickserv-get-password "bob") "sesame")))) + (should (string= (erc-nickserv-get-password "bob") "sesame"))) + + (ert-info ("Session ID") + (let ((erc--session (erc--sid-create 'GNU/chat))) + (should (string= (erc-nickserv-get-password "bob") "spam"))))) (delete-file netrc-file)) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index a337195898..8b9e2f53eb 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -257,11 +257,23 @@ erc--auth-source-search--standard (ert-info ("Normal ordering") - (ert-info ("Network wins") + (ert-info ("Session wins") (let ((erc-session-server "irc.gnu.org") (erc-server-announced-name "west.gnu.org") (erc-session-port 6697) - (erc-network 'GNU.chat)) + (erc-network 'fake) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create 'GNU.chat))) + (should (string= (erc--auth-source-search :user "#chan") + "foo")))) + + (ert-info ("Network wins") + (let* ((erc-session-server "irc.gnu.org") + (erc-server-announced-name "west.gnu.org") + (erc-session-port 6697) + (erc-network 'GNU.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil))) (should (string= (erc--auth-source-search :user "#chan") "foo")))) @@ -269,7 +281,8 @@ erc--auth-source-search--standard (let ((erc-session-server "irc.gnu.org") (erc-server-announced-name "west.gnu.org") (erc-session-port 6697) - erc-network) + erc-network + (erc--session (erc--sid-create nil))) (should (string= (erc--auth-source-search :user "#chan") "baz"))))) @@ -290,23 +303,29 @@ erc--auth-source-search--announced (ert-info ("Announced prioritized") (ert-info ("Announced wins") - (let ((erc-session-server "irc.gnu.org") - (erc-server-announced-name "west.gnu.org") - (erc-session-port 6697) - (erc-network 'GNU.chat)) + (let* ((erc-session-server "irc.gnu.org") + (erc-server-announced-name "west.gnu.org") + (erc-session-port 6697) + (erc-network 'GNU.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil))) (should (string= (erc--auth-source-search :user "#chan") "baz")))) (ert-info ("Peer next") - (let ((erc-server-announced-name "irc.gnu.org") - (erc-session-port 6697) - (erc-network 'GNU.chat)) + (let* ((erc-server-announced-name "irc.gnu.org") + (erc-session-port 6697) + (erc-network 'GNU.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil))) (should (string= (erc--auth-source-search :user "#chan") "bar")))) (ert-info ("Network used as fallback") - (let ((erc-session-port 6697) - (erc-network 'GNU.chat)) + (let* ((erc-session-port 6697) + (erc-network 'GNU.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil))) (should (string= (erc--auth-source-search :user "#chan") "foo"))))) @@ -328,6 +347,8 @@ erc--auth-source-search--overrides (erc-session-server "irc.gnu.org") (erc-server-announced-name "west.gnu.org") (erc-network 'GNU.chat) + (erc-server-current-nick "tester") + (erc--session (erc--sid-create nil)) (erc-session-port 6667)) (unwind-protect -- 2.31.1