Add tests for WALLOPS (#109)

* Add tests for WALLOPS

* Add perms on plexus/hybrid, skip on ergo, laxer matching for ircu2

* Fix again for irc2 and ircu2

* Servers MAY send WALLOPS only to operators.
This commit is contained in:
Val Lorentz 2021-09-19 15:33:31 +02:00 committed by GitHub
parent 29bfb064e9
commit 5e4ae7c999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 2 deletions

View File

@ -90,12 +90,14 @@ SNIRCD_SELECTORS := \
# testListEmpty and testListOne fails because irc2 deprecated LIST
# testKickDefaultComment fails because it uses the nick of the kickee rather than the kicker.
# testWallopsPrivileges fails because it ignores the command instead of replying ERR_UNKNOWNCOMMAND
IRC2_SELECTORS := \
not Ergo \
and not deprecated \
and not strict \
and not testListEmpty and not testListOne \
and not testKickDefaultComment \
and not testWallopsPrivileges \
$(EXTRA_SELECTORS)
MAMMON_SELECTORS := \

View File

@ -63,7 +63,7 @@ operator {{
encrypted = no;
umodes = locops, servnotice, wallop;
flags = admin, connect, connect:remote, die, globops, kill, kill:remote,
kline, module, rehash, restart, set, unkline, unxline, xline;
kline, module, rehash, restart, set, unkline, unxline, wallops, xline;
}};
"""

View File

@ -21,6 +21,7 @@ TEMPLATE_CONFIG = """
<class
name="ServerOperators"
commands="WALLOPS GLOBOPS"
privs="channels/auspex users/auspex channels/auspex servers/auspex"
>
<type

View File

@ -68,7 +68,7 @@ operator {{
encrypted = no;
umodes = locops, servnotice, wallop;
flags = admin, connect, connect:remote, die, globops, kill, kill:remote,
kline, module, rehash, restart, set, unkline, unxline, xline;
kline, module, rehash, restart, set, unkline, unxline, wallops, xline;
}};
"""

View File

@ -0,0 +1,74 @@
from irctest import cases, runner
from irctest.numerics import ERR_NOPRIVILEGES, ERR_UNKNOWNCOMMAND, RPL_YOUREOPER
from irctest.patma import ANYSTR, StrRe
class WallopsTestCase(cases.BaseServerTestCase):
@cases.mark_specifications("RFC2812", "Modern")
def testWallops(self):
"""
"The WALLOPS command is used to send a message to all currently connected
users who have set the 'w' user mode for themselves."
-- https://datatracker.ietf.org/doc/html/rfc2812#section-4.7
-- https://github.com/ircdocs/modern-irc/pull/118
"Servers MAY echo WALLOPS messages to their sender even if they don't have
the 'w' user mode.
Servers MAY send WALLOPS only to operators."
-- https://github.com/ircdocs/modern-irc/pull/118
"""
self.connectClient("nick1")
self.connectClient("nick2")
self.connectClient("nick3")
self.sendLine(2, "MODE nick2 -w")
self.getMessages(2)
self.sendLine(3, "MODE nick3 +w")
self.getMessages(3)
self.sendLine(1, "OPER operuser operpassword")
self.assertIn(
RPL_YOUREOPER,
[m.command for m in self.getMessages(1)],
fail_msg="OPER failed",
)
self.sendLine(1, "WALLOPS :hi everyone")
messages = self.getMessages(1)
if ERR_UNKNOWNCOMMAND in (message.command for message in messages):
raise runner.NotImplementedByController("WALLOPS")
for message in messages:
self.assertMessageMatch(
message,
prefix=StrRe("nick1!.*"),
command="WALLOPS",
params=[StrRe(".*hi everyone")],
)
messages = self.getMessages(3)
if messages:
self.assertMessageMatch(
messages[0],
prefix=StrRe("nick1!.*"),
command="WALLOPS",
params=[StrRe(".*hi everyone")],
)
self.assertEqual(
self.getMessages(2), [], fail_msg="Server sent WALLOPS to user without +w"
)
@cases.mark_specifications("Modern")
def testWallopsPrivileges(self):
"""
https://github.com/ircdocs/modern-irc/pull/118
"""
self.connectClient("nick1")
self.sendLine(1, "WALLOPS :hi everyone")
message = self.getMessage(1)
if message.command == ERR_UNKNOWNCOMMAND:
raise runner.NotImplementedByController("WALLOPS")
self.assertMessageMatch(
message, command=ERR_NOPRIVILEGES, params=["nick1", ANYSTR]
)