diff options
author | drebs <drebs@leap.se> | 2017-02-02 11:45:57 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-02-09 17:41:55 +0100 |
commit | a2f041de7f1ea653f078ac9cd532e2d2b774248f (patch) | |
tree | b32aefb6fd5cbfce0c6f4c03f1a26d9cf7f9f8e9 | |
parent | 53b5a6788ad8416f78b24cc9880d02da73c52d70 (diff) |
[refactor] parametrize blobs toggling in soledad server resource
-rw-r--r-- | server/src/leap/soledad/server/_resource.py | 17 | ||||
-rw-r--r-- | server/src/leap/soledad/server/auth.py | 10 | ||||
-rw-r--r-- | testing/tests/server/test__resource.py | 16 | ||||
-rw-r--r-- | testing/tests/server/test_auth.py | 3 |
4 files changed, 30 insertions, 16 deletions
diff --git a/server/src/leap/soledad/server/_resource.py b/server/src/leap/soledad/server/_resource.py index fec290a2..156e18aa 100644 --- a/server/src/leap/soledad/server/_resource.py +++ b/server/src/leap/soledad/server/_resource.py @@ -33,17 +33,24 @@ class SoledadResource(Resource): for the Soledad Server. """ - def __init__(self, conf, sync_pool=None): - Resource.__init__(self) + def __init__(self, enable_blobs=False, sync_pool=None): + """ + Initialize the Soledad resource. + + :param enable_blobs: Whether the blobs feature should be enabled. + :type enable_blobs: bool - blobs_enabled = conf['soledad-server']['blobs'] + :param sync_pool: A pool to pass to the WSGI sync resource. + :type sync_pool: twisted.python.threadpool.ThreadPool + """ + Resource.__init__(self) # requests to / return server information - server_info = ServerInfo(blobs_enabled) + server_info = ServerInfo(enable_blobs) self.putChild('', server_info) # requests to /blobs will serve blobs if enabled - if blobs_enabled: + if enable_blobs: self.putChild('blobs', blobs_resource) # other requests are routed to legacy sync resource diff --git a/server/src/leap/soledad/server/auth.py b/server/src/leap/soledad/server/auth.py index d7ccdeb9..0ec890ca 100644 --- a/server/src/leap/soledad/server/auth.py +++ b/server/src/leap/soledad/server/auth.py @@ -42,12 +42,18 @@ from ._config import get_config @implementer(IRealm) class SoledadRealm(object): - def __init__(self, sync_pool=None): + def __init__(self, conf=None, sync_pool=None): + if not conf: + conf = get_config() + self._conf = conf self._sync_pool = sync_pool def requestAvatar(self, avatarId, mind, *interfaces): if IResource in interfaces: - resource = SoledadResource(sync_pool=self._sync_pool) + enable_blobs = self._conf['soledad-server']['blobs'] + resource = SoledadResource( + enable_blobs=enable_blobs, + sync_pool=self._sync_pool) return (IResource, resource, lambda: None) raise NotImplementedError() diff --git a/testing/tests/server/test__resource.py b/testing/tests/server/test__resource.py index 30ef782d..c066435e 100644 --- a/testing/tests/server/test__resource.py +++ b/testing/tests/server/test__resource.py @@ -35,22 +35,22 @@ _pool = reactor.getThreadPool() class SoledadResourceTestCase(unittest.TestCase): def test_get_root(self): - conf = {'soledad-server': {'blobs': None}} # doesn't matter - resource = SoledadResource(conf, sync_pool=_pool) + enable_blobs = None # doesn't matter + resource = SoledadResource(enable_blobs=enable_blobs, sync_pool=_pool) request = DummyRequest(['']) child = getChildForRequest(resource, request) self.assertIsInstance(child, ServerInfo) def test_get_blobs_enabled(self): - conf = {'soledad-server': {'blobs': True}} - resource = SoledadResource(conf, sync_pool=_pool) + enable_blobs = True + resource = SoledadResource(enable_blobs=enable_blobs, sync_pool=_pool) request = DummyRequest(['blobs']) child = getChildForRequest(resource, request) self.assertIsInstance(child, BlobsResource) def test_get_blobs_disabled(self): - conf = {'soledad-server': {'blobs': False}} - resource = SoledadResource(conf, sync_pool=_pool) + enable_blobs = False + resource = SoledadResource(enable_blobs=enable_blobs, sync_pool=_pool) request = DummyRequest(['blobs']) child = getChildForRequest(resource, request) # if blobs is disabled, the request should be routed to sync @@ -58,8 +58,8 @@ class SoledadResourceTestCase(unittest.TestCase): self.assertIsInstance(child._application, GzipMiddleware) def test_get_sync(self): - conf = {'soledad-server': {'blobs': None}} # doesn't matter - resource = SoledadResource(conf, sync_pool=_pool) + enable_blobs = None # doesn't matter + resource = SoledadResource(enable_blobs=enable_blobs, sync_pool=_pool) request = DummyRequest(['user-db', 'sync-from', 'source-id']) child = getChildForRequest(resource, request) self.assertIsInstance(child, WSGIResource) diff --git a/testing/tests/server/test_auth.py b/testing/tests/server/test_auth.py index f7fe0f25..00d416d5 100644 --- a/testing/tests/server/test_auth.py +++ b/testing/tests/server/test_auth.py @@ -39,8 +39,9 @@ class SoledadRealmTestCase(unittest.TestCase): def test_returned_resource(self): # we have to pass a pool to the realm , otherwise tests will hang + conf = {'soledad-server': {'blobs': False}} pool = reactor.getThreadPool() - realm = SoledadRealm(sync_pool=pool) + realm = SoledadRealm(conf=conf, sync_pool=pool) iface, avatar, logout = realm.requestAvatar('any', None, IResource) self.assertIsInstance(avatar, SoledadResource) self.assertIsNone(logout()) |