statusmsg: Make tests non Oragono-specific.

This commit is contained in:
Valentin Lorentz 2021-02-27 15:58:02 +01:00 committed by Valentin Lorentz
parent da9567b612
commit 70fcc15e00
3 changed files with 65 additions and 4 deletions

View File

@ -1,4 +1,4 @@
from irctest import cases
from irctest import cases, runner
from irctest.numerics import RPL_NAMREPLY
@ -9,13 +9,68 @@ class StatusmsgTestCase(cases.BaseServerTestCase):
self.connectClient("foo") # detects ISUPPORT
self.assertEqual(self.server_support["STATUSMSG"], "~&@%+")
@cases.mark_specifications("Oragono")
def testStatusmsg(self):
@cases.mark_isupport("STATUSMSG")
def testStatusmsgFromOp(self):
"""Test that STATUSMSG are sent to the intended recipients,
with the intended prefixes."""
self.connectClient("chanop")
self.joinChannel(1, "#chan")
self.getMessages(1)
if "@" not in self.server_support.get("STATUSMSG", ""):
raise runner.IsupportTokenNotSupported("STATUSMSG")
self.connectClient("joe")
self.joinChannel(2, "#chan")
self.getMessages(2)
self.connectClient("schmoe")
self.sendLine(3, "join #chan")
self.sendLine(1, "MODE #chan +o schmoe")
self.getMessages(1)
messages = self.getMessages(3)
names = set()
for message in messages:
if message.command == RPL_NAMREPLY:
names.update(set(message.params[-1].split()))
# chanop should be opped
self.assertEqual(
names, {"@chanop", "joe", "schmoe"}, f"unexpected names: {names}"
)
self.getMessages(3)
self.sendLine(3, "privmsg @#chan :this message is for operators")
self.assertEqual(
self.getMessages(3),
[],
fail_msg="PRIVMSG @#chan from channel op was refused",
)
# check the operator's messages
statusMsg = self.getMessage(1, filter_pred=lambda m: m.command == "PRIVMSG")
self.assertMessageEqual(
statusMsg, params=["@#chan", "this message is for operators"]
)
# check the non-operator's messages
unprivilegedMessages = [
msg for msg in self.getMessages(2) if msg.command == "PRIVMSG"
]
self.assertEqual(len(unprivilegedMessages), 0)
@cases.mark_isupport("STATUSMSG")
def testStatusmsgFromRegular(self):
"""Test that STATUSMSG are sent to the intended recipients,
with the intended prefixes."""
self.connectClient("chanop")
self.joinChannel(1, "#chan")
self.getMessages(1)
if "@" not in self.server_support.get("STATUSMSG", ""):
raise runner.IsupportTokenNotSupported("STATUSMSG")
self.connectClient("joe")
self.joinChannel(2, "#chan")
self.getMessages(2)
@ -32,8 +87,12 @@ class StatusmsgTestCase(cases.BaseServerTestCase):
names, {"@chanop", "joe", "schmoe"}, f"unexpected names: {names}"
)
self.sendLine(3, "privmsg @#chan :this message is for operators")
self.getMessages(3)
self.sendLine(3, "privmsg @#chan :this message is for operators")
if self.getMessages(3) != []:
raise runner.ImplementationChoice(
"Regular users can not send PRIVMSG @#chan"
)
# check the operator's messages
statusMsg = self.getMessage(1, filter_pred=lambda m: m.command == "PRIVMSG")

View File

@ -46,6 +46,7 @@ class Capabilities(enum.Enum):
@enum.unique
class IsupportTokens(enum.Enum):
MONITOR = "MONITOR"
STATUSMSG = "STATUSMSG"
@classmethod
def from_name(cls, name):

View File

@ -25,3 +25,4 @@ markers =
# isupport tokens
MONITOR
STATUSMSG