diff options
author | Kali Kaneko <kali@leap.se> | 2016-04-28 21:40:43 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2016-07-12 03:09:24 +0200 |
commit | b5aa97e9f88934dd73af84f212c95775f97769a9 (patch) | |
tree | 382b243aca84daf0d400a79cef95b84935632d7f /common/src/leap/soledad/common/tests | |
parent | 7abf86737562b5c79e902921df722f01e71178e6 (diff) |
[refactor] make tests use l2db submodule
From this moment on, we embed a fork of u1db called l2db.
Diffstat (limited to 'common/src/leap/soledad/common/tests')
20 files changed, 188 insertions, 213 deletions
diff --git a/common/src/leap/soledad/common/tests/server_state.py b/common/src/leap/soledad/common/tests/server_state.py index 2fe9472f..26838f89 100644 --- a/common/src/leap/soledad/common/tests/server_state.py +++ b/common/src/leap/soledad/common/tests/server_state.py @@ -26,7 +26,7 @@ import errno import tempfile -from u1db.remote.server_state import ServerState +from leap.soledad.common.l2db.remote.server_state import ServerState from leap.soledad.common.tests.util import ( copy_sqlcipher_database_for_test, ) diff --git a/common/src/leap/soledad/common/tests/test_async.py b/common/src/leap/soledad/common/tests/test_async.py index 302ecc37..52be4ff3 100644 --- a/common/src/leap/soledad/common/tests/test_async.py +++ b/common/src/leap/soledad/common/tests/test_async.py @@ -14,8 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - import os import hashlib diff --git a/common/src/leap/soledad/common/tests/test_couch.py b/common/src/leap/soledad/common/tests/test_couch.py index 7ba50e11..eefefc5d 100644 --- a/common/src/leap/soledad/common/tests/test_couch.py +++ b/common/src/leap/soledad/common/tests/test_couch.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # test_couch.py -# Copyright (C) 2013 LEAP +# Copyright (C) 2013-2016 LEAP # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,26 +14,23 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - """ Test ObjectStore and Couch backend bits. """ - - import json +from uuid import uuid4 from urlparse import urljoin + from couchdb.client import Server -from uuid import uuid4 from testscenarios import TestWithScenarios from twisted.trial import unittest from mock import Mock -from u1db import errors as u1db_errors -from u1db import SyncTarget -from u1db import vectorclock +from leap.soledad.common.l2db import errors as u1db_errors +from leap.soledad.common.l2db import SyncTarget +from leap.soledad.common.l2db import vectorclock from leap.soledad.common import couch from leap.soledad.common.document import ServerDocument diff --git a/common/src/leap/soledad/common/tests/test_http.py b/common/src/leap/soledad/common/tests/test_http.py index bc486fe3..2351748d 100644 --- a/common/src/leap/soledad/common/tests/test_http.py +++ b/common/src/leap/soledad/common/tests/test_http.py @@ -17,10 +17,10 @@ """ Test Leap backend bits: test http database """ -from u1db.remote import http_database from leap.soledad.client import auth from leap.soledad.common.tests.u1db_tests import test_http_database +from leap.soledad.common.l2db.remote import http_database # ----------------------------------------------------------------------------- diff --git a/common/src/leap/soledad/common/tests/test_http_client.py b/common/src/leap/soledad/common/tests/test_http_client.py index 700ae3b6..d932b2b0 100644 --- a/common/src/leap/soledad/common/tests/test_http_client.py +++ b/common/src/leap/soledad/common/tests/test_http_client.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # test_http_client.py -# Copyright (C) 2013, 2014 LEAP +# Copyright (C) 2013-2016 LEAP # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,11 +19,10 @@ Test Leap backend bits: sync target """ import json -from u1db.remote import http_client - from testscenarios import TestWithScenarios from leap.soledad.client import auth +from leap.soledad.common.l2db.remote import http_client from leap.soledad.common.tests.u1db_tests import test_http_client from leap.soledad.server.auth import SoledadTokenAuthMiddleware diff --git a/common/src/leap/soledad/common/tests/test_https.py b/common/src/leap/soledad/common/tests/test_https.py index eeeb4982..8d9b8d92 100644 --- a/common/src/leap/soledad/common/tests/test_https.py +++ b/common/src/leap/soledad/common/tests/test_https.py @@ -14,19 +14,16 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - """ Test Leap backend bits: https """ +from unittest import skip - -from u1db.remote import http_client +from testscenarios import TestWithScenarios from leap.soledad import client -from testscenarios import TestWithScenarios - +from leap.soledad.common.l2db.remote import http_client from leap.soledad.common.tests.u1db_tests import test_backends from leap.soledad.common.tests.u1db_tests import test_https from leap.soledad.common.tests.util import ( @@ -65,14 +62,16 @@ def token_leap_https_sync_target(test, host, path, cert_file=None): return st +@skip("Skiping tests imported from U1DB.") class TestSoledadHTTPSyncTargetHttpsSupport( TestWithScenarios, - test_https.TestHttpSyncTargetHttpsSupport, + # test_https.TestHttpSyncTargetHttpsSupport, BaseSoledadTest): scenarios = [ ('token_soledad_https', - {'server_def': test_https.https_server_def, + { + #'server_def': test_https.https_server_def, 'make_app_with_state': make_token_soledad_app, 'make_document_for_test': make_soledad_document_for_test, 'sync_target': token_leap_https_sync_target}), diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py index 2fee119d..357027e9 100644 --- a/common/src/leap/soledad/common/tests/test_server.py +++ b/common/src/leap/soledad/common/tests/test_server.py @@ -17,16 +17,17 @@ """ Tests for server-related functionality. """ +import binascii +import mock import os import tempfile -import mock import time -import binascii + +from hashlib import sha512 from pkg_resources import resource_filename +from urlparse import urljoin from uuid import uuid4 -from hashlib import sha512 -from urlparse import urljoin from twisted.internet import defer from twisted.trial import unittest diff --git a/common/src/leap/soledad/common/tests/test_soledad_app.py b/common/src/leap/soledad/common/tests/test_soledad_app.py index 4598a7bb..7f9a58d3 100644 --- a/common/src/leap/soledad/common/tests/test_soledad_app.py +++ b/common/src/leap/soledad/common/tests/test_soledad_app.py @@ -14,13 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - """ Test ObjectStore and Couch backend bits. """ - - from testscenarios import TestWithScenarios from leap.soledad.common.tests.util import BaseSoledadTest diff --git a/common/src/leap/soledad/common/tests/test_sqlcipher.py b/common/src/leap/soledad/common/tests/test_sqlcipher.py index 8105c56e..2bcdf0fb 100644 --- a/common/src/leap/soledad/common/tests/test_sqlcipher.py +++ b/common/src/leap/soledad/common/tests/test_sqlcipher.py @@ -26,10 +26,10 @@ import shutil from pysqlcipher import dbapi2 from testscenarios import TestWithScenarios -# u1db stuff. -from u1db import errors -from u1db import query_parser -from u1db.backends.sqlite_backend import SQLitePartialExpandDatabase +# l2db stuff. +from leap.soledad.common.l2db import errors +from leap.soledad.common.l2db import query_parser +from leap.soledad.common.l2db.backends.sqlite_backend import SQLitePartialExpandDatabase # soledad stuff. from leap.soledad.common import soledad_assert diff --git a/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py b/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py index 439fc070..42cfa6b7 100644 --- a/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py +++ b/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # test_sqlcipher.py -# Copyright (C) 2013 LEAP +# Copyright (C) 2013-2016 LEAP # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,20 +17,19 @@ """ Test sqlcipher backend sync. """ - - import os -from u1db import sync -from u1db import vectorclock -from u1db import errors from uuid import uuid4 from testscenarios import TestWithScenarios +from leap.soledad.common.l2db import sync +from leap.soledad.common.l2db import vectorclock +from leap.soledad.common.l2db import errors + from leap.soledad.common.crypto import ENC_SCHEME_KEY -from leap.soledad.client.http_target import SoledadHTTPSyncTarget from leap.soledad.client.crypto import decrypt_doc_dict +from leap.soledad.client.http_target import SoledadHTTPSyncTarget from leap.soledad.common.tests import u1db_tests as tests from leap.soledad.common.tests.test_sqlcipher import SQLCIPHER_SCENARIOS diff --git a/common/src/leap/soledad/common/tests/test_sync.py b/common/src/leap/soledad/common/tests/test_sync.py index 1041367b..cc18d387 100644 --- a/common/src/leap/soledad/common/tests/test_sync.py +++ b/common/src/leap/soledad/common/tests/test_sync.py @@ -14,8 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - import json import tempfile import threading diff --git a/common/src/leap/soledad/common/tests/test_sync_target.py b/common/src/leap/soledad/common/tests/test_sync_target.py index f25e84dd..c9b705a3 100644 --- a/common/src/leap/soledad/common/tests/test_sync_target.py +++ b/common/src/leap/soledad/common/tests/test_sync_target.py @@ -21,7 +21,6 @@ import cStringIO import os import time import json -import u1db import random import string import shutil @@ -36,8 +35,9 @@ from leap.soledad.client.sqlcipher import SQLCipherU1DBSync from leap.soledad.client.sqlcipher import SQLCipherOptions from leap.soledad.client.sqlcipher import SQLCipherDatabase -from leap.soledad.common.document import SoledadDocument +from leap.soledad.common import l2db +from leap.soledad.common.document import SoledadDocument from leap.soledad.common.tests import u1db_tests as tests from leap.soledad.common.tests.util import make_sqlcipher_database_for_test from leap.soledad.common.tests.util import make_soledad_app @@ -90,53 +90,53 @@ class TestSoledadParseReceivedDocResponse(SoledadWithCouchServerMixin): doc.get_json(), doc.doc_id, doc.rev, key, secret) - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("[\r\n{},\r\n]") - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response( ('[\r\n{},\r\n{"id": "i", "rev": "r", ' + '"content": %s, "gen": 3, "trans_id": "T-sid"}' + ',\r\n]') % json.dumps(enc_json)) def test_wrong_start(self): - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("{}\r\n]") - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("\r\n{}\r\n]") - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("") def test_wrong_end(self): - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("[\r\n{}") - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("[\r\n") def test_missing_comma(self): - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response( '[\r\n{}\r\n{"id": "i", "rev": "r", ' '"content": "c", "gen": 3}\r\n]') def test_no_entries(self): - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response("[\r\n]") def test_error_in_stream(self): - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response( '[\r\n{"new_generation": 0},' '\r\n{"error": "unavailable"}\r\n') - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response( '[\r\n{"error": "unavailable"}\r\n') - with self.assertRaises(u1db.errors.BrokenSyncStream): + with self.assertRaises(l2db.errors.BrokenSyncStream): self.target._parse_received_doc_response('[\r\n{"error": "?"}\r\n') # @@ -256,7 +256,7 @@ class TestSoledadSyncTarget( replica_trans_id=None, number_of_docs=None, doc_idx=None, sync_id=None): if doc.doc_id in trigger_ids: - raise u1db.errors.U1DBError + raise l2db.errors.U1DBError return _put_doc_if_newer(doc, save_conflict=save_conflict, replica_uid=replica_uid, replica_gen=replica_gen, @@ -278,7 +278,7 @@ class TestSoledadSyncTarget( doc2 = self.make_document('doc-here2', 'replica:1', '{"value": "here2"}') - with self.assertRaises(u1db.errors.U1DBError): + with self.assertRaises(l2db.errors.U1DBError): yield remote_target.sync_exchange( [(doc1, 10, 'T-sid'), (doc2, 11, 'T-sud')], 'replica', @@ -706,7 +706,7 @@ class SoledadDatabaseSyncTargetTests( def before_get_docs_explode(state): if state != 'before get_docs': return - raise u1db.errors.U1DBError("fail") + raise l2db.errors.U1DBError("fail") self.set_trace_hook(before_get_docs_explode) # suppress traceback printing in the wsgiref server # self.patch(simple_server.ServerHandler, @@ -714,7 +714,7 @@ class SoledadDatabaseSyncTargetTests( doc = self.db.create_doc_from_json(tests.simple_doc) self.assertTransactionLog([doc.doc_id], self.db) self.assertRaises( - (u1db.errors.U1DBError, u1db.errors.BrokenSyncStream), + (l2db.errors.U1DBError, l2db.errors.BrokenSyncStream), self.st.sync_exchange, [], 'other-replica', last_known_generation=0, last_known_trans_id=None, insert_doc_cb=self.receive_doc) diff --git a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py index 01da9381..7f334b4a 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py @@ -36,13 +36,13 @@ from twisted.web.server import Site from twisted.web.wsgi import WSGIResource from twisted.internet import reactor -from u1db import errors -from u1db import Document -from u1db.backends import inmemory -from u1db.backends import sqlite_backend -from u1db.remote import server_state -from u1db.remote import http_app -from u1db.remote import http_target +from leap.soledad.common.l2db import errors +from leap.soledad.common.l2db import Document +from leap.soledad.common.l2db.backends import inmemory +from leap.soledad.common.l2db.backends import sqlite_backend +from leap.soledad.common.l2db.remote import server_state +from leap.soledad.common.l2db.remote import http_app +from leap.soledad.common.l2db.remote import http_target class TestCase(unittest.TestCase): diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py b/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py index 410d838f..c0c6ea6b 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py @@ -1,8 +1,9 @@ # Copyright 2011 Canonical Ltd. +# Copyright 2016 LEAP Encryption Access Project # -# This file is part of u1db. +# This file is part of leap.soledad.common # -# u1db is free software: you can redistribute it and/or modify +# leap.soledad.common is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License version 3 # as published by the Free Software Foundation. # @@ -14,21 +15,21 @@ # You should have received a copy of the GNU Lesser General Public License # along with u1db. If not, see <http://www.gnu.org/licenses/>. -"""The backend class for U1DB. This deals with hiding storage details.""" +""" +The backend class for L2DB. This deals with hiding storage details. +""" import json -from u1db import DocumentBase -from u1db import errors -from u1db import vectorclock +from leap.soledad.common.l2db import DocumentBase +from leap.soledad.common.l2db import errors +from leap.soledad.common.l2db import vectorclock +from leap.soledad.common.l2db.remote import http_database from leap.soledad.common.tests import u1db_tests as tests - from leap.soledad.common.tests.u1db_tests import make_http_app from leap.soledad.common.tests.u1db_tests import make_oauth_http_app -from u1db.remote import http_database - from unittest import skip simple_doc = tests.simple_doc diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_document.py b/common/src/leap/soledad/common/tests/u1db_tests/test_document.py index 23502b4b..4e8bcaf9 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_document.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_document.py @@ -1,8 +1,9 @@ # Copyright 2011 Canonical Ltd. +# Copyright 2016 LEAP Encryption Access Project # -# This file is part of u1db. +# This file is part of leap.soledad.common # -# u1db is free software: you can redistribute it and/or modify +# leap.soledad.common is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License version 3 # as published by the Free Software Foundation. # @@ -13,10 +14,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with u1db. If not, see <http://www.gnu.org/licenses/>. - - from unittest import skip -from u1db import errors + +from leap.soledad.common.l2db import errors from leap.soledad.common.tests import u1db_tests as tests diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_http_client.py b/common/src/leap/soledad/common/tests/u1db_tests/test_http_client.py index 973c3b26..344dcb29 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_http_client.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_http_client.py @@ -1,4 +1,5 @@ # Copyright 2011-2012 Canonical Ltd. +# Copyright 2016 LEAP Encryption Access Project # # This file is part of u1db. # @@ -14,22 +15,17 @@ # You should have received a copy of the GNU Lesser General Public License # along with u1db. If not, see <http://www.gnu.org/licenses/>. -"""Tests for HTTPDatabase""" - -from oauth import oauth +""" +Tests for HTTPDatabase +""" import json -from u1db import ( - errors, -) - from unittest import skip -from leap.soledad.common.tests import u1db_tests as tests +from leap.soledad.common.l2db import errors +from leap.soledad.common.l2db.remote import http_client -from u1db.remote import ( - http_client, -) +from leap.soledad.common.tests import u1db_tests as tests @skip("Skiping tests imported from U1DB.") diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_http_database.py b/common/src/leap/soledad/common/tests/u1db_tests/test_http_database.py index 015e6e69..001aebd4 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_http_database.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_http_database.py @@ -21,11 +21,10 @@ import json from unittest import skip -from u1db import errors -from u1db import Document -from u1db.remote import http_database -from u1db.remote import http_target - +from leap.soledad.common.l2db import errors +from leap.soledad.common.l2db import Document +from leap.soledad.common.l2db.remote import http_database +from leap.soledad.common.l2db.remote import http_target from leap.soledad.common.tests import u1db_tests as tests from leap.soledad.common.tests.u1db_tests import make_http_app diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_https.py b/common/src/leap/soledad/common/tests/u1db_tests/test_https.py index e177a808..8a5743e7 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_https.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_https.py @@ -4,119 +4,111 @@ import os import ssl import sys -from paste import httpserver +#from paste import httpserver from unittest import skip -from u1db.remote import http_client -from u1db.remote import http_target +from leap.soledad.common.l2db.remote import http_client +#from leap.soledad.common.l2db.remote import http_target from leap import soledad from leap.soledad.common.tests import u1db_tests as tests from leap.soledad.common.tests.u1db_tests import make_oauth_http_app -def https_server_def(): - def make_server(host_port, application): - from OpenSSL import SSL - cert_file = os.path.join(os.path.dirname(__file__), 'testing-certs', - 'testing.cert') - key_file = os.path.join(os.path.dirname(__file__), 'testing-certs', - 'testing.key') - ssl_context = SSL.Context(SSL.SSLv23_METHOD) - ssl_context.use_privatekey_file(key_file) - ssl_context.use_certificate_chain_file(cert_file) - srv = httpserver.WSGIServerBase(application, host_port, - httpserver.WSGIHandler, - ssl_context=ssl_context - ) - - def shutdown_request(req): - req.shutdown() - srv.close_request(req) - - srv.shutdown_request = shutdown_request - application.base_url = "https://localhost:%s" % srv.server_address[1] - return srv - return make_server, "shutdown", "https" - - -def oauth_https_sync_target(test, host, path): - _, port = test.server.server_address - st = http_target.HTTPSyncTarget('https://%s:%d/~/%s' % (host, port, path)) - st.set_oauth_credentials(tests.consumer1.key, tests.consumer1.secret, - tests.token1.key, tests.token1.secret) - return st - - -@skip("Skiping tests imported from U1DB.") -class TestHttpSyncTargetHttpsSupport(tests.TestCaseWithServer): - - scenarios = [ - ('oauth_https', {'server_def': https_server_def, - 'make_app_with_state': make_oauth_http_app, - 'make_document_for_test': - tests.make_document_for_test, - 'sync_target': oauth_https_sync_target - }), - ] - - def setUp(self): - try: - import OpenSSL # noqa - except ImportError: - self.skipTest("Requires pyOpenSSL") - self.cacert_pem = os.path.join(os.path.dirname(__file__), - 'testing-certs', 'cacert.pem') +#def https_server_def(): + #def make_server(host_port, application): + #from OpenSSL import SSL + #cert_file = os.path.join(os.path.dirname(__file__), 'testing-certs', + #'testing.cert') + #key_file = os.path.join(os.path.dirname(__file__), 'testing-certs', + #'testing.key') + #ssl_context = SSL.Context(SSL.SSLv23_METHOD) + #ssl_context.use_privatekey_file(key_file) + #ssl_context.use_certificate_chain_file(cert_file) + #srv = httpserver.WSGIServerBase(application, host_port, + #httpserver.WSGIHandler, + #ssl_context=ssl_context + #) +# + #def shutdown_request(req): + #req.shutdown() + #srv.close_request(req) +# + #srv.shutdown_request = shutdown_request + #application.base_url = "https://localhost:%s" % srv.server_address[1] + #return srv + #return make_server, "shutdown", "https" + + +#@skip("Skiping tests imported from U1DB.") +#class TestHttpSyncTargetHttpsSupport(tests.TestCaseWithServer): +# + #scenarios = [ + #('oauth_https', {'server_def': https_server_def, + #'make_app_with_state': make_oauth_http_app, + #'make_document_for_test': + #tests.make_document_for_test, + #'sync_target': oauth_https_sync_target + #}), + #] +# + #def setUp(self): + #try: + #import OpenSSL # noqa + #except ImportError: + #self.skipTest("Requires pyOpenSSL") + #self.cacert_pem = os.path.join(os.path.dirname(__file__), + #'testing-certs', 'cacert.pem') # The default u1db http_client class for doing HTTPS only does HTTPS # if the platform is linux. Because of this, soledad replaces that # class with one that will do HTTPS independent of the platform. In # order to maintain the compatibility with u1db default tests, we undo # that replacement here. - http_client._VerifiedHTTPSConnection = \ - soledad.client.api.old__VerifiedHTTPSConnection - super(TestHttpSyncTargetHttpsSupport, self).setUp() - - def getSyncTarget(self, host, path=None, cert_file=None): - if self.server is None: - self.startServer() - return self.sync_target(self, host, path, cert_file=cert_file) - - def test_working(self): - self.startServer() - db = self.request_state._create_database('test') - self.patch(http_client, 'CA_CERTS', self.cacert_pem) - remote_target = self.getSyncTarget('localhost', 'test') - remote_target.record_sync_info('other-id', 2, 'T-id') - self.assertEqual( - (2, 'T-id'), db._get_replica_gen_and_trans_id('other-id')) - - def test_cannot_verify_cert(self): - if not sys.platform.startswith('linux'): - self.skipTest( - "XXX certificate verification happens on linux only for now") - self.startServer() + #http_client._VerifiedHTTPSConnection = \ + #soledad.client.api.old__VerifiedHTTPSConnection + #super(TestHttpSyncTargetHttpsSupport, self).setUp() +# + #def getSyncTarget(self, host, path=None, cert_file=None): + #if self.server is None: + #self.startServer() + #return self.sync_target(self, host, path, cert_file=cert_file) +# + #def test_working(self): + #self.startServer() + #db = self.request_state._create_database('test') + #self.patch(http_client, 'CA_CERTS', self.cacert_pem) + #remote_target = self.getSyncTarget('localhost', 'test') + #remote_target.record_sync_info('other-id', 2, 'T-id') + #self.assertEqual( + #(2, 'T-id'), db._get_replica_gen_and_trans_id('other-id')) +# + #def test_cannot_verify_cert(self): + #if not sys.platform.startswith('linux'): + #self.skipTest( + #"XXX certificate verification happens on linux only for now") + #self.startServer() # don't print expected traceback server-side - self.server.handle_error = lambda req, cli_addr: None - self.request_state._create_database('test') - remote_target = self.getSyncTarget('localhost', 'test') - try: - remote_target.record_sync_info('other-id', 2, 'T-id') - except ssl.SSLError, e: - self.assertIn("certificate verify failed", str(e)) - else: - self.fail("certificate verification should have failed.") - - def test_host_mismatch(self): - if not sys.platform.startswith('linux'): - self.skipTest( - "XXX certificate verification happens on linux only for now") - self.startServer() - self.request_state._create_database('test') - self.patch(http_client, 'CA_CERTS', self.cacert_pem) - remote_target = self.getSyncTarget('127.0.0.1', 'test') - self.assertRaises( - http_client.CertificateError, remote_target.record_sync_info, - 'other-id', 2, 'T-id') - - -load_tests = tests.load_with_scenarios + #self.server.handle_error = lambda req, cli_addr: None + #self.request_state._create_database('test') + #remote_target = self.getSyncTarget('localhost', 'test') + #try: + #remote_target.record_sync_info('other-id', 2, 'T-id') + #except ssl.SSLError, e: + #self.assertIn("certificate verify failed", str(e)) + #else: + #self.fail("certificate verification should have failed.") +# + #def test_host_mismatch(self): + #if not sys.platform.startswith('linux'): + #self.skipTest( + #"XXX certificate verification happens on linux only for now") + #self.startServer() + #self.request_state._create_database('test') + #self.patch(http_client, 'CA_CERTS', self.cacert_pem) + #remote_target = self.getSyncTarget('127.0.0.1', 'test') + #self.assertRaises( + #http_client.CertificateError, remote_target.record_sync_info, + #'other-id', 2, 'T-id') +# +# +#load_tests = tests.load_with_scenarios diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_open.py b/common/src/leap/soledad/common/tests/u1db_tests/test_open.py index ee249e6e..2fc04e38 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_open.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_open.py @@ -1,4 +1,5 @@ # Copyright 2011 Canonical Ltd. +# Copyright 2016 LEAP Encryption Access Project # # This file is part of u1db. # @@ -17,14 +18,13 @@ """Test u1db.open""" import os +from unittest import skip -from u1db import ( - errors, - open as u1db_open, +from leap.soledad.common.l2db import ( + errors, open as u1db_open, ) -from unittest import skip from leap.soledad.common.tests import u1db_tests as tests -from u1db.backends import sqlite_backend +from leap.soledad.common.l2db.backends import sqlite_backend from leap.soledad.common.tests.u1db_tests.test_backends \ import TestAlternativeDocument diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py index c681fa93..abe531ce 100644 --- a/common/src/leap/soledad/common/tests/util.py +++ b/common/src/leap/soledad/common/tests/util.py @@ -26,7 +26,6 @@ import tempfile import shutil import random import string -import u1db import couchdb from uuid import uuid4 @@ -35,13 +34,14 @@ from urlparse import urljoin from StringIO import StringIO from pysqlcipher import dbapi2 -from u1db import sync -from u1db.remote import http_database - from twisted.trial import unittest from leap.common.testing.basetest import BaseLeapTest +from leap.soledad.common import l2db +from leap.soledad.common.l2db import sync +from leap.soledad.common.l2db.remote import http_database + from leap.soledad.common import soledad_assert from leap.soledad.common.document import SoledadDocument from leap.soledad.common.couch import CouchDatabase @@ -234,9 +234,9 @@ class BaseSoledadTest(BaseLeapTest, MockedSharedDBTest): self.db2_file = os.path.join(self.tempdir, "db2.u1db") self.email = ADDRESS # open test dbs - self._db1 = u1db.open(self.db1_file, create=True, + self._db1 = l2db.open(self.db1_file, create=True, document_factory=SoledadDocument) - self._db2 = u1db.open(self.db2_file, create=True, + self._db2 = l2db.open(self.db2_file, create=True, document_factory=SoledadDocument) # get a random prefix for each test, so we do not mess with # concurrency during initialization and shutting down of |