From 8384b006f575ac0b769f9f6e9ce6b2c623ec9fa1 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 11 Sep 2015 11:45:17 +0200 Subject: [test] add test infrastructure Some refactor on the couchdb usage was needed to be able to mock couchdb. - Resolves: #7435 --- src/leap/mx/couchdbhelper.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/leap/mx/couchdbhelper.py') diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index 1752b4e..b26a0d8 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -23,7 +23,9 @@ maps, user UUIDs, and GPG keyIDs. from paisley import client +from twisted.internet import defer from twisted.python import log +from leap.soledad.common.couch import CouchDatabase class ConnectedCouchDB(client.CouchDB): @@ -50,6 +52,10 @@ class ConnectedCouchDB(client.CouchDB): :param str password: (optional) The password for authorization. :type password: str """ + self.mail_couch_url = "http://%s:%s@%s:%s" % (username, + password, + host, + port) client.CouchDB.__init__(self, host, port=port, @@ -131,3 +137,31 @@ class ConnectedCouchDB(client.CouchDB): d.addCallbacks(_get_pubkey_cbk, log.err) return d + + def put_doc(self, uuid, doc): + """ + Update a document. + + If the document currently has conflicts, put will fail. + If the database specifies a maximum document size and the document + exceeds it, put will fail and raise a DocumentTooBig exception. + + :param uuid: The uuid of a user + :type uuid: str + :param doc: A Document with new content. + :type doc: leap.soledad.common.couch.CouchDocument + + :return: A deferred which fires with the new revision identifier for + the document if the Document object has being updated, or + which fails with CouchDBError if there was any error. + """ + # TODO: that should be implemented with paisley + try: + db = CouchDatabase(self._mail_couch_url, "user-%s" % (uuid,)) + return defer.succeed(db.put_doc(doc)) + except Exception as e: + return defer.fail(CouchDBError(e.message)) + + +class CouchDBError(Exception): + pass -- cgit v1.2.3 From 17545618c79478a104ca7be5dd601020f8749780 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 3 Nov 2015 19:38:23 +0100 Subject: [feat] update leap.mx usage of soledad CouchDatabase - Related: #7565 --- src/leap/mx/couchdbhelper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/leap/mx/couchdbhelper.py') diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index b26a0d8..115ecbe 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -52,10 +52,10 @@ class ConnectedCouchDB(client.CouchDB): :param str password: (optional) The password for authorization. :type password: str """ - self.mail_couch_url = "http://%s:%s@%s:%s" % (username, - password, - host, - port) + self._mail_couch_url = "http://%s:%s@%s:%s" % (username, + password, + host, + port) client.CouchDB.__init__(self, host, port=port, @@ -156,8 +156,9 @@ class ConnectedCouchDB(client.CouchDB): which fails with CouchDBError if there was any error. """ # TODO: that should be implemented with paisley + url = self._mail_couch_url + "/user-%s" % (uuid,) try: - db = CouchDatabase(self._mail_couch_url, "user-%s" % (uuid,)) + db = CouchDatabase.open_database(url, create=False) return defer.succeed(db.put_doc(doc)) except Exception as e: return defer.fail(CouchDBError(e.message)) -- cgit v1.2.3 From 8fc1258ace65be2bb828bf302fc0661cdd128bd7 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 18 Nov 2015 00:27:56 +0100 Subject: [feat] postfix lookup against couchdb for client smtp fingerprint - Resolves: #4285 --- src/leap/mx/couchdbhelper.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/leap/mx/couchdbhelper.py') diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index 115ecbe..de133d5 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -138,6 +138,34 @@ class ConnectedCouchDB(client.CouchDB): d.addCallbacks(_get_pubkey_cbk, log.err) return d + def getCertExpiry(self, fingerprint): + """ + Query couch and return a deferred that will fire with the expiration + date for the cert with the given fingerprint. + + :param fingerprint: The cert fingerprint + :type fingerprint: str + + :return: A deferred that will fire with the cert expiration date as a + str. + :rtype: Deferred + """ + d = self.openView(docId="Identity", + viewId="cert_expiry_by_fingerprint/", + key=fingerprint, + reduce=False, + include_docs=True) + + def _get_cert_expiry_cbk(result): + try: + expiry = result["rows"][0]["value"] + except (KeyError, IndexError): + expiry = None + return expiry + + d.addCallback(_get_cert_expiry_cbk) + return d + def put_doc(self, uuid, doc): """ Update a document. -- cgit v1.2.3 From 76df59e41d971a030f3630db96c732efe2577f91 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 11 Mar 2016 13:14:34 +0100 Subject: [bug] Check if the account is enabled - Resolves: #7961 --- src/leap/mx/couchdbhelper.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/leap/mx/couchdbhelper.py') diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index de133d5..e9cf4a4 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -100,9 +100,10 @@ class ConnectedCouchDB(client.CouchDB): pubkey = None if result["rows"]: doc = result["rows"][0]["doc"] - uuid = doc["user_id"] - if "keys" in doc: - pubkey = doc["keys"]["pgp"] + if doc["enabled"]: + uuid = doc["user_id"] + if "keys" in doc: + pubkey = doc["keys"]["pgp"] return uuid, pubkey d.addCallback(_get_uuid_and_pubkey_cbk) -- cgit v1.2.3