From 613a81facc799fd5f76c6057c168bfb41f7bf790 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 15 Mar 2017 20:59:37 -0300 Subject: [test] BlobManager encrypt test --- client/src/leap/soledad/client/_blobs.py | 3 ++- testing/tests/blobs/test_blobs.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py index e0326378..34ce8f4a 100644 --- a/client/src/leap/soledad/client/_blobs.py +++ b/client/src/leap/soledad/client/_blobs.py @@ -151,7 +151,8 @@ class BlobManager(object): """ def __init__(self, local_path, remote, key, secret, user): - self.local = SQLiteBlobBackend(local_path, key) + if local_path: + self.local = SQLiteBlobBackend(local_path, key) self.remote = remote self.secret = secret self.user = user diff --git a/testing/tests/blobs/test_blobs.py b/testing/tests/blobs/test_blobs.py index 5e763026..b78f6c0f 100644 --- a/testing/tests/blobs/test_blobs.py +++ b/testing/tests/blobs/test_blobs.py @@ -19,6 +19,7 @@ Tests for cryptographic related stuff. """ from twisted.trial import unittest from twisted.internet import defer +from leap.soledad.client import _blobs from leap.soledad.client._blobs import DecrypterBuffer from leap.soledad.client import _crypto from io import BytesIO @@ -47,3 +48,20 @@ class BlobTestCase(unittest.TestCase): buf.write(encrypted) fd, size = buf.close() assert fd.getvalue() == 'rosa de foc' + + def test_blob_manager_encrypted_upload(self): + + @defer.inlineCallbacks + def _check_result(uri, data): + decryptor = _crypto.BlobDecryptor( + self.doc_info, data, + armor=False, + secret=self.secret) + decrypted = yield decryptor.decrypt() + assert decrypted.getvalue() == 'up and up' + + manager = _blobs.BlobManager('', '', self.secret, self.secret, 'user') + doc_id, rev = self.doc_info.doc_id, self.doc_info.rev + fd = BytesIO('up and up') + _blobs.treq.put = _check_result + return manager._encrypt_and_upload('blob_id', doc_id, rev, fd) -- cgit v1.2.3