summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-04-29 15:39:57 -0300
committerdrebs <drebs@leap.se>2013-04-29 15:39:57 -0300
commit2b52811ce7357b1a10aacb274903e090574166cc (patch)
treee7e4295d53e786635d023f0004d2d1bc460be36c
parentcc9537b9c73c6f502dc4576df0aee4409e887d47 (diff)
Remove gnupg_home from where it still was.
-rw-r--r--src/leap/soledad/__init__.py10
-rw-r--r--src/leap/soledad/config.py8
-rw-r--r--src/leap/soledad/tests/__init__.py5
-rw-r--r--src/leap/soledad/tests/test_crypto.py104
-rw-r--r--src/leap/soledad/tests/test_soledad.py22
5 files changed, 109 insertions, 40 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py
index 06f7c755..d6122608 100644
--- a/src/leap/soledad/__init__.py
+++ b/src/leap/soledad/__init__.py
@@ -107,7 +107,7 @@ class Soledad(object):
The length of the secret used for symmetric encryption.
"""
- def __init__(self, address, passphrase, config_path=None, gnupg_home=None,
+ def __init__(self, address, passphrase, config_path=None,
secret_path=None, local_db_path=None,
shared_db_url=None, auth_token=None, bootstrap=True):
"""
@@ -120,8 +120,6 @@ class Soledad(object):
@type passphrase: str
@param config_path: Path for configuration file.
@type config_path: str
- @param gnupg_home: Home directory for gnupg.
- @type gnupg_home: str
@param secret_path: Path for storing encrypted key used for
symmetric encryption.
@type secret_path: str
@@ -142,7 +140,6 @@ class Soledad(object):
self._auth_token = auth_token
self._init_config(
config_path=config_path,
- gnupg_home=gnupg_home,
secret_path=secret_path,
local_db_path=local_db_path,
shared_db_url=shared_db_url,
@@ -223,7 +220,7 @@ class Soledad(object):
else:
self._config.load(data='')
# overwrite config with passed parameters
- for param in ['gnupg_home', 'secret_path', 'local_db_path',
+ for param in ['secret_path', 'local_db_path',
'shared_db_url']:
if param in kwargs and kwargs[param] is not None:
self._config._config_checker.config[param] = kwargs[param]
@@ -234,8 +231,7 @@ class Soledad(object):
"""
paths = map(
lambda x: os.path.dirname(x),
- [self._config.get_gnupg_home(), self._config.get_local_db_path(),
- self._config.get_secret_path()])
+ [self._config.get_local_db_path(), self._config.get_secret_path()])
for path in paths:
if not os.path.isdir(path):
os.makedirs(path)
diff --git a/src/leap/soledad/config.py b/src/leap/soledad/config.py
index 3e892d67..e4b34b71 100644
--- a/src/leap/soledad/config.py
+++ b/src/leap/soledad/config.py
@@ -37,11 +37,6 @@ soledad_config_spec = {
'description': 'sample soledad config',
'type': 'object',
'properties': {
- 'gnupg_home': {
- 'type': unicode,
- 'default': PREFIX + '/gnupg',
- 'required': True,
- },
'secret_path': {
'type': unicode,
'default': PREFIX + '/secret.gpg',
@@ -69,9 +64,6 @@ class SoledadConfig(BaseConfig):
"""
return soledad_config_spec
- def get_gnupg_home(self):
- return self._safe_get_value("gnupg_home")
-
def get_secret_path(self):
return self._safe_get_value("secret_path")
diff --git a/src/leap/soledad/tests/__init__.py b/src/leap/soledad/tests/__init__.py
index dac27a29..a30193d3 100644
--- a/src/leap/soledad/tests/__init__.py
+++ b/src/leap/soledad/tests/__init__.py
@@ -23,7 +23,6 @@ class BaseSoledadTest(BaseLeapTest):
def setUp(self):
# config info
- self.gnupg_home = "%s/gnupg" % self.tempdir
self.db1_file = "%s/db1.u1db" % self.tempdir
self.db2_file = "%s/db2.u1db" % self.tempdir
self.email = 'leap@leap.se'
@@ -48,13 +47,11 @@ class BaseSoledadTest(BaseLeapTest):
self._soledad.close()
def _soledad_instance(self, user='leap@leap.se', prefix='',
- bootstrap=False, gnupg_home='/gnupg',
- secret_path='/secret.gpg',
+ bootstrap=False, secret_path='/secret.gpg',
local_db_path='/soledad.u1db'):
return Soledad(
user,
'123',
- gnupg_home=self.tempdir+prefix+gnupg_home,
secret_path=self.tempdir+prefix+secret_path,
local_db_path=self.tempdir+prefix+local_db_path,
bootstrap=bootstrap)
diff --git a/src/leap/soledad/tests/test_crypto.py b/src/leap/soledad/tests/test_crypto.py
index 676c13b0..5d494818 100644
--- a/src/leap/soledad/tests/test_crypto.py
+++ b/src/leap/soledad/tests/test_crypto.py
@@ -20,8 +20,9 @@
Tests for cryptographic related stuff.
"""
-
import os
+import shutil
+import tempfile
try:
import simplejson as json
except ImportError:
@@ -33,15 +34,20 @@ from leap.soledad.backends.leap_backend import (
encrypt_doc_json,
decrypt_doc_json,
EncryptionSchemes,
+ LeapSyncTarget,
)
-from leap.soledad import KeyAlreadyExists
+from leap.soledad.backends.couch import CouchDatabase
+from leap.soledad import KeyAlreadyExists, Soledad
from leap.soledad.crypto import SoledadCrypto
-from leap.common.testing.basetest import BaseLeapTest
from leap.soledad.tests import BaseSoledadTest
+from leap.soledad.tests.test_couch import CouchDBTestCase
from leap.soledad.tests import (
KEY_FINGERPRINT,
PRIVATE_KEY,
)
+from leap.soledad.tests.u1db_tests import simple_doc, nested_doc, TestCaseWithServer
+from leap.soledad.tests.test_leap_backend import make_leap_document_for_test
+from leap.soledad.backends.couch import CouchServerState
class EncryptedSyncTestCase(BaseSoledadTest):
@@ -80,6 +86,96 @@ class EncryptedSyncTestCase(BaseSoledadTest):
"could not encrypt with passphrase.")
+#from leap.soledad.server import SoledadApp, SoledadAuthMiddleware
+#
+#
+#def make_token_leap_app(test, state):
+# app = SoledadApp(state)
+# application = SoledadAuthMiddleware(app, prefix='/soledad/')
+# return application
+#
+#
+#def leap_sync_target(test, path):
+# return LeapSyncTarget(test.getURL(path))
+#
+#
+#def token_leap_sync_target(test, path):
+# st = leap_sync_target(test, 'soledad/' + path)
+# st.set_token_credentials('any_user', 'any_token')
+# return st
+#
+#
+#class EncryptedCouchSyncTest(CouchDBTestCase, TestCaseWithServer):
+#
+# make_app_with_state = make_token_leap_app
+#
+# make_document_for_test = make_leap_document_for_test
+#
+# sync_target = token_leap_sync_target
+#
+# def make_app(self):
+# # potential hook point
+# self.request_state = CouchServerState(self._couch_url)
+# return self.make_app_with_state(self.request_state)
+#
+# def _soledad_instance(self, user='leap@leap.se', prefix='',
+# bootstrap=False, gnupg_home='/gnupg',
+# secret_path='/secret.gpg',
+# local_db_path='/soledad.u1db'):
+# return Soledad(
+# user,
+# '123',
+# gnupg_home=self.tempdir+prefix+gnupg_home,
+# secret_path=self.tempdir+prefix+secret_path,
+# local_db_path=self.tempdir+prefix+local_db_path,
+# bootstrap=bootstrap)
+#
+# def setUp(self):
+# CouchDBTestCase.setUp(self)
+# TestCaseWithServer.setUp(self)
+# self.tempdir = tempfile.mkdtemp(suffix='.couch.test')
+# # initialize soledad by hand so we can control keys
+# self._soledad = self._soledad_instance('leap@leap.se')
+# self._soledad._init_dirs()
+# self._soledad._crypto = SoledadCrypto(self._soledad)
+# if not self._soledad._has_symkey():
+# self._soledad._gen_symkey()
+# self._soledad._load_symkey()
+# self._soledad._init_db()
+#
+# def tearDown(self):
+# shutil.rmtree(self.tempdir)
+#
+# def test_encrypted_sym_sync(self):
+# # get direct access to couchdb
+# import ipdb; ipdb.set_trace()
+# self._couch_url = 'http://localhost:' + str(self.wrapper.port)
+# db = CouchDatabase(self._couch_url, 'testdb')
+# # create and encrypt a doc to insert directly in couchdb
+# doc = LeapDocument('doc-id')
+# doc.set_json(
+# encrypt_doc_json(
+# self._soledad._crypto, 'doc-id', json.dumps(simple_doc)))
+# db.put_doc(doc)
+# # setup credentials for access to soledad server
+# creds = {
+# 'token': {
+# 'address': 'leap@leap.se',
+# 'token': '1234',
+# }
+# }
+# # sync local soledad db with server
+# self.assertTrue(self._soledad.get_doc('doc-id') is None)
+# self.startServer()
+# # TODO fix sync for test.
+# #self._soledad.sync(self.getURL('soledad/testdb'), creds)
+# # get and check doc
+# doc = self._soledad.get_doc('doc-id')
+# # TODO: fix below.
+# #self.assertTrue(doc is not None)
+# #self.assertTrue(doc.content == simple_doc)
+
+
class RecoveryDocumentTestCase(BaseSoledadTest):
def test_export_recovery_document_raw(self):
@@ -117,7 +213,6 @@ class RecoveryDocumentTestCase(BaseSoledadTest):
def test_import_recovery_document_raw(self):
rd = self._soledad.export_recovery_document(None)
- gnupg_home = self.gnupg_home = "%s/gnupg2" % self.tempdir
s = self._soledad_instance(user='anotheruser@leap.se', prefix='/2')
s._init_dirs()
s._crypto = SoledadCrypto(s)
@@ -130,7 +225,6 @@ class RecoveryDocumentTestCase(BaseSoledadTest):
def test_import_recovery_document_crypt(self):
rd = self._soledad.export_recovery_document('123456')
- gnupg_home = self.gnupg_home = "%s/gnupg2" % self.tempdir
s = self._soledad_instance(user='anotheruser@leap.se', prefix='3')
s._init_dirs()
s._crypto = SoledadCrypto(s)
diff --git a/src/leap/soledad/tests/test_soledad.py b/src/leap/soledad/tests/test_soledad.py
index bbe9ad4b..caf9be44 100644
--- a/src/leap/soledad/tests/test_soledad.py
+++ b/src/leap/soledad/tests/test_soledad.py
@@ -41,10 +41,8 @@ class AuxMethodsTestCase(BaseSoledadTest):
sol = self._soledad_instance(prefix='/_init_dirs')
sol._init_dirs()
local_db_dir = os.path.dirname(sol._config.get_local_db_path())
- gnupg_home = os.path.dirname(sol._config.get_gnupg_home())
secret_path = os.path.dirname(sol._config.get_secret_path())
self.assertTrue(os.path.isdir(local_db_dir))
- self.assertTrue(os.path.isdir(gnupg_home))
self.assertTrue(os.path.isdir(secret_path))
def test__init_db(self):
@@ -65,8 +63,6 @@ class AuxMethodsTestCase(BaseSoledadTest):
"""
sol = Soledad('leap@leap.se', passphrase='123', bootstrap=False)
self.assertTrue(bool(re.match(
- '.*/\.config/leap/soledad/gnupg', sol._config.get_gnupg_home())))
- self.assertTrue(bool(re.match(
'.*/\.config/leap/soledad/secret.gpg',
sol._config.get_secret_path())))
self.assertTrue(bool(re.match(
@@ -85,8 +81,6 @@ class AuxMethodsTestCase(BaseSoledadTest):
# that change.
sol = Soledad('leap@leap.se', passphrase='123', bootstrap=False)
self.assertTrue(bool(re.match(
- '.*/\.config/leap/soledad/gnupg', sol._config.get_gnupg_home())))
- self.assertTrue(bool(re.match(
'.*/\.config/leap/soledad/secret.gpg',
sol._config.get_secret_path())))
self.assertTrue(bool(re.match(
@@ -104,10 +98,9 @@ class AuxMethodsTestCase(BaseSoledadTest):
# changed by the BaseLeapTest class but BaseConfig does not capture
# that change.
config_values = {
- "gnupg_home": "value_1",
- "secret_path": "value_2",
- "local_db_path": "value_3",
- "shared_db_url": "value_4"
+ "secret_path": "value_1",
+ "local_db_path": "value_2",
+ "shared_db_url": "value_3"
}
tmpfile = tempfile.mktemp(dir=self.tempdir)
f = open(tmpfile, 'w')
@@ -118,10 +111,9 @@ class AuxMethodsTestCase(BaseSoledadTest):
passphrase='123',
bootstrap=False,
config_path=tmpfile)
- self.assertEqual('value_1', sol._config.get_gnupg_home())
- self.assertEqual('value_2', sol._config.get_secret_path())
- self.assertEqual('value_3', sol._config.get_local_db_path())
- self.assertEqual('value_4', sol._config.get_shared_db_url())
+ self.assertEqual('value_1', sol._config.get_secret_path())
+ self.assertEqual('value_2', sol._config.get_local_db_path())
+ self.assertEqual('value_3', sol._config.get_shared_db_url())
def test__init_config_from_params(self):
"""
@@ -134,11 +126,9 @@ class AuxMethodsTestCase(BaseSoledadTest):
'leap@leap.se',
passphrase='123',
bootstrap=False,
- gnupg_home='value_4',
secret_path='value_3',
local_db_path='value_2',
shared_db_url='value_1')
- self.assertEqual('value_4', sol._config.get_gnupg_home())
self.assertEqual('value_3', sol._config.get_secret_path())
self.assertEqual('value_2', sol._config.get_local_db_path())
self.assertEqual('value_1', sol._config.get_shared_db_url())