From 61941e2be0dd3ffe8d64cd80f86a1db140e69202 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 10 Sep 2020 02:31:23 -0400 Subject: [PATCH] test for RELAYMSG --- irctest/controllers/oragono.py | 6 +++ irctest/server_tests/test_relaymsg.py | 69 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 irctest/server_tests/test_relaymsg.py diff --git a/irctest/controllers/oragono.py b/irctest/controllers/oragono.py index 2ed21c5..eb26534 100644 --- a/irctest/controllers/oragono.py +++ b/irctest/controllers/oragono.py @@ -36,6 +36,11 @@ BASE_CONFIG = { "exempted": ["localhost"], }, 'enforce-utf8': True, + 'relaymsg': { + 'enabled': True, + 'separators': '/', + 'available-to-chanops': True, + }, }, 'accounts': { @@ -103,6 +108,7 @@ BASE_CONFIG = { "samode", "vhosts", "chanreg", + "relaymsg-anywhere", ], }, }, diff --git a/irctest/server_tests/test_relaymsg.py b/irctest/server_tests/test_relaymsg.py new file mode 100644 index 0000000..5322529 --- /dev/null +++ b/irctest/server_tests/test_relaymsg.py @@ -0,0 +1,69 @@ +from irctest import cases +from irctest.irc_utils.random import random_name +from irctest.server_tests.test_chathistory import CHATHISTORY_CAP, EVENT_PLAYBACK_CAP + + +RELAYMSG_CAP = 'draft/relaymsg' + +class RelaymsgTestCase(cases.BaseServerTestCase): + + def customizedConfig(self): + return self.controller.addMysqlToConfig() + + @cases.SpecificationSelector.requiredBySpecification('Oragono') + def testRelaymsg(self): + self.connectClient('baz', name='baz', capabilities=['server-time', 'message-tags', 'batch', 'labeled-response', 'echo-message', CHATHISTORY_CAP, EVENT_PLAYBACK_CAP]) + self.connectClient('qux', name='qux', capabilities=['server-time', 'message-tags', 'batch', 'labeled-response', 'echo-message', CHATHISTORY_CAP, EVENT_PLAYBACK_CAP]) + chname = random_name('#relaymsg') + self.joinChannel('baz', chname) + self.joinChannel('qux', chname) + self.getMessages('baz') + self.getMessages('qux') + + self.sendLine('baz', 'RELAYMSG %s invalid!nick/discord hi' % (chname,)) + response = self.getMessages('baz')[0] + self.assertEqual(response.command, 'FAIL') + self.assertEqual(response.params[:2], ['RELAYMSG', 'INVALID_NICK']) + + self.sendLine('baz', 'RELAYMSG %s regular_nick hi' % (chname,)) + response = self.getMessages('baz')[0] + self.assertEqual(response.command, 'FAIL') + self.assertEqual(response.params[:2], ['RELAYMSG', 'INVALID_NICK']) + + self.sendLine('baz', 'RELAYMSG %s smt/discord hi' % (chname,)) + response = self.getMessages('baz')[0] + self.assertMessageEqual(response, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi']) + relayed_msg = self.getMessages('qux')[0] + self.assertMessageEqual(relayed_msg, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi']) + + # labeled-response + self.sendLine('baz', '@label=x RELAYMSG %s smt/discord :hi again' % (chname,)) + response = self.getMessages('baz')[0] + self.assertMessageEqual(response, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi again']) + self.assertEqual(response.tags.get('label'), 'x') + relayed_msg = self.getMessages('qux')[0] + self.assertMessageEqual(relayed_msg, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi again']) + + self.sendLine('qux', 'RELAYMSG %s smt/discord :hi a third time' % (chname,)) + response = self.getMessages('qux')[0] + self.assertEqual(response.command, 'FAIL') + self.assertEqual(response.params[:2], ['RELAYMSG', 'NOT_PRIVED']) + + # grant qux chanop, allowing relaymsg + self.sendLine('baz', 'MODE %s +o qux' % (chname,)) + self.getMessages('baz') + self.getMessages('qux') + # give baz the relaymsg cap + self.sendLine('baz', 'CAP REQ %s' % (RELAYMSG_CAP)) + self.assertMessageEqual(self.getMessages('baz')[0], command='CAP', params=['baz', 'ACK', RELAYMSG_CAP]) + + self.sendLine('qux', 'RELAYMSG %s smt/discord :hi a third time' % (chname,)) + response = self.getMessages('qux')[0] + self.assertMessageEqual(response, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi a third time']) + relayed_msg = self.getMessages('baz')[0] + self.assertMessageEqual(relayed_msg, nick='smt/discord', command='PRIVMSG', params=[chname, 'hi a third time']) + self.assertEqual(relayed_msg.tags.get('relaymsg'), 'qux') + + self.sendLine('baz', 'CHATHISTORY LATEST %s * 10' % (chname,)) + messages = self.getMessages('baz') + self.assertEqual([msg.params[-1] for msg in messages if msg.command == 'PRIVMSG'], ['hi', 'hi again', 'hi a third time'])