Add tests from section 3.1 of RFC 2812.

This commit is contained in:
Valentin Lorentz
2015-12-20 23:59:35 +01:00
parent 027a8b968f
commit 2a44f9a7ad
2 changed files with 71 additions and 2 deletions

View File

@ -28,7 +28,8 @@ class _IrcTestCase(unittest.TestCase):
fetches messages until the predicate returns a False on a message,
and returns this message."""
while True:
msg = message_parser.parse_message(self.getLine(*args))
line = self.getLine(*args)
msg = message_parser.parse_message(line)
if not filter_pred or filter_pred(msg):
return msg
def assertMessageEqual(self, msg, subcommand=None, subparams=None,
@ -216,7 +217,10 @@ class BaseServerTestCase(_IrcTestCase):
conn.setblocking(False)
while True:
time.sleep(0.1) # TODO: do better than this (use ping?)
data += conn.recv(4096)
new_data = conn.recv(4096) # May raise BlockingIOError
if not new_data:
raise BlockingIOError
data += new_data
except BlockingIOError:
for line in data.decode().split('\r\n'):
if line and self.show_io:
@ -258,6 +262,22 @@ class BaseServerTestCase(_IrcTestCase):
caps = capabilities.cap_list_to_dict(caps)
return caps
def assertDisconnected(self, client):
try:
self.getLines(client)
self.sendLine(client, 'PING foo')
while True:
l = self.getLine(client)
self.assertNotEqual(line, '')
m = message_parser.parse_message(l)
self.assertNotEqual(m.command, 'PONG',
'Client not disconnected.')
except socket.error:
del self.clients[client]
return
else:
raise AssertionError('Client not disconnected.')
class OptionalityHelper:
def checkMechanismSupport(self, mechanism):
if mechanism in self.controller.supported_sasl_mechanisms:

View File

@ -0,0 +1,49 @@
"""
Tests section 4.1 of RFC 1459.
<https://tools.ietf.org/html/rfc1459#section-4.1>
"""
from irctest import cases
from irctest import authentication
from irctest.irc_utils.message_parser import Message
class ConnectionRegistrationTestCase(cases.BaseServerTestCase):
def connectClient(self, nick, name=None):
name = self.addClient(name)
self.sendLine(1, 'NICK {}'.format(nick))
self.sendLine(1, 'USER username * * :Realname')
# Skip to the point where we are registered
# https://tools.ietf.org/html/rfc2812#section-3.1
while True:
m = self.getMessage(1)
if m.command == '001':
break
self.sendLine(1, 'PING foo')
# Skip all that happy welcoming stuff
while True:
m = self.getMessage(1)
if m.command == 'PONG':
break
def testPassBeforeNickuser(self):
"""“Currently this requires that user send a PASS command before
sending the NICK/USER combination.”
<https://tools.ietf.org/html/rfc2812#section-3.1.1>"""
self.connectClient('foo')
self.getMessages(1)
self.sendLine(1, 'PASS :foo')
m = self.getMessage(1)
self.assertMessageEqual(m, command='462') # ERR_ALREADYREGISTRED
def testQuitDisconnects(self):
"""“The server must close the connection to a client which sends a
QUIT message.” <https://tools.ietf.org/html/rfc1459#section-4.1.3>
"""
self.connectClient('foo')
self.getMessages(1)
self.sendLine(1, 'QUIT')
m = self.getMessage(1)
self.assertMessageEqual(m, command='ERROR')
self.assertDisconnected(1)