From 3101a2edd3ade3945965829b4e7e1eb624133aec Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 28 Jan 2013 11:48:32 -0200 Subject: LeapSyncTarget checks whether document has been correctly encrypted. --- backends/leap_backend.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backends/leap_backend.py b/backends/leap_backend.py index ec26dca4..f73698f2 100644 --- a/backends/leap_backend.py +++ b/backends/leap_backend.py @@ -20,6 +20,10 @@ class NoSoledadInstance(Exception): pass +class DocumentEncryptionFailed(Exception): + pass + + class LeapDocument(Document): """ LEAP Documents are standard u1db documents with cabability of returning an @@ -181,9 +185,17 @@ class LeapSyncTarget(HTTPSyncTarget): comma = ',' for doc, gen, trans_id in docs_by_generations: if doc.syncable: - # encrypt before sending to server. + # encrypt and verify before sending to server. + doc_content = doc.get_encrypted_json() + if doc_content == doc.get_json(): + raise DocumentEncryptionFailed + enc_doc = LeapDocument(doc.doc_id, doc.rev, + encrypted_json=doc_content, + soledad=self._soledad) + if doc.get_json() != enc_doc.get_json(): + raise DocumentEncryptionFailed size += prepare(id=doc.doc_id, rev=doc.rev, - content=doc.get_encrypted_json(), + content=doc_content, gen=gen, trans_id=trans_id) entries.append('\r\n]') size += len(entries[-1]) -- cgit v1.2.3 From e6f5027e42c8dbcde2a42cd48b9f7a54731fc10d Mon Sep 17 00:00:00 2001 From: antialias Date: Wed, 30 Jan 2013 13:26:18 -0500 Subject: pep8. --- tests/test_couch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_couch.py b/tests/test_couch.py index b5d6378c..02399e4c 100644 --- a/tests/test_couch.py +++ b/tests/test_couch.py @@ -110,7 +110,7 @@ class CouchDBTestCase(unittest.TestCase): class TestCouchBackendImpl(CouchDBTestCase): def test__allocate_doc_id(self): - db = couch.CouchDatabase('http://localhost:'+str(self.wrapper.port), + db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port), 'u1db_tests') doc_id1 = db._allocate_doc_id() self.assertTrue(doc_id1.startswith('D-')) @@ -125,13 +125,13 @@ class TestCouchBackendImpl(CouchDBTestCase): def make_couch_database_for_test(test, replica_uid): port = str(test.wrapper.port) - return couch.CouchDatabase('http://localhost:'+port, replica_uid, + return couch.CouchDatabase('http://localhost:' + port, replica_uid, replica_uid=replica_uid or 'test') def copy_couch_database_for_test(test, db): port = str(test.wrapper.port) - new_db = couch.CouchDatabase('http://localhost:'+port, + new_db = couch.CouchDatabase('http://localhost:' + port, db._replica_uid + '_copy', replica_uid=db._replica_uid or 'test') gen, docs = db.get_all_docs(include_deleted=True) -- cgit v1.2.3