summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-07-24 18:11:14 -0300
committerVictor Shyba <victor1984@riseup.net>2017-08-03 05:33:01 -0300
commit841db9f072401f2b6f40873b35c733723a54de36 (patch)
treedb64800de5858aca58f42547e4086a79274e7dfd
parent8fc244cb0946f46ba9aff019b70568d08a226b29 (diff)
[bug] make download namespace-aware
-rw-r--r--src/leap/soledad/client/_db/blobs.py9
-rw-r--r--src/leap/soledad/server/_blobs.py4
-rw-r--r--testing/tests/blobs/test_blob_manager.py3
-rw-r--r--testing/tests/server/test_blobs_server.py11
4 files changed, 20 insertions, 7 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py
index 148e1ff1..e95f9d9e 100644
--- a/src/leap/soledad/client/_db/blobs.py
+++ b/src/leap/soledad/client/_db/blobs.py
@@ -302,13 +302,13 @@ class BlobManager(object):
defer.returnValue((yield response.json()))
@defer.inlineCallbacks
- def get(self, blob_id):
+ def get(self, blob_id, namespace=None):
local_blob = yield self.local.get(blob_id)
if local_blob:
logger.info("Found blob in local database: %s" % blob_id)
defer.returnValue(local_blob)
- result = yield self._download_and_decrypt(blob_id)
+ result = yield self._download_and_decrypt(blob_id, namespace)
if not result:
defer.returnValue(None)
@@ -347,11 +347,12 @@ class BlobManager(object):
logger.info("Finished upload: %s" % (blob_id,))
@defer.inlineCallbacks
- def _download_and_decrypt(self, blob_id):
+ def _download_and_decrypt(self, blob_id, namespace=None):
logger.info("Staring download of blob: %s" % blob_id)
# TODO this needs to be connected in a tube
uri = urljoin(self.remote, self.user + '/' + blob_id)
- data = yield self._client.get(uri)
+ params = {'namespace': namespace} if namespace else None
+ data = yield self._client.get(uri, params=params)
if data.code == 404:
logger.warn("Blob not found in server: %s" % blob_id)
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 6afd802c..b6323906 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -68,7 +68,7 @@ class FilesystemBlobsBackend(object):
self.path = blobs_path
def read_blob(self, user, blob_id, request, namespace=''):
- logger.info('reading blob: %s - %s' % (user, blob_id))
+ logger.info('reading blob: %s - %s@%s' % (user, blob_id, namespace))
path = self._get_path(user, blob_id, namespace)
logger.debug('blob path: %s' % path)
_file = static.File(path, defaultType='application/octet-stream')
@@ -249,7 +249,7 @@ class BlobsResource(resource.Resource):
filter_flag=filter_flag)
if 'only_flags' in request.args:
return self._handler.get_flags(user, blob_id, request, namespace)
- self._handler.add_tag_header(user, blob_id, request)
+ self._handler.add_tag_header(user, blob_id, request, namespace)
return self._handler.read_blob(user, blob_id, request, namespace)
def render_DELETE(self, request):
diff --git a/testing/tests/blobs/test_blob_manager.py b/testing/tests/blobs/test_blob_manager.py
index 5b96cae0..56bea87a 100644
--- a/testing/tests/blobs/test_blob_manager.py
+++ b/testing/tests/blobs/test_blob_manager.py
@@ -50,7 +50,8 @@ class BlobManagerTestCase(unittest.TestCase):
bad_blob_id = 'inexsistent_id'
result = yield self.manager.get(bad_blob_id)
self.assertIsNone(result)
- self.manager._download_and_decrypt.assert_called_once_with(bad_blob_id)
+ args = bad_blob_id, None
+ self.manager._download_and_decrypt.assert_called_once_with(*args)
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
diff --git a/testing/tests/server/test_blobs_server.py b/testing/tests/server/test_blobs_server.py
index 152215d1..cf370147 100644
--- a/testing/tests/server/test_blobs_server.py
+++ b/testing/tests/server/test_blobs_server.py
@@ -192,6 +192,17 @@ class BlobServerTestCase(unittest.TestCase):
blobs_list = yield manager.remote_list(namespace=namespace)
self.assertEquals(['blob_id1'], blobs_list)
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_download_from_namespace(self):
+ manager = BlobManager('', self.uri, self.secret,
+ self.secret, 'user')
+ namespace, blob_id, content = 'incoming', 'blob_id1', 'test'
+ yield manager._encrypt_and_upload(blob_id, BytesIO(content),
+ namespace=namespace)
+ got_blob = yield manager._download_and_decrypt(blob_id, namespace)
+ self.assertEquals(content, got_blob[0].getvalue())
+
def __touch(self, *args):
path = os.path.join(*args)
with open(path, 'a'):