irctest/irctest/server_tests/channel_forward.py

59 lines
2.0 KiB
Python
Raw Permalink Normal View History

"""
`Ergo <https://ergo.chat/>`_-specific tests of channel forwarding
TODO: Should be extended to other servers, once a specification is written.
"""
2020-12-14 10:22:41 +00:00
from irctest import cases
from irctest.numerics import ERR_CHANOPRIVSNEEDED, ERR_INVALIDMODEPARAM, ERR_LINKCHANNEL
2021-02-22 18:02:13 +00:00
MODERN_CAPS = [
"server-time",
"message-tags",
"batch",
"labeled-response",
"echo-message",
"account-tag",
]
2020-12-14 10:22:41 +00:00
class ChannelForwardingTestCase(cases.BaseServerTestCase):
2020-12-14 10:22:41 +00:00
"""Test the +f channel forwarding mode."""
2021-05-27 03:55:21 +00:00
@cases.mark_specifications("Ergo")
2020-12-14 10:22:41 +00:00
def testChannelForwarding(self):
2021-02-22 18:02:13 +00:00
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.assertMessageMatch(msg, command=ERR_INVALIDMODEPARAM)
2020-12-14 10:22:41 +00:00
# need chanops in the target channel as well
2021-02-22 18:02:13 +00:00
self.sendLine("bar", "MODE #bar +f #baz")
responses = set(msg.command for msg in self.getMessages("bar"))
2020-12-14 10:22:41 +00:00
self.assertIn(ERR_CHANOPRIVSNEEDED, responses)
2021-02-22 18:02:13 +00:00
self.sendLine("bar", "MODE #bar +f #bar_two")
msg = self.getMessage("bar")
self.assertMessageMatch(msg, command="MODE", params=["#bar", "+f", "#bar_two"])
2020-12-14 10:22:41 +00:00
# can still join the channel fine
2021-02-22 18:02:13 +00:00
self.joinChannel("baz", "#bar")
self.sendLine("baz", "PART #bar")
self.getMessages("baz")
2020-12-14 10:22:41 +00:00
# now make it invite-only, which should cause forwarding
2021-02-22 18:02:13 +00:00
self.sendLine("bar", "MODE #bar +i")
self.getMessages("bar")
2020-12-14 10:22:41 +00:00
2021-02-22 18:02:13 +00:00
self.sendLine("baz", "JOIN #bar")
msgs = self.getMessages("baz")
2020-12-14 10:22:41 +00:00
forward = [msg for msg in msgs if msg.command == ERR_LINKCHANNEL]
2021-02-22 18:02:13 +00:00
self.assertEqual(forward[0].params[:3], ["baz", "#bar", "#bar_two"])
join = [msg for msg in msgs if msg.command == "JOIN"]
self.assertMessageMatch(join[0], params=["#bar_two"])