mirror of https://github.com/progval/irctest.git
Simplify multi-prefix-related tests and add testNoMultiPrefix (#262)
* Simplify RPL_NAMREPLY-on-join tests * Simplify testMultiPrefix * Add testNoMultiPrefix
This commit is contained in:
parent
ea66a8f9a4
commit
9d43a002c2
|
@ -1,23 +0,0 @@
|
||||||
"""
|
|
||||||
Handles ambiguities of RFCs.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_namreply_params(params: List[str]) -> List[str]:
|
|
||||||
# So… RFC 2812 says:
|
|
||||||
# "( "=" / "*" / "@" ) <channel>
|
|
||||||
# :[ "@" / "+" ] <nick> *( " " [ "@" / "+" ] <nick> )
|
|
||||||
# but spaces seem to be missing (eg. before the colon), so we
|
|
||||||
# don't know if there should be one before the <channel> and its
|
|
||||||
# prefix.
|
|
||||||
# So let's normalize this to “with space”, and strip spaces at the
|
|
||||||
# end of the nick list.
|
|
||||||
params = list(params) # copy the list
|
|
||||||
if len(params) == 3:
|
|
||||||
assert params[1][0] in "=*@", params
|
|
||||||
params.insert(1, params[1][0])
|
|
||||||
params[2] = params[2][1:]
|
|
||||||
params[3] = params[3].rstrip()
|
|
||||||
return params
|
|
|
@ -6,7 +6,6 @@ The JOIN command (`RFC 1459
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from irctest import cases, runner
|
from irctest import cases, runner
|
||||||
from irctest.irc_utils import ambiguities
|
|
||||||
from irctest.numerics import (
|
from irctest.numerics import (
|
||||||
ERR_BADCHANMASK,
|
ERR_BADCHANMASK,
|
||||||
ERR_FORBIDDENCHANNEL,
|
ERR_FORBIDDENCHANNEL,
|
||||||
|
@ -75,33 +74,23 @@ class JoinTestCase(cases.BaseServerTestCase):
|
||||||
|
|
||||||
for m in self.getMessages(1):
|
for m in self.getMessages(1):
|
||||||
if m.command == "353":
|
if m.command == "353":
|
||||||
self.assertIn(
|
self.assertMessageMatch(
|
||||||
len(m.params),
|
m, params=["foo", StrRe(r"[=\*@]"), "#chan", StrRe("[@+]?foo")]
|
||||||
(3, 4),
|
|
||||||
m,
|
|
||||||
fail_msg="RPL_NAM_REPLY with number of arguments "
|
|
||||||
"<3 or >4: {msg}",
|
|
||||||
)
|
)
|
||||||
params = ambiguities.normalize_namreply_params(m.params)
|
|
||||||
self.assertIn(
|
self.connectClient("bar")
|
||||||
params[1],
|
self.sendLine(2, "JOIN #chan")
|
||||||
"=*@",
|
|
||||||
|
for m in self.getMessages(2):
|
||||||
|
if m.command == "353":
|
||||||
|
self.assertMessageMatch(
|
||||||
m,
|
m,
|
||||||
fail_msg="Bad channel prefix: {item} not in {list}: {msg}",
|
params=[
|
||||||
)
|
"bar",
|
||||||
self.assertEqual(
|
StrRe(r"[=\*@]"),
|
||||||
params[2],
|
"#chan",
|
||||||
"#chan",
|
StrRe("([@+]?foo bar|bar [@+]?foo)"),
|
||||||
m,
|
],
|
||||||
fail_msg="Bad channel name: {got} instead of " "{expects}: {msg}",
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
params[3],
|
|
||||||
{"foo", "@foo", "+foo"},
|
|
||||||
m,
|
|
||||||
fail_msg="Bad user list: should contain only user "
|
|
||||||
'"foo" with an optional "+" or "@" prefix, but got: '
|
|
||||||
"{msg}",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def testJoinTwice(self):
|
def testJoinTwice(self):
|
||||||
|
@ -115,34 +104,8 @@ class JoinTestCase(cases.BaseServerTestCase):
|
||||||
# if the join is successful, or has an error among the given set.
|
# if the join is successful, or has an error among the given set.
|
||||||
for m in self.getMessages(1):
|
for m in self.getMessages(1):
|
||||||
if m.command == "353":
|
if m.command == "353":
|
||||||
self.assertIn(
|
self.assertMessageMatch(
|
||||||
len(m.params),
|
m, params=["foo", StrRe(r"[=\*@]"), "#chan", StrRe("[@+]?foo")]
|
||||||
(3, 4),
|
|
||||||
m,
|
|
||||||
fail_msg="RPL_NAM_REPLY with number of arguments "
|
|
||||||
"<3 or >4: {msg}",
|
|
||||||
)
|
|
||||||
params = ambiguities.normalize_namreply_params(m.params)
|
|
||||||
self.assertIn(
|
|
||||||
params[1],
|
|
||||||
"=*@",
|
|
||||||
m,
|
|
||||||
fail_msg="Bad channel prefix: {item} not in {list}: {msg}",
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
params[2],
|
|
||||||
"#chan",
|
|
||||||
m,
|
|
||||||
fail_msg="Bad channel name: {got} instead of " "{expects}: {msg}",
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
params[3],
|
|
||||||
{"foo", "@foo", "+foo"},
|
|
||||||
m,
|
|
||||||
fail_msg='Bad user list after user "foo" joined twice '
|
|
||||||
"the same channel: should contain only user "
|
|
||||||
'"foo" with an optional "+" or "@" prefix, but got: '
|
|
||||||
"{msg}",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def testJoinPartiallyInvalid(self):
|
def testJoinPartiallyInvalid(self):
|
||||||
|
|
|
@ -24,11 +24,6 @@ class MultiPrefixTestCase(cases.BaseServerTestCase):
|
||||||
|
|
||||||
self.sendLine(1, "NAMES #chan")
|
self.sendLine(1, "NAMES #chan")
|
||||||
reply = self.getMessage(1)
|
reply = self.getMessage(1)
|
||||||
self.assertMessageMatch(
|
|
||||||
reply,
|
|
||||||
command="353",
|
|
||||||
fail_msg="Expected NAMES response (353) with @+foo, got: {msg}",
|
|
||||||
)
|
|
||||||
self.assertMessageMatch(
|
self.assertMessageMatch(
|
||||||
reply,
|
reply,
|
||||||
command="353",
|
command="353",
|
||||||
|
@ -47,9 +42,57 @@ class MultiPrefixTestCase(cases.BaseServerTestCase):
|
||||||
8,
|
8,
|
||||||
"Expected WHO response (352) with 8 params, got: {msg}".format(msg=msg),
|
"Expected WHO response (352) with 8 params, got: {msg}".format(msg=msg),
|
||||||
)
|
)
|
||||||
self.assertTrue(
|
self.assertIn(
|
||||||
"@+" in msg.params[6],
|
"@+",
|
||||||
|
msg.params[6],
|
||||||
'Expected WHO response (352) with "@+" in param 7, got: {msg}'.format(
|
'Expected WHO response (352) with "@+" in param 7, got: {msg}'.format(
|
||||||
msg=msg
|
msg=msg
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cases.xfailIfSoftware(
|
||||||
|
["irc2", "Bahamut"], "irc2 and Bahamut send a trailing space"
|
||||||
|
)
|
||||||
|
def testNoMultiPrefix(self):
|
||||||
|
"""When not requested, only the highest prefix should be sent"""
|
||||||
|
self.connectClient("foo")
|
||||||
|
self.joinChannel(1, "#chan")
|
||||||
|
self.sendLine(1, "MODE #chan +v foo")
|
||||||
|
self.getMessages(1)
|
||||||
|
|
||||||
|
# TODO(dan): Make sure +v is voice
|
||||||
|
|
||||||
|
self.sendLine(1, "NAMES #chan")
|
||||||
|
reply = self.getMessage(1)
|
||||||
|
self.assertMessageMatch(
|
||||||
|
reply,
|
||||||
|
command="353",
|
||||||
|
params=["foo", ANYSTR, "#chan", "@foo"],
|
||||||
|
fail_msg="Expected NAMES response (353) with @foo, got: {msg}",
|
||||||
|
)
|
||||||
|
self.getMessages(1)
|
||||||
|
|
||||||
|
self.sendLine(1, "WHO #chan")
|
||||||
|
msg = self.getMessage(1)
|
||||||
|
self.assertEqual(
|
||||||
|
msg.command, "352", msg, fail_msg="Expected WHO response (352), got: {msg}"
|
||||||
|
)
|
||||||
|
self.assertGreaterEqual(
|
||||||
|
len(msg.params),
|
||||||
|
8,
|
||||||
|
"Expected WHO response (352) with 8 params, got: {msg}".format(msg=msg),
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"@",
|
||||||
|
msg.params[6],
|
||||||
|
'Expected WHO response (352) with "@" in param 7, got: {msg}'.format(
|
||||||
|
msg=msg
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertNotIn(
|
||||||
|
"+",
|
||||||
|
msg.params[6],
|
||||||
|
'Expected WHO response (352) with no "+" in param 7, got: {msg}'.format(
|
||||||
|
msg=msg
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue