mirror of https://github.com/progval/irctest.git
Add tests for the draft bot mode.
This commit is contained in:
parent
98824a4abd
commit
26a0245a6a
2
Makefile
2
Makefile
|
@ -25,6 +25,7 @@ ERGO_SELECTORS := \
|
||||||
# testNoticeNonexistentChannel fails because of https://github.com/inspircd/inspircd/issues/1849
|
# testNoticeNonexistentChannel fails because of https://github.com/inspircd/inspircd/issues/1849
|
||||||
# testDirectMessageEcho fails because of https://github.com/inspircd/inspircd/issues/1851
|
# testDirectMessageEcho fails because of https://github.com/inspircd/inspircd/issues/1851
|
||||||
# testKeyValidation fails because of https://github.com/inspircd/inspircd/issues/1850
|
# testKeyValidation fails because of https://github.com/inspircd/inspircd/issues/1850
|
||||||
|
# testBotPrivateMessage and testBotChannelMessage fail because https://github.com/inspircd/inspircd/pull/1910 is not released yet
|
||||||
INSPIRCD_SELECTORS := \
|
INSPIRCD_SELECTORS := \
|
||||||
not Ergo \
|
not Ergo \
|
||||||
and not deprecated \
|
and not deprecated \
|
||||||
|
@ -32,6 +33,7 @@ INSPIRCD_SELECTORS := \
|
||||||
and not testNoticeNonexistentChannel \
|
and not testNoticeNonexistentChannel \
|
||||||
and not testDirectMessageEcho \
|
and not testDirectMessageEcho \
|
||||||
and not testKeyValidation \
|
and not testKeyValidation \
|
||||||
|
and not testBotPrivateMessage and not testBotChannelMessage \
|
||||||
$(EXTRA_SELECTORS)
|
$(EXTRA_SELECTORS)
|
||||||
|
|
||||||
MAMMON_SELECTORS := \
|
MAMMON_SELECTORS := \
|
||||||
|
|
|
@ -36,6 +36,7 @@ TEMPLATE_CONFIG = """
|
||||||
target="services.example.org">
|
target="services.example.org">
|
||||||
|
|
||||||
# Protocol:
|
# Protocol:
|
||||||
|
<module name="botmode">
|
||||||
<module name="cap">
|
<module name="cap">
|
||||||
<module name="ircv3">
|
<module name="ircv3">
|
||||||
<module name="ircv3_accounttag">
|
<module name="ircv3_accounttag">
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
"""
|
||||||
|
Draft bot mode specification, as defined in
|
||||||
|
<https://ircv3.net/specs/extensions/bot-mode>
|
||||||
|
"""
|
||||||
|
|
||||||
|
from irctest import cases, runner
|
||||||
|
from irctest.numerics import RPL_WHOISBOT
|
||||||
|
from irctest.patma import ANYDICT, ANYSTR, StrRe
|
||||||
|
|
||||||
|
|
||||||
|
@cases.mark_specifications("IRCv3")
|
||||||
|
@cases.mark_isupport("BOT")
|
||||||
|
class BotModeTestCase(cases.BaseServerTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.connectClient("modegetter")
|
||||||
|
if "BOT" not in self.server_support:
|
||||||
|
raise runner.IsupportTokenNotSupported("BOT")
|
||||||
|
self._mode_char = self.server_support["BOT"]
|
||||||
|
|
||||||
|
def _initBot(self):
|
||||||
|
self.assertEqual(
|
||||||
|
len(self._mode_char),
|
||||||
|
1,
|
||||||
|
fail_msg=(
|
||||||
|
f"BOT ISUPPORT token should be exactly one character, "
|
||||||
|
f"but is: {self._mode_char!r}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.connectClient("botnick", "bot")
|
||||||
|
|
||||||
|
self.sendLine("bot", f"MODE botnick +{self._mode_char}")
|
||||||
|
|
||||||
|
# Check echoed mode
|
||||||
|
self.assertMessageMatch(
|
||||||
|
self.getMessage("bot"),
|
||||||
|
command="MODE",
|
||||||
|
params=["botnick", StrRe(r"\+?" + self._mode_char)],
|
||||||
|
)
|
||||||
|
|
||||||
|
def testBotMode(self):
|
||||||
|
self._initBot()
|
||||||
|
|
||||||
|
def testBotWhois(self):
|
||||||
|
self._initBot()
|
||||||
|
|
||||||
|
self.connectClient("usernick", "user")
|
||||||
|
self.sendLine("user", "WHOIS botnick")
|
||||||
|
messages = self.getMessages("user")
|
||||||
|
messages = [msg for msg in messages if msg.command == RPL_WHOISBOT]
|
||||||
|
self.assertEqual(
|
||||||
|
len(messages),
|
||||||
|
1,
|
||||||
|
msg=(
|
||||||
|
f"Expected exactly one RPL_WHOISBOT ({RPL_WHOISBOT}), "
|
||||||
|
f"got: {messages}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
(message,) = messages
|
||||||
|
self.assertMessageMatch(
|
||||||
|
message, command=RPL_WHOISBOT, params=["usernick", "botnick", ANYSTR]
|
||||||
|
)
|
||||||
|
|
||||||
|
def testBotPrivateMessage(self):
|
||||||
|
self._initBot()
|
||||||
|
|
||||||
|
self.connectClient("usernick", "user", capabilities=["message-tags"])
|
||||||
|
|
||||||
|
self.sendLine("bot", "PRIVMSG usernick :beep boop")
|
||||||
|
self.assertMessageMatch(
|
||||||
|
self.getMessage("user"),
|
||||||
|
command="PRIVMSG",
|
||||||
|
params=["usernick", "beep boop"],
|
||||||
|
tags={"draft/bot": None, **ANYDICT},
|
||||||
|
)
|
||||||
|
|
||||||
|
def testBotChannelMessage(self):
|
||||||
|
self._initBot()
|
||||||
|
|
||||||
|
self.connectClient("usernick", "user", capabilities=["message-tags"])
|
||||||
|
|
||||||
|
self.sendLine("bot", "JOIN #chan")
|
||||||
|
self.sendLine("user", "JOIN #chan")
|
||||||
|
self.getMessages("bot")
|
||||||
|
self.getMessages("user")
|
||||||
|
|
||||||
|
self.sendLine("bot", "PRIVMSG #chan :beep boop")
|
||||||
|
self.assertMessageMatch(
|
||||||
|
self.getMessage("user"),
|
||||||
|
command="PRIVMSG",
|
||||||
|
params=["#chan", "beep boop"],
|
||||||
|
tags={"draft/bot": None, **ANYDICT},
|
||||||
|
)
|
||||||
|
|
||||||
|
def testBotWhox(self):
|
||||||
|
self._initBot()
|
||||||
|
|
||||||
|
self.connectClient("usernick", "user", capabilities=["message-tags"])
|
||||||
|
|
||||||
|
self.sendLine("bot", "JOIN #chan")
|
||||||
|
self.sendLine("user", "JOIN #chan")
|
||||||
|
self.getMessages("bot")
|
||||||
|
self.getMessages("user")
|
||||||
|
|
||||||
|
self.sendLine("user", "WHO #chan")
|
||||||
|
msg1 = self.getMessage("user")
|
||||||
|
self.assertMessageMatch(
|
||||||
|
msg1, command="352", fail_msg="Expected WHO response (352), got: {msg}"
|
||||||
|
)
|
||||||
|
msg2 = self.getMessage("user")
|
||||||
|
self.assertMessageMatch(
|
||||||
|
msg2, command="352", fail_msg="Expected WHO response (352), got: {msg}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if msg1.params[5] == "botnick":
|
||||||
|
msg = msg1
|
||||||
|
elif msg2.params[5] == "botnick":
|
||||||
|
msg = msg2
|
||||||
|
else:
|
||||||
|
assert False, "No WHO response contained botnick"
|
||||||
|
|
||||||
|
self.assertMessageMatch(
|
||||||
|
msg,
|
||||||
|
command="352",
|
||||||
|
params=[
|
||||||
|
"usernick",
|
||||||
|
"#chan",
|
||||||
|
ANYSTR, # ident
|
||||||
|
ANYSTR, # hostname
|
||||||
|
ANYSTR, # server
|
||||||
|
"botnick",
|
||||||
|
StrRe(f".*{self._mode_char}.*"),
|
||||||
|
ANYSTR, # realname
|
||||||
|
],
|
||||||
|
fail_msg="Expected WHO response with bot flag, got: {msg}",
|
||||||
|
)
|
|
@ -49,6 +49,7 @@ class Capabilities(enum.Enum):
|
||||||
|
|
||||||
@enum.unique
|
@enum.unique
|
||||||
class IsupportTokens(enum.Enum):
|
class IsupportTokens(enum.Enum):
|
||||||
|
BOT = "BOT"
|
||||||
MONITOR = "MONITOR"
|
MONITOR = "MONITOR"
|
||||||
STATUSMSG = "STATUSMSG"
|
STATUSMSG = "STATUSMSG"
|
||||||
|
|
||||||
|
|
|
@ -26,5 +26,6 @@ markers =
|
||||||
sts
|
sts
|
||||||
|
|
||||||
# isupport tokens
|
# isupport tokens
|
||||||
|
BOT
|
||||||
MONITOR
|
MONITOR
|
||||||
STATUSMSG
|
STATUSMSG
|
||||||
|
|
Loading…
Reference in New Issue