Make tests pass + update testKeyValidation to match the Modern PR

This commit is contained in:
Valentin Lorentz 2021-08-09 22:59:56 +02:00
parent d130ae89f2
commit 8744a49073
6 changed files with 41 additions and 8 deletions

View File

@ -11,10 +11,13 @@ EXTRA_SELECTORS ?=
ANOPE_SELECTORS := \
and not testPlainLarge
# buffering tests cannot pass because of issues with UTF-8 handling: https://github.com/DALnet/bahamut/issues/196
BAHAMUT_SELECTORS := \
not Ergo \
and not deprecated \
and not strict \
and not IRCv3 \
and not buffering \
$(EXTRA_SELECTORS)
# testQuitErrors is very flaky

View File

@ -40,6 +40,7 @@ from .numerics import (
ERR_NEEDREGGEDNICK,
ERR_NOSUCHCHANNEL,
ERR_TOOMANYCHANNELS,
RPL_HELLO,
)
from .specifications import Capabilities, IsupportTokens, Specifications
@ -559,7 +560,9 @@ class BaseServerTestCase(
"""Filter notices, do not send pings."""
while True:
msg = self.getMessage(
client, synchronize=False, filter_pred=lambda m: m.command != "NOTICE"
client,
synchronize=False,
filter_pred=lambda m: m.command not in ("NOTICE", RPL_HELLO),
)
if msg.command == "PING":
# Hi Unreal

View File

@ -44,7 +44,7 @@ allow {{
class {{
name users; # Class name
maxusers 100; # Maximum connections
pingfreq 90; # Check idle connections every N seconds
pingfreq 1000; # Check idle connections every N seconds
maxsendq 100000; # 100KB send buffer limit
}};

View File

@ -16,6 +16,7 @@ RPL_MYINFO = "004"
RPL_ISUPPORT = "005"
RPL_SNOMASKIS = "008"
RPL_BOUNCE = "010"
RPL_HELLO = "020"
RPL_TRACELINK = "200"
RPL_TRACECONNECTING = "201"
RPL_TRACEHANDSHAKE = "202"

View File

@ -2,6 +2,7 @@
correctly. Also checks truncation"""
import socket
import time
import pytest
@ -81,7 +82,7 @@ class BufferingTestCase(cases.BaseServerTestCase):
continue
received_line = self._getLine(2)
print("(repr) S -> 2:", repr(received_line))
print("(repr) S -> 2", repr(received_line))
try:
decoded_line = received_line.decode()
except UnicodeDecodeError:
@ -117,11 +118,13 @@ class BufferingTestCase(cases.BaseServerTestCase):
def _getLine(self, client) -> bytes:
line = b""
while True:
for _ in range(600):
try:
data = self.clients[client].conn.recv(4096)
except socket.timeout:
data = b""
line += data
if not data or data.endswith(b"\r\n"):
if data.endswith(b"\r\n"):
return line
time.sleep(0.1)
return line

View File

@ -897,15 +897,29 @@ class KeyTestCase(cases.BaseServerTestCase):
reply = self.getMessages(2)
self.assertMessageMatch(reply[0], command="JOIN", params=["#chan"])
@cases.mark_specifications("RFC2812")
@cases.mark_specifications("RFC2812", "Modern")
def testKeyValidation(self):
"""
key = 1*23( %x01-05 / %x07-08 / %x0C / %x0E-1F / %x21-7F )
; any 7-bit US_ASCII character,
; except NUL, CR, LF, FF, h/v TABs, and " "
<https://tools.ietf.org/html/rfc2812#page-8>
-- https://tools.ietf.org/html/rfc2812#page-8
"Servers may validate the value (eg. to forbid spaces, as they make it harder
to use the key in `JOIN` messages). If the value is invalid, they SHOULD
return [`ERR_INVALIDMODEPARAM`](#errinvalidmodeparam-696).
However, clients MUST be able to handle any of the following:
* [`ERR_INVALIDMODEPARAM`](#errinvalidmodeparam-696)
* [`ERR_INVALIDKEY`](#errinvalidkey-525)
* `MODE` echoed with a different key (eg. truncated or stripped of invalid
characters)
* the key changed ignored, and no `MODE` echoed if no other mode change
was valid.
"
-- https://modern.ircdocs.horse/#key-channel-mode
-- https://github.com/ircdocs/modern-irc/pull/107
"""
# oragono issue #1021
self.connectClient("bar")
self.joinChannel(1, "#chan")
self.sendLine(1, "MODE #chan +k :passphrase with spaces")
@ -927,6 +941,15 @@ class KeyTestCase(cases.BaseServerTestCase):
# First option: ERR_INVALIDMODEPARAM (eg. Ergo)
return
if not replies:
# MODE was ignored entirely
self.connectClient("foo")
self.sendLine(2, "JOIN #chan")
self.assertMessageMatch(
self.getMessage(2), command="JOIN", params=["#chan"]
)
return
# Second and third options: truncating the key (eg. UnrealIRCd)
# or replacing spaces (eg. Charybdis)
mode_commands = [msg for msg in replies if msg.command == "MODE"]