Add missing files.

This commit is contained in:
Valentin Lorentz
2015-12-19 18:08:34 +01:00
parent 9868f6a1d4
commit 3c6be69538
2 changed files with 62 additions and 0 deletions

13
irctest/authentication.py Normal file
View File

@ -0,0 +1,13 @@
import enum
import collections
@enum.unique
class Mechanisms(enum.Enum):
@classmethod
def as_string(cls, mech):
return {cls.plain: 'PLAIN'}[mech]
plain = 1
Authentication = collections.namedtuple('Authentication',
'mechanisms username password certificate')
Authentication.__new__.__defaults__ = ([Mechanisms.plain], None, None, None)

View File

@ -0,0 +1,49 @@
import base64
from irctest import cases
from irctest import authentication
from irctest.irc_utils.message_parser import Message
class CapTestCase(cases.BaseClientTestCase, cases.ClientNegociationHelper):
def testPlain(self):
auth = authentication.Authentication(
mechanisms=[authentication.Mechanisms.plain],
username='jilles',
password='sesame',
)
m = self.negotiateCapabilities(['sasl'], auth=auth)
self.assertEqual(m.command, 'AUTHENTICATE', m)
self.sendLine('AUTHENTICATE +')
m = self.getMessage()
self.assertEqual(m, Message([], None, 'AUTHENTICATE',
['amlsbGVzAGppbGxlcwBzZXNhbWU=']))
self.sendLine('900 * * jilles :You are now logged in.')
self.sendLine('903 * :SASL authentication successful')
m = self.negotiateCapabilities(['sasl'], False)
self.assertEqual(m, Message([], None, 'CAP', ['END']))
def testPlainLarge(self):
# TODO: authzid is optional
auth = authentication.Authentication(
mechanisms=[authentication.Mechanisms.plain],
username='foo',
password='bar'*200,
)
authstring = base64.b64encode(b'\x00'.join(
[b'foo', b'foo', b'bar'*200])).decode()
m = self.negotiateCapabilities(['sasl'], auth=auth)
self.assertEqual(m.command, 'AUTHENTICATE', m)
self.sendLine('AUTHENTICATE +')
m = self.getMessage()
print(authstring[0:400])
self.assertEqual(m, Message([], None, 'AUTHENTICATE',
[authstring[0:400]]), m)
m = self.getMessage()
self.assertEqual(m, Message([], None, 'AUTHENTICATE',
[authstring[400:800]]))
m = self.getMessage()
self.assertEqual(m, Message([], None, 'AUTHENTICATE',
[authstring[800:]]))
self.sendLine('900 * * {} :You are now logged in.'.format('foo'*100))
self.sendLine('903 * :SASL authentication successful')
m = self.negotiateCapabilities(['sasl'], False)
self.assertEqual(m, Message([], None, 'CAP', ['END']))