From 3319920250235e69e699844e264f86f536fdd34b Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 16 Nov 2022 14:38:35 +0100 Subject: [PATCH 1/2] Check behavior of PRIVMSG when banned --- irctest/server_tests/chmodes/ban.py | 59 +++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/irctest/server_tests/chmodes/ban.py b/irctest/server_tests/chmodes/ban.py index d0f48292..0dd204e6 100644 --- a/irctest/server_tests/chmodes/ban.py +++ b/irctest/server_tests/chmodes/ban.py @@ -7,14 +7,18 @@ """ from irctest import cases, runner -from irctest.numerics import ERR_BANNEDFROMCHAN, RPL_BANLIST, RPL_ENDOFBANLIST +from irctest.numerics import ( + ERR_BANNEDFROMCHAN, + ERR_CANNOTSENDTOCHAN, + RPL_BANLIST, + RPL_ENDOFBANLIST, +) from irctest.patma import ANYSTR, StrRe class BanModeTestCase(cases.BaseServerTestCase): @cases.mark_specifications("RFC1459", "RFC2812", "Modern") - def testBan(self): - """Basic ban operation""" + def testBanJoin(self): self.connectClient("chanop", name="chanop") self.joinChannel("chanop", "#chan") self.getMessages("chanop") @@ -32,6 +36,55 @@ def testBan(self): self.sendLine("bar", "JOIN #chan") self.assertMessageMatch(self.getMessage("bar"), command="JOIN") + @cases.mark_specifications("Modern") + def testBanPrivmsg(self): + """ + TODO: this checks the following quote is false: + + "If `` is a channel name and the client is [banned](#ban-channel-mode) + and not covered by a [ban exception](#ban-exception-channel-mode), the + message will not be delivered and the command will silently fail." + -- https://modern.ircdocs.horse/#privmsg-message + + to check https://github.com/ircdocs/modern-irc/pull/201 + """ + self.connectClient("chanop", name="chanop") + self.joinChannel("chanop", "#chan") + self.getMessages("chanop") + + self.connectClient("Bar", name="bar") + self.getMessages("bar") + self.sendLine("bar", "JOIN #chan") + self.getMessages("bar") + self.getMessages("chanop") + + self.sendLine("chanop", "MODE #chan +b bar!*@*") + self.assertMessageMatch(self.getMessage("chanop"), command="MODE") + self.getMessages("chanop") + self.getMessages("bar") + + self.sendLine("bar", "PRIVMSG #chan :hello world") + self.assertMessageMatch( + self.getMessage("bar"), + command=ERR_CANNOTSENDTOCHAN, + params=["Bar", "#chan", ANYSTR], + ) + self.assertEqual(self.getMessages("bar"), []) + self.assertEqual(self.getMessages("chanop"), []) + + self.sendLine("chanop", "MODE #chan -b bar!*@*") + self.assertMessageMatch(self.getMessage("chanop"), command="MODE") + self.getMessages("chanop") + self.getMessages("bar") + + self.sendLine("bar", "PRIVMSG #chan :hello again") + self.assertMessageMatch( + self.getMessage("chanop"), + command="PRIVMSG", + params=["#chan", "hello again"], + ) + self.assertEqual(self.getMessages("bar"), []) + @cases.mark_specifications("Modern") def testBanList(self): """`RPL_BANLIST `_""" From 0816232c1c5159d46ea5013f78f72f6f72024147 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 16 Nov 2022 15:39:33 +0100 Subject: [PATCH 2/2] Fix sync issue --- irctest/server_tests/chmodes/ban.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irctest/server_tests/chmodes/ban.py b/irctest/server_tests/chmodes/ban.py index 0dd204e6..1dfb3bdd 100644 --- a/irctest/server_tests/chmodes/ban.py +++ b/irctest/server_tests/chmodes/ban.py @@ -78,12 +78,12 @@ def testBanPrivmsg(self): self.getMessages("bar") self.sendLine("bar", "PRIVMSG #chan :hello again") + self.assertEqual(self.getMessages("bar"), []) self.assertMessageMatch( self.getMessage("chanop"), command="PRIVMSG", params=["#chan", "hello again"], ) - self.assertEqual(self.getMessages("bar"), []) @cases.mark_specifications("Modern") def testBanList(self):