Skip to content

Commit

Permalink
fix buffering test
Browse files Browse the repository at this point in the history
The test for erroneous ERR_INPUTTOOLONG was counting codepoints instead
of bytes, consequently underestimating the actual relayed size of the message.
  • Loading branch information
slingamn committed Jun 11, 2024
1 parent af980ed commit 9856317
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions irctest/server_tests/buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def testNoTags(self, sender_function, colon):
if messages and ERR_INPUTTOOLONG in (m.command for m in messages):
# https://defs.ircdocs.horse/defs/numerics.html#err-inputtoolong-417
self.assertGreater(
len(line + payload + "\r\n"),
len((line + payload + "\r\n").encode()),
512 - overhead,
"Got ERR_INPUTTOOLONG for a messag that should fit "
"withing 512 characters.",
"Got ERR_INPUTTOOLONG for a message that should fit "
"within 512 characters.",
)
continue

Expand Down Expand Up @@ -125,11 +125,24 @@ def testNoTags(self, sender_function, colon):
f"expected payload to be a prefix of {payload!r}, "
f"but got {payload!r}",
)
if self.controller.software_name == "Ergo":
self.assertTrue(
payload_intact,
f"Ergo should not truncate messages: {repr(line + payload)}, {repr(received_line)}",
)

def get_overhead(self, client1, client2, colon):
self.sendLine(client1, f"PRIVMSG nick2 {colon}a\r\n")
"""Compute the overhead added to client1's message:
PRIVMSG nick2 a\r\n
:nick1!~user@host PRIVMSG nick2 :a\r\n
So typically client1's NUH length plus either 2 or 3 bytes
(the initial colon, the space between source and command, and possibly
a colon preceding the trailing).
"""
outgoing = f"PRIVMSG nick2 {colon}a\r\n"
self.sendLine(client1, outgoing)
line = self._getLine(client2)
return len(line) - len(f"PRIVMSG nick2 {colon}a\r\n")
return len(line) - len(outgoing.encode())

def _getLine(self, client) -> bytes:
line = b""
Expand Down

0 comments on commit 9856317

Please sign in to comment.