Skip to content

Commit

Permalink
Add various validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Sep 3, 2023
1 parent c58167b commit b72f369
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
4 changes: 2 additions & 2 deletions irctest/server_tests/chmodes/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
56 changes: 55 additions & 1 deletion irctest/server_tests/connection_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
19 changes: 19 additions & 0 deletions irctest/server_tests/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ def testPrivmsgNonexistentUser(self):
# ERR_NOSUCHNICK: 401 <sender> <recipient> :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")
Expand Down
20 changes: 20 additions & 0 deletions irctest/server_tests/utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b72f369

Please sign in to comment.