From ffde23f71594cec5775a1579cdc0ee4b019fbf6d Mon Sep 17 00:00:00 2001 From: Bruno Wagner Date: Wed, 12 Aug 2015 18:56:38 -0300 Subject: [bug] wrong sqlcipher passphrase now raises correctly When you tried to start a local sqlcipher that was created before, with the wrong passphrase, the code was raising a sqlcipher DatabaseError, there were tests covering this but they were expecting a WrongMacError that was never raised. I added code to wrap the DatabaseError and raise a new exception DatabaseAccessError that is specific to soledad and adapted the tests to expect it --- client/src/leap/soledad/client/adbapi.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'client/src/leap/soledad') diff --git a/client/src/leap/soledad/client/adbapi.py b/client/src/leap/soledad/client/adbapi.py index 2bf89a6c..237159bd 100644 --- a/client/src/leap/soledad/client/adbapi.py +++ b/client/src/leap/soledad/client/adbapi.py @@ -30,6 +30,9 @@ from twisted.enterprise import adbapi from twisted.python import log from zope.proxy import ProxyBase, setProxiedObject from pysqlcipher.dbapi2 import OperationalError +from pysqlcipher.dbapi2 import DatabaseError + +from leap.soledad.common.errors import DatabaseAccessError from leap.soledad.client import sqlcipher as soledad_sqlcipher from leap.soledad.client.pragmas import set_init_pragmas @@ -100,7 +103,10 @@ class U1DBConnection(adbapi.Connection): """ self.init_u1db = init_u1db self._sync_enc_pool = sync_enc_pool - adbapi.Connection.__init__(self, pool) + try: + adbapi.Connection.__init__(self, pool) + except DatabaseError: + raise DatabaseAccessError('Could not open sqlcipher database') def reconnect(self): """ @@ -166,8 +172,10 @@ class U1DBConnectionPool(adbapi.ConnectionPool): # extract soledad-specific objects from keyword arguments self.opts = kwargs.pop("opts") self._sync_enc_pool = kwargs.pop("sync_enc_pool") - - adbapi.ConnectionPool.__init__(self, *args, **kwargs) + try: + adbapi.ConnectionPool.__init__(self, *args, **kwargs) + except DatabaseError: + raise DatabaseAccessError('Could not open sqlcipher database') # all u1db connections, hashed by thread-id self._u1dbconnections = {} -- cgit v1.2.3