From 88a8f8ad8dfa4bec80d419271f65bb6901d98def Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Mon, 10 Jan 2022 23:55:42 +0100 Subject: [PATCH] Add tests for INFO (#121) * Add tests for INFO * Workaround remote INFO being oper-only on some ircds * Skip testInfoNosuchserver on Ergo * info: Mark tests with target as deprecated. --- Makefile | 2 + irctest/server_tests/info.py | 112 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 irctest/server_tests/info.py diff --git a/Makefile b/Makefile index 9978892..23b2ed7 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,10 @@ CHARYBDIS_SELECTORS := \ and not (testWhoisNumerics and oper) \ $(EXTRA_SELECTORS) +# testInfoNosuchserver does not apply to Ergo: Ergo ignores the optional argument ERGO_SELECTORS := \ not deprecated \ + and not testInfoNosuchserver \ $(EXTRA_SELECTORS) # testInviteUnoppedModern is the only strict test that Hybrid fails diff --git a/irctest/server_tests/info.py b/irctest/server_tests/info.py new file mode 100644 index 0000000..db0d9db --- /dev/null +++ b/irctest/server_tests/info.py @@ -0,0 +1,112 @@ +""" +The INFO command. +""" + +import pytest + +from irctest import cases +from irctest.numerics import ERR_NOSUCHSERVER, RPL_ENDOFINFO, RPL_INFO, RPL_YOUREOPER +from irctest.patma import ANYSTR + + +class InfoTestCase(cases.BaseServerTestCase): + @cases.mark_specifications("RFC1459", "RFC2812", "Modern") + def testInfo(self): + """ + + + + "Upon receiving an INFO command, the given server will respond with zero or + more RPL_INFO replies, followed by one RPL_ENDOFINFO numeric" + -- + """ + self.connectClient("nick") + + # Remote /INFO is oper-only on Unreal and ircu2 + self.sendLine(1, "OPER operuser operpassword") + self.assertIn( + RPL_YOUREOPER, + [m.command for m in self.getMessages(1)], + fail_msg="OPER failed", + ) + + self.sendLine(1, "INFO") + + messages = self.getMessages(1) + last_message = messages.pop() + + self.assertMessageMatch( + last_message, command=RPL_ENDOFINFO, params=["nick", ANYSTR] + ) + + for message in messages: + self.assertMessageMatch(message, command=RPL_INFO, params=["nick", ANYSTR]) + + @pytest.mark.parametrize( + "target", + ["My.Little.Server", "*Little*", "nick"], + ids=["target-server", "target-wildcard", "target-nick"], + ) + @cases.mark_specifications("RFC1459", "RFC2812", deprecated=True) + def testInfoTarget(self, target): + """ + + + + "Upon receiving an INFO command, the given server will respond with zero or + more RPL_INFO replies, followed by one RPL_ENDOFINFO numeric" + -- + """ + self.connectClient("nick") + + # Remote /INFO is oper-only on Unreal and ircu2 + self.sendLine(1, "OPER operuser operpassword") + self.assertIn( + RPL_YOUREOPER, + [m.command for m in self.getMessages(1)], + fail_msg="OPER failed", + ) + + if target: + self.sendLine(1, "INFO My.Little.Server") + else: + self.sendLine(1, "INFO") + + messages = self.getMessages(1) + last_message = messages.pop() + + self.assertMessageMatch( + last_message, command=RPL_ENDOFINFO, params=["nick", ANYSTR] + ) + + for message in messages: + self.assertMessageMatch(message, command=RPL_INFO, params=["nick", ANYSTR]) + + @pytest.mark.parametrize("target", ["invalid.server.example", "invalidserver"]) + @cases.mark_specifications("RFC1459", "RFC2812", deprecated=True) + def testInfoNosuchserver(self, target): + """ + + + + "Upon receiving an INFO command, the given server will respond with zero or + more RPL_INFO replies, followed by one RPL_ENDOFINFO numeric" + -- + """ + self.connectClient("nick") + + # Remote /INFO is oper-only on Unreal and ircu2 + self.sendLine(1, "OPER operuser operpassword") + self.assertIn( + RPL_YOUREOPER, + [m.command for m in self.getMessages(1)], + fail_msg="OPER failed", + ) + + self.sendLine(1, f"INFO {target}") + + self.assertMessageMatch( + self.getMessage(1), + command=ERR_NOSUCHSERVER, + params=["nick", target, ANYSTR], + )