summaryrefslogtreecommitdiff
path: root/mail
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-12-15 02:04:07 -0400
committerKali Kaneko <kali@leap.se>2015-12-15 02:30:30 -0400
commit2ab4fee80de10d89c4ff2b3db8e871c81c0ab8a1 (patch)
tree7d87610166c5e6e330bbd52d8ab58b90d164cb87 /mail
parentda4317a4df7184cf581c95b43460456d3225205f (diff)
[fix] dummy credentials for tests
imap tests must be adapted, using a dummy credential checker.
Diffstat (limited to 'mail')
-rw-r--r--mail/src/leap/mail/imap/tests/test_imap.py4
-rw-r--r--mail/src/leap/mail/imap/tests/utils.py59
2 files changed, 60 insertions, 3 deletions
diff --git a/mail/src/leap/mail/imap/tests/test_imap.py b/mail/src/leap/mail/imap/tests/test_imap.py
index 62c3c419..ccce285e 100644
--- a/mail/src/leap/mail/imap/tests/test_imap.py
+++ b/mail/src/leap/mail/imap/tests/test_imap.py
@@ -575,8 +575,8 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
"""
Test login requiring quoting
"""
- self.server._userid = '{test}user@leap.se'
- self.server._password = '{test}password'
+ self.server.checker.userid = '{test}user@leap.se'
+ self.server.checker.password = '{test}password'
def login():
d = self.client.login('{test}user@leap.se', '{test}password')
diff --git a/mail/src/leap/mail/imap/tests/utils.py b/mail/src/leap/mail/imap/tests/utils.py
index b1f85630..ad89e92b 100644
--- a/mail/src/leap/mail/imap/tests/utils.py
+++ b/mail/src/leap/mail/imap/tests/utils.py
@@ -20,10 +20,15 @@ Common utilities for testing Soledad IMAP Server.
from email import parser
from mock import Mock
+from twisted.cred.checkers import ICredentialsChecker
+from twisted.cred.credentials import IUsernamePassword
+from twisted.cred.error import UnauthorizedLogin
+from twisted.cred.portal import Portal, IRealm
from twisted.mail import imap4
from twisted.internet import defer
from twisted.protocols import loopback
from twisted.python import log
+from zope.interface import implementer
from leap.mail.adaptors import soledad as soledad_adaptor
from leap.mail.imap.account import IMAPAccount
@@ -64,6 +69,57 @@ class SimpleClient(imap4.IMAP4Client):
self.events.append(['newMessages', exists, recent])
self.transport.loseConnection()
+#
+# Dummy credentials for tests
+#
+
+
+@implementer(IRealm)
+class TestRealm(object):
+
+ def __init__(self, account):
+ self._account = account
+
+ def requestAvatar(self, avatarId, mind, *interfaces):
+ avatar = self._account
+ return (imap4.IAccount, avatar,
+ getattr(avatar, 'logout', lambda: None))
+
+
+@implementer(ICredentialsChecker)
+class TestCredentialsChecker(object):
+
+ credentialInterfaces = (IUsernamePassword,)
+
+ userid = TEST_USER
+ password = TEST_PASSWD
+
+ def requestAvatarId(self, credentials):
+ username, password = credentials.username, credentials.password
+ d = self.checkTestCredentials(username, password)
+ d.addErrback(lambda f: defer.fail(UnauthorizedLogin()))
+ return d
+
+ def checkTestCredentials(self, username, password):
+ if username == self.userid and password == self.password:
+ return defer.succeed(username)
+ else:
+ return defer.fail(Exception("Wrong credentials"))
+
+
+class TestSoledadIMAPServer(LEAPIMAPServer):
+
+ def __init__(self, account, *args, **kw):
+
+ LEAPIMAPServer.__init__(self, *args, **kw)
+
+ realm = TestRealm(account)
+ portal = Portal(realm)
+ checker = TestCredentialsChecker()
+ self.checker = checker
+ self.portal = portal
+ portal.registerChecker(checker)
+
class IMAP4HelperMixin(SoledadTestMixin):
"""
@@ -80,7 +136,8 @@ class IMAP4HelperMixin(SoledadTestMixin):
USERID = TEST_USER
def setup_server(account):
- self.server = LEAPIMAPServer(
+ self.server = TestSoledadIMAPServer(
+ account=account,
contextFactory=self.serverCTX)
self.server.theAccount = account