diff --git a/irctest/server_tests/chmodes/key.py b/irctest/server_tests/chmodes/key.py index fd4c008e..e5c774bb 100644 --- a/irctest/server_tests/chmodes/key.py +++ b/irctest/server_tests/chmodes/key.py @@ -44,8 +44,8 @@ def testKeyNormal(self): @pytest.mark.parametrize( "key", - ["passphrase with spaces", "long" * 100, ""], - ids=["spaces", "long", "empty"], + ["passphrase with spaces", "long" * 100, "", " "], + ids=["spaces", "long", "empty", "only-space"], ) @cases.mark_specifications("RFC2812", "Modern") def testKeyValidation(self, key): diff --git a/irctest/server_tests/connection_registration.py b/irctest/server_tests/connection_registration.py index 7399cb9c..394d9f24 100644 --- a/irctest/server_tests/connection_registration.py +++ b/irctest/server_tests/connection_registration.py @@ -5,6 +5,8 @@ TODO: cross-reference Modern and RFC 2812 too """ +import time + from irctest import cases from irctest.client_mock import ConnectionClosed from irctest.numerics import ERR_NEEDMOREPARAMS, ERR_PASSWDMISMATCH @@ -133,7 +135,7 @@ def testNickCollision(self): self.assertNotEqual( m.command, "001", - "Received 001 after registering with the nick of a " "registered user.", + "Received 001 after registering with the nick of a registered user.", ) def testEarlyNickCollision(self): @@ -206,3 +208,55 @@ def testEmptyRealname(self): command=ERR_NEEDMOREPARAMS, params=[StrRe(r"(\*|foo)"), "USER", ANYSTR], ) + + def testNonutf8Realname(self): + self.addClient() + self.sendLine(1, "NICK foo") + line = b"USER username * * :i\xe8rc\xe9\r\n" + print("1 -> S (repr): " + repr(line)) + self.clients[1].conn.sendall(line) + for _ in range(10): + time.sleep(1) + d = self.clients[1].conn.recv(10000) + self.assertTrue(d, "Server closed connection") + print("S -> 1 (repr): " + repr(d)) + if b" 001 " in d: + break + if b"ERROR " in d: + # Rejected; nothing more to test. + return + if d.startswith(b"PING "): + line = d.split(b"\r\n")[0].replace(b"PING", b"PONG") + b"\r\n" + print("1 -> S (repr): " + repr(line)) + self.clients[1].conn.sendall(line) + else: + self.assertTrue(False, "stuck waiting") + self.sendLine(1, "WHOIS foo") + d = self.clients[1].conn.recv(10000) + print("S -> 1 (repr): " + repr(d)) + self.assertIn(b"username", d) + + def testNonutf8Username(self): + self.addClient() + self.sendLine(1, "NICK foo") + self.sendLine(1, "USER 😊😊😊😊😊😊😊😊😊😊 * * :realname") + for _ in range(10): + time.sleep(1) + d = self.clients[1].conn.recv(10000) + self.assertTrue(d, "Server closed connection") + print("S -> 1 (repr): " + repr(d)) + if b" 001 " in d: + break + if b" 468" in d or b"ERROR " in d: + # Rejected; nothing more to test. + return + if d.startswith(b"PING "): + line = d.split(b"\r\n")[0].replace(b"PING", b"PONG") + b"\r\n" + print("1 -> S (repr): " + repr(line)) + self.clients[1].conn.sendall(line) + else: + self.assertTrue(False, "stuck waiting") + self.sendLine(1, "WHOIS foo") + d = self.clients[1].conn.recv(10000) + print("S -> 1 (repr): " + repr(d)) + self.assertIn(b"realname", d) diff --git a/irctest/server_tests/messages.py b/irctest/server_tests/messages.py index 441446df..914293a7 100644 --- a/irctest/server_tests/messages.py +++ b/irctest/server_tests/messages.py @@ -53,6 +53,25 @@ def testPrivmsgNonexistentUser(self): # ERR_NOSUCHNICK: 401 :No such nick self.assertMessageMatch(msg, command="401", params=["foo", "bar", ANYSTR]) + @cases.mark_specifications("RFC1459", "RFC2812", "Modern") + def testEmptyPrivmsg(self): + self.connectClient("foo") + self.sendLine(1, "JOIN #chan") + self.getMessages(1) # synchronize + self.connectClient("bar") + self.sendLine(2, "JOIN #chan") + self.getMessages(2) # synchronize + self.getMessages(1) # synchronize + self.sendLine(1, "PRIVMSG #chan :") + + self.assertMessageMatch( + self.getMessage(1), + command="412", # ERR_NOTEXTTOSEND + params=["foo", ANYSTR], + ) + self.assertEqual(self.getMessages(2), []) + + class NoticeTestCase(cases.BaseServerTestCase): @cases.mark_specifications("RFC1459", "RFC2812") diff --git a/irctest/server_tests/utf8.py b/irctest/server_tests/utf8.py index bb5e77da..be72be2d 100644 --- a/irctest/server_tests/utf8.py +++ b/irctest/server_tests/utf8.py @@ -46,3 +46,23 @@ def testUtf8Validation(self): if m.command in ("FAIL", "WARN"): self.assertMessageMatch(m, params=["PRIVMSG", "INVALID_UTF8", ANYSTR]) + + def testNonutf8Realname(self): + self.addClient() + self.sendLine(1, "NICK foo") + self.clients[1].conn.sendall(b"USER username * * :i\xe8rc\xe9\r\n") + self.assertIn(b" 001 ", self.clients[1].conn.recv(1024)) + self.sendLine(1, "WHOIS foo") + self.getMessages(1) + + def testNonutf8Username(self): + self.addClient() + self.sendLine(1, "NICK foo") + self.sendLine(1, "USER 😊😊😊😊😊😊😊😊😊😊 * * :realname") + m = self.getRegistrationMessage(1) + self.assertMessageMatch( + m, + command="001", + ) + self.sendLine(1, "WHOIS foo") + self.getMessages(1)