diff options
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/soledad/auth.py | 5 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_couch.py | 22 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_leap_backend.py | 103 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_sqlcipher.py | 26 |
4 files changed, 83 insertions, 73 deletions
diff --git a/src/leap/soledad/auth.py b/src/leap/soledad/auth.py index 44755d58..35f4700f 100644 --- a/src/leap/soledad/auth.py +++ b/src/leap/soledad/auth.py @@ -21,6 +21,9 @@ Methods for token-based authentication. """ +from u1db.remote.http_client import HTTPClientBase + + def set_token_credentials(self, address, token): self._creds = {'token': (address, token)} @@ -30,3 +33,5 @@ def _sign_request(self, method, url_query, params): address, token = self._creds['token'] auth = '%s:%s' % (address, token) return [('Authorization', 'Token %s' % auth.encode('base64'))] + else: + return HTTPClientBase._sign_request(self, method, url_query, params) diff --git a/src/leap/soledad/tests/test_couch.py b/src/leap/soledad/tests/test_couch.py index 456bc080..b0352782 100644 --- a/src/leap/soledad/tests/test_couch.py +++ b/src/leap/soledad/tests/test_couch.py @@ -1,7 +1,23 @@ -"""Test ObjectStore backend bits. +# -*- coding: utf-8 -*- +# test_couch.py +# Copyright (C) 2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. -For these tests to run, a couch server has to be running on (default) port -5984. + +""" +Test ObjectStore and Couch backend bits. """ import re diff --git a/src/leap/soledad/tests/test_leap_backend.py b/src/leap/soledad/tests/test_leap_backend.py index 7509af0e..4c76bbb9 100644 --- a/src/leap/soledad/tests/test_leap_backend.py +++ b/src/leap/soledad/tests/test_leap_backend.py @@ -1,7 +1,23 @@ -"""Test ObjectStore backend bits. +# -*- coding: utf-8 -*- +# test_leap_backend.py +# Copyright (C) 2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. -For these tests to run, a leap server has to be running on (default) port -5984. + +""" +Test Leap backend bits. """ import u1db @@ -12,9 +28,11 @@ except ImportError: from leap.soledad.backends import leap_backend +from leap.soledad.server import SoledadApp + + from leap.soledad.tests import u1db_tests as tests from leap.soledad.tests.u1db_tests.test_remote_sync_target import ( - make_http_app, make_oauth_http_app, ) from leap.soledad.tests import BaseSoledadTest @@ -36,12 +54,16 @@ def make_leap_document_for_test(test, doc_id, rev, content, doc_id, rev, content, has_conflicts=has_conflicts) +def make_soledad_app(state): + return SoledadApp(state) + + LEAP_SCENARIOS = [ ('http', { 'make_database_for_test': test_backends.make_http_database_for_test, 'copy_database_for_test': test_backends.copy_http_database_for_test, 'make_document_for_test': make_leap_document_for_test, - 'make_app_with_state': make_http_app}), + 'make_app_with_state': make_soledad_app}), ] @@ -55,6 +77,9 @@ class LeapTests(test_backends.AllDatabaseTests, BaseSoledadTest): #----------------------------------------------------------------------------- class TestLeapClientBase(test_http_client.TestHTTPClientBase): + """ + This class should be used to test Token auth. + """ pass @@ -89,6 +114,9 @@ class TestLeapSyncTargetBasics( self.assertEqual('/', remote_target._url.path) +# Monkey patch test class so it uses our sync target. +test_remote_sync_target.http_target.HTTPSyncTarget = leap_backend.LeapSyncTarget + class TestLeapParsingSyncStream( test_remote_sync_target.TestParsingSyncStream, BaseSoledadTest): @@ -101,53 +129,6 @@ class TestLeapParsingSyncStream( test_remote_sync_target.TestParsingSyncStream.tearDown(self) BaseSoledadTest.tearDown(self) - def test_wrong_start(self): - """ - Test adapted to use a LeapSyncTarget. - """ - tgt = leap_backend.LeapSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "{}\r\n]", None) - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "\r\n{}\r\n]", None) - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "", None) - - def test_wrong_end(self): - """ - Test adapted to use a LeapSyncTarget. - """ - tgt = leap_backend.LeapSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n{}", None) - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n", None) - - def test_missing_comma(self): - """ - Test adapted to use a LeapSyncTarget. - """ - tgt = leap_backend.LeapSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, - '[\r\n{}\r\n{"id": "i", "rev": "r", ' - '"content": "c", "gen": 3}\r\n]', None) - - def test_no_entries(self): - """ - Test adapted to use a LeapSyncTarget. - """ - tgt = leap_backend.LeapSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n]", None) - def test_extra_comma(self): """ Test adapted to use encrypted content. @@ -168,22 +149,6 @@ class TestLeapParsingSyncStream( ',\r\n]' % json.dumps(enc_json), lambda doc, gen, trans_id: None) - def test_error_in_stream(self): - tgt = leap_backend.LeapSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.Unavailable, - tgt._parse_sync_stream, - '[\r\n{"new_generation": 0},' - '\r\n{"error": "unavailable"}\r\n', None) - - self.assertRaises(u1db.errors.Unavailable, - tgt._parse_sync_stream, - '[\r\n{"error": "unavailable"}\r\n', None) - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, - '[\r\n{"error": "?"}\r\n', None) - def leap_sync_target(test, path): return leap_backend.LeapSyncTarget(test.getURL(path)) @@ -199,7 +164,7 @@ def oauth_leap_sync_target(test, path): class TestRemoteSyncTargets(tests.TestCaseWithServer): scenarios = [ - ('http', {'make_app_with_state': make_http_app, + ('http', {'make_app_with_state': make_soledad_app, 'make_document_for_test': make_leap_document_for_test, 'sync_target': leap_sync_target}), ('oauth_http', {'make_app_with_state': make_oauth_http_app, diff --git a/src/leap/soledad/tests/test_sqlcipher.py b/src/leap/soledad/tests/test_sqlcipher.py index 6b2889d6..b937b634 100644 --- a/src/leap/soledad/tests/test_sqlcipher.py +++ b/src/leap/soledad/tests/test_sqlcipher.py @@ -1,4 +1,25 @@ -"""Test sqlcipher backend internals.""" +# -*- coding: utf-8 -*- +# test_sqlcipher.py +# Copyright (C) 2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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 sqlcipher backend internals. +""" + import os import time @@ -11,6 +32,7 @@ import threading from pysqlcipher import dbapi2 from StringIO import StringIO + # u1db stuff. from u1db import ( errors, @@ -20,6 +42,7 @@ from u1db import ( ) from u1db.backends.sqlite_backend import SQLitePartialExpandDatabase + # soledad stuff. from leap.soledad.backends.sqlcipher import ( SQLCipherDatabase, @@ -36,6 +59,7 @@ from leap.soledad.backends.leap_backend import ( MAC_KEY, ) + # u1db tests stuff. from leap.soledad.tests import u1db_tests as tests, BaseSoledadTest from leap.soledad.tests.u1db_tests import test_sqlite_backend |