From 40ac45cdbe8ba3165487b2af6fb9d8684ec3a297 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 14 Dec 2020 05:22:41 -0500 Subject: [PATCH] add a channel forwarding test --- irctest/numerics.py | 1 + irctest/server_tests/test_channel_forward.py | 44 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 irctest/server_tests/test_channel_forward.py diff --git a/irctest/numerics.py b/irctest/numerics.py index c67239f..5608c68 100644 --- a/irctest/numerics.py +++ b/irctest/numerics.py @@ -144,6 +144,7 @@ ERR_YOUREBANNEDCREEP = "465" ERR_YOUWILLBEBANNED = "466" ERR_KEYSET = "467" ERR_INVALIDUSERNAME = "468" +ERR_LINKCHANNEL = "470" ERR_CHANNELISFULL = "471" ERR_UNKNOWNMODE = "472" ERR_INVITEONLYCHAN = "473" diff --git a/irctest/server_tests/test_channel_forward.py b/irctest/server_tests/test_channel_forward.py new file mode 100644 index 0000000..5f56afd --- /dev/null +++ b/irctest/server_tests/test_channel_forward.py @@ -0,0 +1,44 @@ +from irctest import cases +from irctest.numerics import ERR_CHANOPRIVSNEEDED, ERR_INVALIDMODEPARAM, ERR_LINKCHANNEL + +MODERN_CAPS = ['server-time', 'message-tags', 'batch', 'labeled-response', 'echo-message', 'account-tag'] + +class ChannelForwarding(cases.BaseServerTestCase): + """Test the +f channel forwarding mode.""" + + @cases.SpecificationSelector.requiredBySpecification('Oragono') + def testChannelForwarding(self): + self.connectClient('bar', name='bar', capabilities=MODERN_CAPS) + self.connectClient('baz', name='baz', capabilities=MODERN_CAPS) + self.joinChannel('bar', '#bar') + self.joinChannel('bar', '#bar_two') + self.joinChannel('baz', '#baz') + + self.sendLine('bar', 'MODE #bar +f #nonexistent') + msg = self.getMessage('bar') + self.assertMessageEqual(msg, command=ERR_INVALIDMODEPARAM) + + # need chanops in the target channel as well + self.sendLine('bar', 'MODE #bar +f #baz') + responses = set(msg.command for msg in self.getMessages('bar')) + self.assertIn(ERR_CHANOPRIVSNEEDED, responses) + + self.sendLine('bar', 'MODE #bar +f #bar_two') + msg = self.getMessage('bar') + self.assertMessageEqual(msg, command='MODE', params=['#bar', '+f', '#bar_two']) + + # can still join the channel fine + self.joinChannel('baz', '#bar') + self.sendLine('baz', 'PART #bar') + self.getMessages('baz') + + # now make it invite-only, which should cause forwarding + self.sendLine('bar', 'MODE #bar +i') + self.getMessages('bar') + + self.sendLine('baz', 'JOIN #bar') + msgs = self.getMessages('baz') + forward = [msg for msg in msgs if msg.command == ERR_LINKCHANNEL] + self.assertEqual(forward[0].params[:3], ['baz', '#bar', '#bar_two']) + join = [msg for msg in msgs if msg.command == 'JOIN'] + self.assertMessageEqual(join[0], params=['#bar_two'])