summaryrefslogtreecommitdiff
path: root/service/test/support
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@riseup.net>2016-09-08 19:07:31 -0300
committerTulio Casagrande <tcasagra@thoughtworks.com>2016-09-12 14:39:33 -0300
commit8e7b7d53a6bef24ced29549746699f26595f4c71 (patch)
tree8a1fa8f0d5e3784a7795b97500616ed0954cc780 /service/test/support
parent1114cfcfba7b67b9d3e6238ce9dc2ab578060f93 (diff)
multi_user_client now accounts for the login process
The login resource was being totally mocked out of the integration tests, I adapted the test client to touch the actual login code and fixed the multi_user_client to use the same checker the single user one was using. With that change we now have tests that cover the change of authenticating with bonafide
Diffstat (limited to 'service/test/support')
-rw-r--r--service/test/support/integration/app_test_client.py9
-rw-r--r--service/test/support/integration/multi_user_client.py26
2 files changed, 15 insertions, 20 deletions
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 5d1e760a..619062a8 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -31,7 +31,6 @@ from mock import Mock
from twisted.internet import reactor, defer
from twisted.internet.defer import succeed
from twisted.web.resource import getChildForRequest
-# from twisted.web.server import Site as PixelatedSite
from zope.interface import implementer
from twisted.cred import checkers, credentials
from pixelated.adapter.mailstore.leap_attachment_store import LeapAttachmentStore
@@ -136,8 +135,11 @@ class StubSRPChecker(object):
self._credentials[username] = password
def requestAvatarId(self, credentials):
- leap_auth = SRPSession(credentials.username, uuid.uuid4(), uuid.uuid4(), uuid.uuid4(), {})
- return defer.succeed(LeapSession(self._leap_provider, leap_auth, None, None, None, None))
+ if(self._credentials[credentials.username] == credentials.password):
+ leap_auth = SRPSession(credentials.username, uuid.uuid4(), uuid.uuid4(), uuid.uuid4(), {})
+ return defer.succeed(LeapSession(self._leap_provider, leap_auth, None, None, None, None))
+ else:
+ return defer.fail()
class StubServicesFactory(ServicesFactory):
@@ -196,7 +198,6 @@ class AppTestClient(object):
else:
self.service_factory = StubServicesFactory(self.accounts, mode)
provider = mock()
-
self.resource = set_up_protected_resources(RootResource(self.service_factory), provider, self.service_factory, checker=StubSRPChecker(provider))
@defer.inlineCallbacks
diff --git a/service/test/support/integration/multi_user_client.py b/service/test/support/integration/multi_user_client.py
index 4b2cb832..75168128 100644
--- a/service/test/support/integration/multi_user_client.py
+++ b/service/test/support/integration/multi_user_client.py
@@ -17,7 +17,7 @@ from leap.exceptions import SRPAuthenticationError
from mockito import mock, when, any as ANY
from twisted.internet import defer
-from leap.auth import SRPAuth
+from leap.auth import SRPSession
from pixelated.application import UserAgentMode, set_up_protected_resources
from pixelated.config.services import ServicesFactory
@@ -26,7 +26,7 @@ from pixelated.config.sessions import LeapSessionFactory, LeapSession
import pixelated.config.services
from pixelated.resources.root_resource import RootResource
from test.support.integration import AppTestClient
-from test.support.integration.app_test_client import AppTestAccount
+from test.support.integration.app_test_client import AppTestAccount, StubSRPChecker
import test.support.mockito
from test.support.test_helper import request_mock
@@ -47,36 +47,30 @@ class MultiUserClient(AppTestClient):
root_resource = RootResource(self.service_factory)
leap_provider = mock()
- self.resource = set_up_protected_resources(root_resource, leap_provider, self.service_factory)
+ self.credentials_checker = StubSRPChecker(leap_provider)
+ self.resource = set_up_protected_resources(root_resource, leap_provider, self.service_factory, checker=self.credentials_checker)
def login(self, username='username', password='password'):
+ if(username == 'username' and password == 'password'):
+ self.credentials_checker.add_user(username, password)
+ session = SRPSession(username, 'some_user_token', 'some_user_uuid', 'session_id', {'is_admin': False})
leap_session = self._test_account.leap_session
- user_auth = mock()
- user_auth.uuid = 'some_user_uuid'
- leap_session.user_auth = user_auth
+ leap_session.user_auth = session
config = mock()
config.leap_home = 'some_folder'
leap_session.config = config
leap_session.fresh_account = False
self.leap_session = leap_session
self.services = self._test_account.services
- self.user_auth = user_auth
+ self.user_auth = session
- self._set_leap_srp_auth(username, password, user_auth)
- when(LeapSessionFactory).create(username, password, user_auth).thenReturn(leap_session)
+ when(LeapSessionFactory).create(username, password, session).thenReturn(leap_session)
when(leap_session).initial_sync().thenAnswer(lambda: defer.succeed(None))
when(pixelated.config.services).Services(ANY()).thenReturn(self.services)
request = request_mock(path='/login', method="POST", body={'username': username, 'password': password})
return self._render(request, as_json=False)
- def _set_leap_srp_auth(self, username, password, mock_srp_auth):
- auth_dict = {'username': 'password'}
- if auth_dict[username] == password:
- when(SRPAuth).authenticate(username, password).thenReturn(mock_srp_auth)
- else:
- when(SRPAuth).authenticate(username, password).thenRaise(SRPAuthenticationError())
-
def get(self, path, get_args='', as_json=True, from_request=None):
request = request_mock(path)
request.args = get_args