From 363b62cc80923d307a2095d0eb52ce5b7bdc0514 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Wed, 13 Apr 2022 18:56:29 +0200 Subject: [PATCH] Add tests for LINKS (#147) --- irctest/controllers/inspircd.py | 2 +- irctest/controllers/irc2.py | 2 +- irctest/controllers/ngircd.py | 2 +- irctest/controllers/unrealircd.py | 2 +- irctest/server_tests/links.py | 136 ++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 irctest/server_tests/links.py diff --git a/irctest/controllers/inspircd.py b/irctest/controllers/inspircd.py index 1cd40ba..402a10b 100644 --- a/irctest/controllers/inspircd.py +++ b/irctest/controllers/inspircd.py @@ -83,7 +83,7 @@ TEMPLATE_CONFIG = """ # Misc: - + """ TEMPLATE_SSL_CONFIG = """ diff --git a/irctest/controllers/irc2.py b/irctest/controllers/irc2.py index 0281fb6..8006ea6 100644 --- a/irctest/controllers/irc2.py +++ b/irctest/controllers/irc2.py @@ -10,7 +10,7 @@ from irctest.basecontrollers import ( TEMPLATE_CONFIG = """ # M:::::: -M:My.Little.Server:{hostname}:Somewhere:{port}:0042: +M:My.Little.Server:{hostname}:test server:{port}:0042: # A:::::: A:Organization, IRC dept.:Daemon :Client Server::IRCnet: diff --git a/irctest/controllers/ngircd.py b/irctest/controllers/ngircd.py index 17b3540..e296899 100644 --- a/irctest/controllers/ngircd.py +++ b/irctest/controllers/ngircd.py @@ -12,7 +12,7 @@ from irctest.irc_utils.junkdrawer import find_hostname_and_port TEMPLATE_CONFIG = """ [Global] Name = My.Little.Server - Info = ExampleNET Server + Info = test server Bind = {hostname} Ports = {port} AdminInfo1 = Bob Smith diff --git a/irctest/controllers/unrealircd.py b/irctest/controllers/unrealircd.py index af397c1..529ed80 100644 --- a/irctest/controllers/unrealircd.py +++ b/irctest/controllers/unrealircd.py @@ -22,7 +22,7 @@ include "help/help.conf"; me {{ name "My.Little.Server"; - info "ExampleNET Server"; + info "test server"; sid "001"; }} admin {{ diff --git a/irctest/server_tests/links.py b/irctest/server_tests/links.py new file mode 100644 index 0000000..62c746f --- /dev/null +++ b/irctest/server_tests/links.py @@ -0,0 +1,136 @@ +from irctest import cases, runner +from irctest.numerics import ERR_UNKNOWNCOMMAND, RPL_ENDOFLINKS, RPL_LINKS +from irctest.patma import ANYSTR, StrRe + + +class LinksTestCase(cases.BaseServerTestCase): + @cases.mark_specifications("RFC1459", "RFC2812", "Modern") + def testLinksSingleServer(self): + """ + Only testing the parameter-less case. + + https://datatracker.ietf.org/doc/html/rfc1459#section-4.3.3 + https://datatracker.ietf.org/doc/html/rfc2812#section-3.4.5 + https://github.com/ircdocs/modern-irc/pull/175 + + " + 364 RPL_LINKS + " : " + 365 RPL_ENDOFLINKS + " :End of /LINKS list" + + - In replying to the LINKS message, a server must send + replies back using the RPL_LINKS numeric and mark the + end of the list using an RPL_ENDOFLINKS reply. + " + -- https://datatracker.ietf.org/doc/html/rfc1459#page-51 + -- https://datatracker.ietf.org/doc/html/rfc2812#page-48 + + RPL_LINKS: " * : " + RPL_ENDOFLINKS: " * :End of /LINKS list" + -- https://github.com/ircdocs/modern-irc/pull/175/files + """ + self.connectClient("nick") + self.sendLine(1, "LINKS") + messages = self.getMessages(1) + if messages[0].command == ERR_UNKNOWNCOMMAND: + raise runner.NotImplementedByController("LINKS") + + # Ignore '/LINKS has been disabled' from ircu2 + messages = [m for m in messages if m.command != "NOTICE"] + + self.assertMessageMatch( + messages.pop(-1), + command=RPL_ENDOFLINKS, + params=["nick", "*", ANYSTR], + ) + + if not messages: + # This server probably redacts links + return + + self.assertMessageMatch( + messages[0], + command=RPL_LINKS, + params=[ + "nick", + "My.Little.Server", + "My.Little.Server", + StrRe("0 (0042 )?test server"), + ], + ) + + +@cases.mark_services +class ServicesLinksTestCase(cases.BaseServerTestCase): + # On every IRCd but Ergo, services are linked. + # Ergo does not implement LINKS at all, so this test is skipped. + @cases.mark_specifications("RFC1459", "RFC2812", "Modern") + def testLinksWithServices(self): + """ + Only testing the parameter-less case. + + https://datatracker.ietf.org/doc/html/rfc1459#section-4.3.3 + https://datatracker.ietf.org/doc/html/rfc2812#section-3.4.5 + + " + 364 RPL_LINKS + " : " + 365 RPL_ENDOFLINKS + " :End of /LINKS list" + + - In replying to the LINKS message, a server must send + replies back using the RPL_LINKS numeric and mark the + end of the list using an RPL_ENDOFLINKS reply. + " + -- https://datatracker.ietf.org/doc/html/rfc1459#page-51 + -- https://datatracker.ietf.org/doc/html/rfc2812#page-48 + + RPL_LINKS: " * : " + RPL_ENDOFLINKS: " * :End of /LINKS list" + -- https://github.com/ircdocs/modern-irc/pull/175/files + """ + self.connectClient("nick") + self.sendLine(1, "LINKS") + messages = self.getMessages(1) + + if messages[0].command == ERR_UNKNOWNCOMMAND: + raise runner.NotImplementedByController("LINKS") + + # Ignore '/LINKS has been disabled' from ircu2 + messages = [m for m in messages if m.command != "NOTICE"] + + self.assertMessageMatch( + messages.pop(-1), + command=RPL_ENDOFLINKS, + params=["nick", "*", ANYSTR], + ) + + if not messages: + # This server redacts links + return + + messages.sort(key=lambda m: m.params[-1]) + + self.assertMessageMatch( + messages.pop(0), + command=RPL_LINKS, + params=[ + "nick", + "My.Little.Server", + "My.Little.Server", + StrRe("0 (0042 )?test server"), + ], + ) + self.assertMessageMatch( + messages.pop(0), + command=RPL_LINKS, + params=[ + "nick", + "services.example.org", + "My.Little.Server", + StrRe("1 .+"), # SID instead of description for Anope... + ], + ) + + self.assertEqual(messages, [])