summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-02-09 22:27:22 -0200
committerdrebs <drebs@leap.se>2013-02-09 22:27:22 -0200
commitc6c0e0aadfe248fb8d907d12fce063dad359a140 (patch)
tree0ba050997da935fc833fbf6041a64ecf8db26b69
parentac99a63c702fcca5b102a2e4e04416871c83347c (diff)
parente6f5027e42c8dbcde2a42cd48b9f7a54731fc10d (diff)
Merge branch 'develop' into feature/soledad-api
-rw-r--r--backends/leap_backend.py16
-rw-r--r--tests/test_couch.py6
2 files changed, 17 insertions, 5 deletions
diff --git a/backends/leap_backend.py b/backends/leap_backend.py
index c0a22feb..c3c52ee6 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):
"""
Encryptable and syncable document.
@@ -164,9 +168,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])
diff --git a/tests/test_couch.py b/tests/test_couch.py
index 09c7269e..3482b035 100644
--- a/tests/test_couch.py
+++ b/tests/test_couch.py
@@ -115,7 +115,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-'))
@@ -130,13 +130,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)