From e4bca8a4016af12261d44dc70d4363a5be7b0b2d Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 1 Apr 2022 13:59:41 +0200 Subject: [PATCH] Add test for mode +C ('no ctcp') --- irctest/controllers/inspircd.py | 1 + irctest/server_tests/chmodes/noctcp.py | 69 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 irctest/server_tests/chmodes/noctcp.py diff --git a/irctest/controllers/inspircd.py b/irctest/controllers/inspircd.py index 1cd40ba..fa9246a 100644 --- a/irctest/controllers/inspircd.py +++ b/irctest/controllers/inspircd.py @@ -74,6 +74,7 @@ TEMPLATE_CONFIG = """ # for testing mute extbans # For multi-prefix + # HELP/HELPOP diff --git a/irctest/server_tests/chmodes/noctcp.py b/irctest/server_tests/chmodes/noctcp.py new file mode 100644 index 0000000..1d8c228 --- /dev/null +++ b/irctest/server_tests/chmodes/noctcp.py @@ -0,0 +1,69 @@ +from irctest import cases, runner +from irctest.numerics import ERR_CANNOTSENDTOCHAN +from irctest.patma import ANYSTR + + +class NoctcpModeTestCase(cases.BaseServerTestCase): + @cases.mark_specifications("Modern") + def testNoctcpMode(self): + """ + "This mode is used in almost all IRC software today. The standard mode letter + used for it is `"+C"`. + When this mode is set, should not send [CTCP](/ctcp.html) messages, except + CTCP Action (also known as `/me`) to the channel. + When blocking a message because of this mode, servers SHOULD use + ERR_CANNOTSENDTOCHAN" + -- TODO add link + """ + self.connectClient("chanop") + + if "C" not in self.server_support.get("CHANMODES", ""): + raise runner.NotImplementedByController("+C (noctcp) channel mode") + + # Both users join: + + self.sendLine(1, "JOIN #chan") + self.getMessages(1) # synchronize + + self.connectClient("user") + self.sendLine(2, "JOIN #chan") + self.getMessages(2) + self.getMessages(1) + + # Send ACTION and PING, both should go through: + + self.sendLine(2, "PRIVMSG #chan :\x01ACTION is testing\x01") + self.sendLine(2, "PRIVMSG #chan :\x01PING 12345\x01") + self.assertEqual(self.getMessages(2), []) + + self.assertEqual( + [(m.command, m.params[1]) for m in self.getMessages(1)], + [ + ("PRIVMSG", "\x01ACTION is testing\x01"), + ("PRIVMSG", "\x01PING 12345\x01"), + ], + ) + + # Set mode +C: + + self.sendLine(1, "MODE #chan +C") + self.getMessages(1) + self.getMessages(2) + + # Send ACTION and PING, only ACTION should go through: + + self.sendLine(2, "PRIVMSG #chan :\x01ACTION is testing\x01") + self.assertEqual(self.getMessages(2), []) + self.sendLine(2, "PRIVMSG #chan :\x01PING 12345\x01") + self.assertMessageMatch( + self.getMessage(2), + command=ERR_CANNOTSENDTOCHAN, + params=["user", "#chan", ANYSTR], + ) + + self.assertEqual( + [(m.command, m.params[1]) for m in self.getMessages(1)], + [ + ("PRIVMSG", "\x01ACTION is testing\x01"), + ], + )