>From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 29 Sep 2021 01:30:16 -0700 Subject: [PATCH 21/28] SQUASH-ME: Add ERC test scenarios involving auth-source XXX this should be combined with the commit entitled "Make auth-source searches session-ID aware in ERC". It was split off for the sake of flexibility during code review. * test/lisp/erc/erc-scenarios.el: Add session-aware scenarios involving the auth-source queries. See bug#48598 for background. --- .../base/auth-source/foonet.lispdata | 23 +++ .../base/auth-source/nopass.lispdata | 22 +++ .../services/auth-source/libera.lispdata | 49 +++++++ test/lisp/erc/erc-scenarios.el | 135 ++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 test/lisp/erc/erc-scenarios-resources/base/auth-source/foonet.lispdata create mode 100644 test/lisp/erc/erc-scenarios-resources/base/auth-source/nopass.lispdata create mode 100644 test/lisp/erc/erc-scenarios-resources/services/auth-source/libera.lispdata diff --git a/test/lisp/erc/erc-scenarios-resources/base/auth-source/foonet.lispdata b/test/lisp/erc/erc-scenarios-resources/base/auth-source/foonet.lispdata new file mode 100644 index 0000000000..1fe772c7e2 --- /dev/null +++ b/test/lisp/erc/erc-scenarios-resources/base/auth-source/foonet.lispdata @@ -0,0 +1,23 @@ +;; -*- mode: lisp-data; -*- +((pass 1 "PASS :changeme")) +((nick 1 "NICK tester")) +((user 1 "USER user 0 * :tester") + (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester") + (0 ":irc.foonet.org 002 tester :Your host is irc.foonet.org, running version oragono-2.6.0-7481bf0385b95b16") + (0 ":irc.foonet.org 003 tester :This server was created Tue, 04 May 2021 05:06:18 UTC") + (0 ":irc.foonet.org 004 tester irc.foonet.org oragono-2.6.0-7481bf0385b95b16 BERTZios CEIMRUabefhiklmnoqstuv Iabefhkloqv") + (0 ":irc.foonet.org 005 tester AWAYLEN=390 BOT=B CASEMAPPING=ascii CHANLIMIT=#:100 CHANMODES=Ibe,k,fl,CEMRUimnstu CHANNELLEN=64 CHANTYPES=# ELIST=U EXCEPTS EXTBAN=,m FORWARD=f INVEX KICKLEN=390 :are supported by this server") + (0 ":irc.foonet.org 005 tester MAXLIST=beI:60 MAXTARGETS=4 MODES MONITOR=100 NETWORK=FooNet NICKLEN=32 PREFIX=(qaohv)~&@%+ STATUSMSG=~&@%+ TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,USERHOST:10,PRIVMSG:4,TAGMSG:4,NOTICE:4,MONITOR:100 TOPICLEN=390 UTF8MAPPING=rfc8265 UTF8ONLY WHOX :are supported by this server") + (0 ":irc.foonet.org 005 tester draft/CHATHISTORY=100 :are supported by this server") + (0 ":irc.foonet.org 251 tester :There are 0 users and 3 invisible on 1 server(s)") + (0 ":irc.foonet.org 252 tester 0 :IRC Operators online") + (0 ":irc.foonet.org 253 tester 0 :unregistered connections") + (0 ":irc.foonet.org 254 tester 1 :channels formed") + (0 ":irc.foonet.org 255 tester :I have 3 clients and 0 servers") + (0 ":irc.foonet.org 265 tester 3 3 :Current local users 3, max 3") + (0 ":irc.foonet.org 266 tester 3 3 :Current global users 3, max 3") + (0 ":irc.foonet.org 422 tester :MOTD File is missing")) + +((mode-user 1.2 "MODE tester +i") + (0 ":irc.foonet.org 221 tester +i") + (0 ":irc.foonet.org NOTICE tester :This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect.")) diff --git a/test/lisp/erc/erc-scenarios-resources/base/auth-source/nopass.lispdata b/test/lisp/erc/erc-scenarios-resources/base/auth-source/nopass.lispdata new file mode 100644 index 0000000000..3fdb4ecf7b --- /dev/null +++ b/test/lisp/erc/erc-scenarios-resources/base/auth-source/nopass.lispdata @@ -0,0 +1,22 @@ +;; -*- mode: lisp-data; -*- +((nick 1 "NICK tester")) +((user 1 "USER user 0 * :tester") + (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester") + (0 ":irc.foonet.org 002 tester :Your host is irc.foonet.org, running version oragono-2.6.0-7481bf0385b95b16") + (0 ":irc.foonet.org 003 tester :This server was created Tue, 04 May 2021 05:06:18 UTC") + (0 ":irc.foonet.org 004 tester irc.foonet.org oragono-2.6.0-7481bf0385b95b16 BERTZios CEIMRUabefhiklmnoqstuv Iabefhkloqv") + (0 ":irc.foonet.org 005 tester AWAYLEN=390 BOT=B CASEMAPPING=ascii CHANLIMIT=#:100 CHANMODES=Ibe,k,fl,CEMRUimnstu CHANNELLEN=64 CHANTYPES=# ELIST=U EXCEPTS EXTBAN=,m FORWARD=f INVEX KICKLEN=390 :are supported by this server") + (0 ":irc.foonet.org 005 tester MAXLIST=beI:60 MAXTARGETS=4 MODES MONITOR=100 NETWORK=FooNet NICKLEN=32 PREFIX=(qaohv)~&@%+ STATUSMSG=~&@%+ TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,USERHOST:10,PRIVMSG:4,TAGMSG:4,NOTICE:4,MONITOR:100 TOPICLEN=390 UTF8MAPPING=rfc8265 UTF8ONLY WHOX :are supported by this server") + (0 ":irc.foonet.org 005 tester draft/CHATHISTORY=100 :are supported by this server") + (0 ":irc.foonet.org 251 tester :There are 0 users and 3 invisible on 1 server(s)") + (0 ":irc.foonet.org 252 tester 0 :IRC Operators online") + (0 ":irc.foonet.org 253 tester 0 :unregistered connections") + (0 ":irc.foonet.org 254 tester 1 :channels formed") + (0 ":irc.foonet.org 255 tester :I have 3 clients and 0 servers") + (0 ":irc.foonet.org 265 tester 3 3 :Current local users 3, max 3") + (0 ":irc.foonet.org 266 tester 3 3 :Current global users 3, max 3") + (0 ":irc.foonet.org 422 tester :MOTD File is missing")) + +((mode-user 1.2 "MODE tester +i") + (0 ":irc.foonet.org 221 tester +i") + (0 ":irc.foonet.org NOTICE tester :This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect.")) diff --git a/test/lisp/erc/erc-scenarios-resources/services/auth-source/libera.lispdata b/test/lisp/erc/erc-scenarios-resources/services/auth-source/libera.lispdata new file mode 100644 index 0000000000..c8dbc9d425 --- /dev/null +++ b/test/lisp/erc/erc-scenarios-resources/services/auth-source/libera.lispdata @@ -0,0 +1,49 @@ +;; -*- mode: lisp-data; -*- +((nick 1 "NICK tester")) +((user 1 "USER user 0 * :tester") + (0.26 ":zirconium.libera.chat NOTICE * :*** Checking Ident") + (0.01 ":zirconium.libera.chat NOTICE * :*** Looking up your hostname...") + (0.01 ":zirconium.libera.chat NOTICE * :*** No Ident response") + (0.02 ":zirconium.libera.chat NOTICE * :*** Found your hostname: static-198-54-131-100.cust.tzulo.com") + (0.02 ":zirconium.libera.chat 001 tester :Welcome to the Libera.Chat Internet Relay Chat Network tester") + (0.01 ":zirconium.libera.chat 002 tester :Your host is zirconium.libera.chat[46.16.175.175/6697], running version solanum-1.0-dev") + (0.03 ":zirconium.libera.chat 003 tester :This server was created Wed Jun 9 2021 at 01:38:28 UTC") + (0.02 ":zirconium.libera.chat 004 tester zirconium.libera.chat solanum-1.0-dev DGQRSZaghilopsuwz CFILMPQSbcefgijklmnopqrstuvz bkloveqjfI") + (0.00 ":zirconium.libera.chat 005 tester ETRACE WHOX FNC MONITOR=100 SAFELIST ELIST=CTU CALLERID=g KNOCK CHANTYPES=# EXCEPTS INVEX CHANMODES=eIbq,k,flj,CFLMPQScgimnprstuz :are supported by this server") + (0.03 ":zirconium.libera.chat 005 tester CHANLIMIT=#:250 PREFIX=(ov)@+ MAXLIST=bqeI:100 MODES=4 NETWORK=Libera.Chat STATUSMSG=@+ CASEMAPPING=rfc1459 NICKLEN=16 MAXNICKLEN=16 CHANNELLEN=50 TOPICLEN=390 DEAF=D :are supported by this server") + (0.02 ":zirconium.libera.chat 005 tester TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:4,NOTICE:4,ACCEPT:,MONITOR: EXTBAN=$,ajrxz CLIENTVER=3.0 :are supported by this server") + (0.02 ":zirconium.libera.chat 251 tester :There are 68 users and 37640 invisible on 25 servers") + (0.00 ":zirconium.libera.chat 252 tester 36 :IRC Operators online") + (0.01 ":zirconium.libera.chat 253 tester 5 :unknown connection(s)") + (0.00 ":zirconium.libera.chat 254 tester 19341 :channels formed") + (0.01 ":zirconium.libera.chat 255 tester :I have 3321 clients and 1 servers") + (0.01 ":zirconium.libera.chat 265 tester 3321 4289 :Current local users 3321, max 4289") + (0.00 ":zirconium.libera.chat 266 tester 37708 38929 :Current global users 37708, max 38929") + (0.01 ":zirconium.libera.chat 250 tester :Highest connection count: 4290 (4289 clients) (38580 connections received)") + (0.21 ":zirconium.libera.chat 375 tester :- zirconium.libera.chat Message of the Day - ") + (0.00 ":zirconium.libera.chat 372 tester :- This server provided by Seeweb ") + (0.01 ":zirconium.libera.chat 372 tester :- Welcome to Libera Chat, the IRC network for") + (0.01 ":zirconium.libera.chat 372 tester :- free & open-source software and peer directed projects.") + (0.00 ":zirconium.libera.chat 372 tester :- ") + (0.00 ":zirconium.libera.chat 372 tester :- Use of Libera Chat is governed by our network policies.") + (0.00 ":zirconium.libera.chat 372 tester :- ") + (0.01 ":zirconium.libera.chat 372 tester :- Please visit us in #libera for questions and support.") + (0.01 ":zirconium.libera.chat 372 tester :- ") + (0.01 ":zirconium.libera.chat 372 tester :- Website and documentation: https://libera.chat") + (0.01 ":zirconium.libera.chat 372 tester :- Webchat: https://web.libera.chat") + (0.01 ":zirconium.libera.chat 372 tester :- Network policies: https://libera.chat/policies") + (0.01 ":zirconium.libera.chat 372 tester :- Email: support@libera.chat") + (0.00 ":zirconium.libera.chat 376 tester :End of /MOTD command.")) + +((mode-user 1.2 "MODE tester +i") + (0.02 ":tester MODE tester :+Zi") + (0.02 ":NickServ!NickServ@services.libera.chat NOTICE tester :This nickname is registered. Please choose a different nickname, or identify via \2/msg NickServ IDENTIFY tester \2")) + +((privmsg 2 "PRIVMSG NickServ :IDENTIFY changeme") + (0.96 ":NickServ!NickServ@services.libera.chat NOTICE tester :You are now identified for \2tester\2.") + (0.25 ":NickServ!NickServ@services.libera.chat NOTICE tester :Last login from: \2~tester@school.edu/tester\2 on Jun 18 01:15:56 2021 +0000.")) + +((quit 5 "QUIT :\2ERC\2") + (0.19 ":tester!~user@static-198-54-131-100.cust.tzulo.com QUIT :Client Quit")) + +((linger 1 LINGER)) diff --git a/test/lisp/erc/erc-scenarios.el b/test/lisp/erc/erc-scenarios.el index 1d2f988338..5a74a266b8 100644 --- a/test/lisp/erc/erc-scenarios.el +++ b/test/lisp/erc/erc-scenarios.el @@ -1759,6 +1759,141 @@ erc-scenarios-base-legacy-autojoin (erc-d-t-wait-for 6 "#chan exists" (get-buffer "#chan")) (erc-d-t-search-for 10 "Live, and be prosperous"))))) +;; Auth source consulted for initial PASS arg. Option +;; `erc-connect-auth-source-host' obeyed. + +(defun erc-scenarios-common--auth-source (id dialog &rest rest) + (push "machine GNU.chat port %d user \"#chan\" password spam" rest) + (erc-scenarios-common-with-cleanup + ((erc-scenarios-common-dialog "base/auth-source") + (dumb-server (erc-d-run "localhost" t dialog)) + (port (process-contact dumb-server :service)) + (ents `(,@(mapcar (lambda (fmt) (format fmt port)) rest) + "machine MyHost port irc password 123")) + (netrc-file (make-temp-file "auth-source-test" nil nil + (string-join ents "\n"))) + (auth-sources (list netrc-file)) + (auth-source-do-cache nil) + (erc-scenarios-common-extra-teardown (lambda () + (delete-file netrc-file))) + (dumb-server-buffer (get-buffer "*erc-d-server*"))) + + (ert-info ("Connect") + (with-current-buffer (erc :server "127.0.0.1" + :port port + :nick "tester" + :full-name "tester" + :id id) + (should (string= (buffer-name) (if id + (symbol-name id) + (format "127.0.0.1:%d" port)))) + (erc-d-t-wait-for 1 "Network determined" (eq erc-network 'FooNet)))))) + +(ert-deftest erc-scenarios-base-auth-source--dialed () + (should (eq erc-connect-auth-source-host 'server)) + (erc-scenarios-common--auth-source + nil 'foonet + "machine GNU.chat port %d user tester password fake" + "machine 127.0.0.1 port %d user tester password changeme" + "machine 127.0.0.1 port %d user imposter password fake")) + +(ert-deftest erc-scenarios-base-auth-source--dialed-fallback () + (let ((erc-connect-auth-source-host t)) + (erc-scenarios-common--auth-source + nil 'foonet + "machine FooNet port %d user tester password fake" + "machine 127.0.0.1 port %d user tester password changeme" + "machine 127.0.0.1 port %d user imposter password fake"))) + +(ert-deftest erc-scenarios-base-auth-source--session-id () + (let ((erc-connect-auth-source-host t)) + (erc-scenarios-common--auth-source + 'MySession 'foonet + "machine MySession port %d user tester password changeme" + "machine 127.0.0.1 port %d user tester password fake" + "machine FooNet port %d user tester password fake"))) + +(ert-deftest erc-scenarios-base-auth-source--string--session-id () + (let ((erc-connect-auth-source-host "MyHost")) + (erc-scenarios-common--auth-source + 'MySession 'foonet + "machine 127.0.0.1 port %d user tester password fake" + "machine MyHost port %d user tester password changeme" + "machine MySession port %d user tester password fake"))) + +(ert-deftest erc-scenarios-base-auth-source--nopass () + (let (erc-connect-auth-source-host) ; nil + (erc-scenarios-common--auth-source nil 'nopass))) + +(ert-deftest erc-scenarios-base-auth-source--nopass--session-id () + (let (erc-connect-auth-source-host) ; nil + (erc-scenarios-common--auth-source 'MySession 'nopass))) + +;; Identify via auth source with no initial password + +(defun erc-scenarios-common--services-auth-source (&rest rest) + (defvar erc-use-auth-source-for-nickserv-password) + (erc-scenarios-common-with-cleanup + ((erc-scenarios-common-dialog "services/auth-source") + (erc-server-flood-penalty 0.1) + (dumb-server (erc-d-run "localhost" t 'libera)) + (port (process-contact dumb-server :service)) + (ents `(,@(mapcar (lambda (fmt) (format fmt port)) rest) + "machine MyHost port irc password 123")) + (netrc-file (make-temp-file "auth-source-test" nil nil + (string-join ents "\n"))) + (auth-sources (list netrc-file)) + (auth-source-do-cache nil) + (erc-modules (cons 'services erc-modules)) + (erc-use-auth-source-for-nickserv-password t) ; do consult for NickServ + (expect (erc-d-t-make-expecter)) + (erc-scenarios-common-extra-teardown (lambda () + (delete-file netrc-file))) + (dumb-server-buffer (get-buffer "*erc-d-server*"))) + + (cl-letf (((symbol-function 'read-passwd) + (lambda (&rest _) (error "Unexpected read-passwd call")))) + (ert-info ("Connect without password") + (with-current-buffer (erc :server "127.0.0.1" + :port port + :nick "tester" + :full-name "tester") + (should (string= (buffer-name) (format "127.0.0.1:%d" port))) + (erc-d-t-wait-for 3 "Network determined" + (eq erc-network 'Libera.Chat)) + (funcall expect 3 "This nickname is registered.") + (funcall expect 3 "You are now identified") + (funcall expect 3 "Last login from") + (erc-cmd-QUIT "")))) + + (erc-services-mode -1) + + (should-not (memq 'services erc-modules)))) + +(ert-deftest erc-scenarios-services-auth-source--network () + (let (erc-connect-auth-source-host) ; don't consult auth-source for PASS + (erc-scenarios-common--services-auth-source + "machine 127.0.0.1 port %d user tester password spam" + "machine zirconium.libera.chat port %d user tester password fake" + "machine Libera.Chat port %d user tester password changeme"))) + +(ert-deftest erc-scenarios-services-auth-source--network-connect-lookup () + (should (eq erc-connect-auth-source-host 'server)) + (erc-scenarios-common--services-auth-source + "machine zirconium.libera.chat port %d user tester password fake" + "machine Libera.Chat port %d user tester password changeme")) + +(ert-deftest erc-scenarios-services-auth-source--announced () + (let (erc-connect-auth-source-host) ; don't consult auth-source for PASS + (erc-scenarios-common--services-auth-source + "machine 127.0.0.1 port %d user tester password spam" + "machine zirconium.libera.chat port %d user tester password changeme"))) + +(ert-deftest erc-scenarios-services-auth-source--dialed () + (let (erc-connect-auth-source-host) ; don't consult auth-source for PASS + (erc-scenarios-common--services-auth-source + "machine 127.0.0.1 port %d user tester password changeme"))) + (ert-deftest erc-scenarios-services-password () (defvar erc-nickserv-passwords) -- 2.31.1