From c7baad4f07ec8a44bd12113775c40974be3a4fb9 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 2 Oct 2015 17:44:11 -0300 Subject: [bug] Migrate back to python-couchdb 0.8 Wheezy is still at 0.8 and it is yet supported. This commit changes all necessary calls from python-couchdb 1.0 back to python-couchdb 0.8. We can migrate this back to simpler implementation with python-couchdb 1.0 when support for wheezy is dropped. --- common/src/leap/soledad/common/couch.py | 20 ++++++++++++++++---- common/src/leap/soledad/common/tests/test_couch.py | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'common/src/leap') diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py index 4c5f6400..10a1b277 100644 --- a/common/src/leap/soledad/common/couch.py +++ b/common/src/leap/soledad/common/couch.py @@ -461,7 +461,8 @@ class CouchDatabase(CommonBackend): """ for ddoc_name in ['docs', 'syncs', 'transactions']: try: - self._database.info(ddoc_name) + self._database.resource('_design', + ddoc_name, '_info').get_json() except ResourceNotFound: ddoc = json.loads( binascii.a2b_base64( @@ -478,10 +479,10 @@ class CouchDatabase(CommonBackend): This is achieved by creating a _security design document, see: http://docs.couchdb.org/en/latest/api/database/security.html """ - security = self._database.security + security = self._database.resource.get_json('_security')[2] security['members'] = {'names': ['soledad'], 'roles': []} security['admins'] = {'names': [], 'roles': []} - self._database.security = security + self._database.resource.put_json('_security', body=security) def get_sync_target(self): """ @@ -888,7 +889,7 @@ class CouchDatabase(CommonBackend): try: resource = self._new_resource() resource.put_json( - doc.doc_id, body=buf.getvalue(), headers=envelope.headers) + doc.doc_id, body=str(buf.getvalue()), headers=envelope.headers) except ResourceConflict: raise RevisionConflict() if self.replica_uid + '_gen' in self.cache: @@ -1337,6 +1338,17 @@ class CouchDatabase(CommonBackend): in matching doc_ids order. :rtype: iterable """ + # Workaround for: + # + # http://bugs.python.org/issue7980 + # https://leap.se/code/issues/5449 + # + # python-couchdb uses time.strptime, which is not thread safe. In + # order to avoid the problem described on the issues above, we preload + # strptime here by evaluating the conversion of an arbitrary date. + # This will not be needed when/if we switch from python-couchdb to + # paisley. + time.strptime('Mar 8 1917', '%b %d %Y') get_one = lambda doc_id: self._get_doc(doc_id, check_for_conflicts) docs = [THREAD_POOL.apply_async(get_one, [doc_id]) for doc_id in doc_ids] diff --git a/common/src/leap/soledad/common/tests/test_couch.py b/common/src/leap/soledad/common/tests/test_couch.py index d1a07a3a..b4797f5e 100644 --- a/common/src/leap/soledad/common/tests/test_couch.py +++ b/common/src/leap/soledad/common/tests/test_couch.py @@ -1507,9 +1507,9 @@ class CouchDatabaseExceptionsTests(CouchDBTestCase): will have the lowest privileged access to an user db. """ self.create_db(ensure=False) - self.assertFalse(self.db._database.security) + self.assertFalse(self.db._database.resource.get_json('_security')[2]) self.db.ensure_security_ddoc() - security_ddoc = self.db._database.security + security_ddoc = self.db._database.resource.get_json('_security')[2] self.assertIn('admins', security_ddoc) self.assertFalse(security_ddoc['admins']['names']) self.assertIn('members', security_ddoc) -- cgit v1.2.3 From dccaf79789b5f52848cfedd82ca4a2999de1432c Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 5 Oct 2015 12:19:12 -0300 Subject: [bug] fix leap mx by default false on ensure_ddocs ensure_ddocs is a privileged operation. The code was defaulting to True, which caused unprivileged code to fail. This commit changes it to False, forcing you to check your privileges and declare a new argument when calling in order to ensure that this behavior is only supposed to happen on privileged parts. --- common/src/leap/soledad/common/couch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/src/leap') diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py index 10a1b277..3dee1473 100644 --- a/common/src/leap/soledad/common/couch.py +++ b/common/src/leap/soledad/common/couch.py @@ -404,7 +404,7 @@ class CouchDatabase(CommonBackend): return cls( url, dbname, replica_uid=replica_uid, ensure_ddocs=ensure_ddocs) - def __init__(self, url, dbname, replica_uid=None, ensure_ddocs=True): + def __init__(self, url, dbname, replica_uid=None, ensure_ddocs=False): """ Create a new Couch data container. -- cgit v1.2.3