summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Wagner <bwgpro@gmail.com>2015-08-12 18:56:38 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-08-12 19:03:50 -0300
commitffde23f71594cec5775a1579cdc0ee4b019fbf6d (patch)
tree02be041313b1462e1b43bc9ecd1ec70f1d205b1d
parent861f7d355f2b42b02d00906cbb63351cbc5d0146 (diff)
[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
-rw-r--r--client/src/leap/soledad/client/adbapi.py14
-rw-r--r--common/src/leap/soledad/common/errors.py5
-rw-r--r--common/src/leap/soledad/common/tests/test_soledad.py12
3 files changed, 22 insertions, 9 deletions
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 = {}
diff --git a/common/src/leap/soledad/common/errors.py b/common/src/leap/soledad/common/errors.py
index f285cc77..5798770b 100644
--- a/common/src/leap/soledad/common/errors.py
+++ b/common/src/leap/soledad/common/errors.py
@@ -51,6 +51,11 @@ class SoledadError(errors.U1DBError):
# Authorization errors
#
+
+class DatabaseAccessError(Exception):
+ pass
+
+
@register_exception
class InvalidAuthTokenError(errors.Unauthorized):
diff --git a/common/src/leap/soledad/common/tests/test_soledad.py b/common/src/leap/soledad/common/tests/test_soledad.py
index 1217b763..c8bcaba1 100644
--- a/common/src/leap/soledad/common/tests/test_soledad.py
+++ b/common/src/leap/soledad/common/tests/test_soledad.py
@@ -27,7 +27,7 @@ from leap.soledad.common.tests.util import (
)
from leap import soledad
from leap.soledad.common.document import SoledadDocument
-from leap.soledad.common.crypto import WrongMacError
+from leap.soledad.common.errors import DatabaseAccessError
from leap.soledad.client import Soledad
from leap.soledad.client.adbapi import U1DBConnectionPool
from leap.soledad.client.secrets import PassphraseTooShort
@@ -114,11 +114,11 @@ class AuxMethodsTestCase(BaseSoledadTest):
sol.close()
def _assert_wrong_password_raises(results):
- self.assertRaises(
- WrongMacError,
- self._soledad_instance, 'leap@leap.se',
- passphrase=u'123',
- prefix=prefix)
+ with self.assertRaises(DatabaseAccessError):
+ self._soledad_instance(
+ 'leap@leap.se',
+ passphrase=u'123',
+ prefix=prefix)
def _instantiate_with_new_passphrase(results):
sol2 = self._soledad_instance(