summaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-09-26 17:46:15 -0300
committerVictor Shyba <victor1984@riseup.net>2017-10-05 05:43:20 -0300
commitb8bdbcda11bccaf2110c441b9d4000d0fe73048a (patch)
treecd51eac55507e02dca858e5d52659916068762b3 /tests/server
parentbbc704834bf15798e4bce3e75e3baaebd38a8765 (diff)
[feature] notify, retry and fail from invalid tag
Notify, log something meaninful and retry at most 3 times before marking the download as unusable (FAILED_DOWNLOAD). -- Related: #8825
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/test_blobs_server.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/tests/server/test_blobs_server.py b/tests/server/test_blobs_server.py
index e3bc761d..892ae5ff 100644
--- a/tests/server/test_blobs_server.py
+++ b/tests/server/test_blobs_server.py
@@ -33,11 +33,21 @@ from leap.soledad.client._db.blobs import BlobManager
from leap.soledad.client._db.blobs import BlobAlreadyExistsError
from leap.soledad.client._db.blobs import InvalidFlagsError
from leap.soledad.client._db.blobs import SoledadError
+from leap.soledad.client._db.blobs import SyncStatus
+from leap.soledad.client._db import blobs as client_blobs
+from leap.soledad.client._crypto import InvalidBlob
+
+
+def sleep(x):
+ d = defer.Deferred()
+ reactor.callLater(x, d.callback, None)
+ return d
class BlobServerTestCase(unittest.TestCase):
def setUp(self):
+ client_blobs.MAX_WAIT = 0.1
root = server_blobs.BlobsResource("filesystem", self.tempdir)
self.site = Site(root)
self.port = reactor.listenTCP(0, self.site, interface='127.0.0.1')
@@ -265,12 +275,8 @@ class BlobServerTestCase(unittest.TestCase):
yield manager.local.put(blob_id, BytesIO("X"), size=1)
yield self.port.stopListening()
- def sleep(x):
- d = defer.Deferred()
- reactor.callLater(x, d.callback, None)
- return d
d = manager.send_missing()
- yield sleep(1)
+ yield sleep(0.1)
self.port = reactor.listenTCP(
self.host.port, self.site, interface='127.0.0.1')
yield d
@@ -302,12 +308,8 @@ class BlobServerTestCase(unittest.TestCase):
yield manager.refresh_sync_status_from_server()
yield self.port.stopListening()
- def sleep(x):
- d = defer.Deferred()
- reactor.callLater(x, d.callback, None)
- return d
d = manager.fetch_missing()
- yield sleep(1)
+ yield sleep(0.1)
self.port = reactor.listenTCP(
self.host.port, self.site, interface='127.0.0.1')
yield d
@@ -317,6 +319,28 @@ class BlobServerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
+ def test_download_corrupted_tag_marks_blob_as_failed(self):
+ user_id = uuid4().hex
+ manager = BlobManager(self.tempdir, self.uri, self.secret,
+ self.secret, user_id)
+ self.addCleanup(manager.close)
+ blob_id = 'corrupted'
+ yield manager._encrypt_and_upload(blob_id, BytesIO("corrupted"))
+ parts = ['default'] + [blob_id[0], blob_id[0:3], blob_id[0:6]]
+ parts += [blob_id]
+ corrupted_blob_path = os.path.join(self.tempdir, user_id, *parts)
+ with open(corrupted_blob_path, 'r+b') as corrupted_blob:
+ # Corrupt the tag (last 16 bytes)
+ corrupted_blob.seek(-16, 2)
+ corrupted_blob.write('x' * 16)
+ with pytest.raises(InvalidBlob):
+ yield manager.sync()
+ status, retries = yield manager.local.get_sync_status(blob_id)
+ self.assertEquals(status, SyncStatus.FAILED_DOWNLOAD)
+ self.assertEquals(retries, 3)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
def test_upload_then_delete_updates_list(self):
manager = BlobManager('', self.uri, self.secret,
self.secret, uuid4().hex)