2022-04-10 12:51:14 +00:00
|
|
|
|
"""
|
|
|
|
|
`Ergo <https://ergo.chat/>`_-specific tests of non-Unicode filtering
|
|
|
|
|
|
|
|
|
|
<https://ircv3.net/specs/extensions/utf8-only>`_
|
|
|
|
|
"""
|
|
|
|
|
|
2023-01-28 09:12:32 +00:00
|
|
|
|
from irctest import cases, runner
|
2023-12-21 08:52:33 +00:00
|
|
|
|
from irctest.numerics import ERR_ERRONEUSNICKNAME
|
2021-03-01 19:18:09 +00:00
|
|
|
|
from irctest.patma import ANYSTR
|
2020-06-22 19:48:56 +00:00
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
|
2022-04-12 16:48:03 +00:00
|
|
|
|
class Utf8TestCase(cases.BaseServerTestCase):
|
2021-05-27 03:55:21 +00:00
|
|
|
|
@cases.mark_specifications("Ergo")
|
2023-01-28 09:12:32 +00:00
|
|
|
|
def testNonUtf8Filtering(self):
|
2021-02-22 18:02:13 +00:00
|
|
|
|
self.connectClient(
|
|
|
|
|
"bar",
|
2021-03-01 19:18:09 +00:00
|
|
|
|
capabilities=["batch", "echo-message", "labeled-response"],
|
2021-02-22 18:02:13 +00:00
|
|
|
|
)
|
|
|
|
|
self.joinChannel(1, "#qux")
|
2023-01-28 09:12:32 +00:00
|
|
|
|
self.sendLine(1, b"@label=xyz PRIVMSG #qux hi\xaa")
|
2021-03-01 19:18:09 +00:00
|
|
|
|
self.assertMessageMatch(
|
|
|
|
|
self.getMessage(1),
|
|
|
|
|
command="FAIL",
|
|
|
|
|
params=["PRIVMSG", "INVALID_UTF8", ANYSTR],
|
2023-01-28 09:12:32 +00:00
|
|
|
|
tags={"label": "xyz"},
|
2021-03-01 19:18:09 +00:00
|
|
|
|
)
|
2020-06-22 19:48:56 +00:00
|
|
|
|
|
2023-01-28 09:12:32 +00:00
|
|
|
|
@cases.mark_isupport("UTF8ONLY")
|
|
|
|
|
def testUtf8Validation(self):
|
|
|
|
|
self.connectClient("foo")
|
|
|
|
|
self.connectClient("bar")
|
|
|
|
|
|
|
|
|
|
if "UTF8ONLY" not in self.server_support:
|
|
|
|
|
raise runner.IsupportTokenNotSupported("UTF8ONLY")
|
|
|
|
|
|
|
|
|
|
self.sendLine(1, "PRIVMSG bar hi")
|
2023-02-11 21:26:23 +00:00
|
|
|
|
self.getMessages(1) # synchronize
|
2023-01-28 09:12:32 +00:00
|
|
|
|
ms = self.getMessages(2)
|
2021-03-01 19:18:09 +00:00
|
|
|
|
self.assertMessageMatch(
|
2023-01-28 09:12:32 +00:00
|
|
|
|
[m for m in ms if m.command == "PRIVMSG"][0], params=["bar", "hi"]
|
2021-03-01 19:18:09 +00:00
|
|
|
|
)
|
2023-01-28 09:12:32 +00:00
|
|
|
|
|
|
|
|
|
self.sendLine(1, b"PRIVMSG bar hi\xaa")
|
|
|
|
|
|
|
|
|
|
m = self.getMessage(1)
|
|
|
|
|
assert m.command in ("FAIL", "WARN", "ERROR")
|
|
|
|
|
|
|
|
|
|
if m.command in ("FAIL", "WARN"):
|
|
|
|
|
self.assertMessageMatch(m, params=["PRIVMSG", "INVALID_UTF8", ANYSTR])
|
2023-09-18 18:31:50 +00:00
|
|
|
|
|
|
|
|
|
def testNonutf8Realname(self):
|
|
|
|
|
self.connectClient("foo")
|
|
|
|
|
if "UTF8ONLY" not in self.server_support:
|
|
|
|
|
raise runner.IsupportTokenNotSupported("UTF8ONLY")
|
|
|
|
|
|
|
|
|
|
self.addClient()
|
2023-12-31 18:47:18 +00:00
|
|
|
|
self.sendLine(2, "NICK bar")
|
2023-09-18 18:31:50 +00:00
|
|
|
|
self.clients[2].conn.sendall(b"USER username * * :i\xe8rc\xe9\r\n")
|
|
|
|
|
|
2024-04-19 13:13:51 +00:00
|
|
|
|
d = b""
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
buf = self.clients[2].conn.recv(1024)
|
|
|
|
|
except TimeoutError:
|
|
|
|
|
break
|
|
|
|
|
if d and not buf:
|
|
|
|
|
break
|
|
|
|
|
d += buf
|
|
|
|
|
if b"FAIL " in d or b"ERROR " in d or b"468 " in d: # ERR_INVALIDUSERNAME
|
2023-09-18 18:31:50 +00:00
|
|
|
|
return # nothing more to test
|
2023-12-31 18:47:18 +00:00
|
|
|
|
self.assertIn(b"001 ", d)
|
2023-09-18 18:31:50 +00:00
|
|
|
|
|
2023-12-31 18:47:18 +00:00
|
|
|
|
self.sendLine(2, "WHOIS bar")
|
2023-09-18 18:31:50 +00:00
|
|
|
|
self.getMessages(2)
|
|
|
|
|
|
|
|
|
|
def testNonutf8Username(self):
|
|
|
|
|
self.connectClient("foo")
|
|
|
|
|
if "UTF8ONLY" not in self.server_support:
|
|
|
|
|
raise runner.IsupportTokenNotSupported("UTF8ONLY")
|
|
|
|
|
|
|
|
|
|
self.addClient()
|
2023-12-31 18:47:18 +00:00
|
|
|
|
self.sendLine(2, "NICK bar")
|
2024-04-19 13:10:22 +00:00
|
|
|
|
self.clients[2].conn.sendall(b"USER \xe8rc\xe9 * * :readlname\r\n")
|
|
|
|
|
|
2024-04-19 13:13:51 +00:00
|
|
|
|
d = b""
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
buf = self.clients[2].conn.recv(1024)
|
|
|
|
|
except TimeoutError:
|
|
|
|
|
break
|
|
|
|
|
if d and not buf:
|
|
|
|
|
break
|
|
|
|
|
d += buf
|
|
|
|
|
if b"FAIL " in d or b"ERROR " in d or b"468 " in d: # ERR_INVALIDUSERNAME
|
2023-09-18 18:31:50 +00:00
|
|
|
|
return # nothing more to test
|
2024-04-19 13:10:22 +00:00
|
|
|
|
self.assertIn(b"001 ", d)
|
|
|
|
|
|
2023-12-31 18:47:18 +00:00
|
|
|
|
self.sendLine(2, "WHOIS bar")
|
2023-09-18 18:31:50 +00:00
|
|
|
|
self.getMessages(2)
|
2023-12-21 08:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ErgoUtf8NickEnabledTestCase(cases.BaseServerTestCase):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def config() -> cases.TestCaseControllerConfig:
|
|
|
|
|
return cases.TestCaseControllerConfig(
|
|
|
|
|
ergo_config=lambda config: config["server"].update(
|
|
|
|
|
{"casemapping": "precis"},
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@cases.mark_specifications("Ergo")
|
|
|
|
|
def testUtf8NonAsciiNick(self):
|
|
|
|
|
"""Ergo accepts certain non-ASCII UTF8 nicknames if PRECIS is enabled."""
|
|
|
|
|
self.connectClient("Işıl")
|
|
|
|
|
self.joinChannel(1, "#test")
|
|
|
|
|
|
|
|
|
|
self.connectClient("Claire")
|
|
|
|
|
self.joinChannel(2, "#test")
|
|
|
|
|
|
|
|
|
|
self.sendLine(1, "PRIVMSG #test :hi there")
|
2023-12-24 06:11:29 +00:00
|
|
|
|
self.getMessages(1)
|
2023-12-21 08:52:33 +00:00
|
|
|
|
self.assertMessageMatch(
|
|
|
|
|
self.getMessage(2), nick="Işıl", params=["#test", "hi there"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ErgoUtf8NickDisabledTestCase(cases.BaseServerTestCase):
|
|
|
|
|
@cases.mark_specifications("Ergo")
|
|
|
|
|
def testUtf8NonAsciiNick(self):
|
|
|
|
|
"""Ergo rejects non-ASCII nicknames in its default configuration."""
|
|
|
|
|
self.addClient(1)
|
|
|
|
|
self.sendLine(1, "USER u s e r")
|
|
|
|
|
self.sendLine(1, "NICK Işıl")
|
|
|
|
|
self.assertMessageMatch(self.getMessage(1), command=ERR_ERRONEUSNICKNAME)
|