diff options
-rw-r--r-- | client/src/leap/soledad/client/http_target.py | 7 | ||||
-rw-r--r-- | common/src/leap/soledad/common/tests/test_sync_target.py | 51 |
2 files changed, 26 insertions, 32 deletions
diff --git a/client/src/leap/soledad/client/http_target.py b/client/src/leap/soledad/client/http_target.py index f5d8ef1c..31729e2c 100644 --- a/client/src/leap/soledad/client/http_target.py +++ b/client/src/leap/soledad/client/http_target.py @@ -527,8 +527,11 @@ class SoledadHTTPSyncTarget(SyncTarget): raise errors.BrokenSyncStream data = parts[1:-1] # decode metadata - line, comma = utils.check_and_strip_comma(data[0]) - metadata = None + try: + line, comma = utils.check_and_strip_comma(data[0]) + metadata = None + except (IndexError): + raise errors.BrokenSyncStream try: metadata = json.loads(line) new_generation = metadata['new_generation'] 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 070ead3e..21ead889 100644 --- a/common/src/leap/soledad/common/tests/test_sync_target.py +++ b/common/src/leap/soledad/common/tests/test_sync_target.py @@ -56,7 +56,7 @@ from leap.soledad.common.tests.u1db_tests import test_sync # The following tests come from `u1db.tests.test_remote_sync_target`. # ----------------------------------------------------------------------------- -class TestSoledadParsingSyncStream( +class TestSoledadParseReceivedDocResponse( test_remote_sync_target.TestParsingSyncStream, BaseSoledadTest): @@ -112,49 +112,40 @@ class TestSoledadParsingSyncStream( self.target._parse_received_doc_response("") def test_wrong_end(self): - tgt = target.SoledadHTTPSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n{}", None) + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response("[\r\n{}") - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n", None) + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response("[\r\n") def test_missing_comma(self): - tgt = target.SoledadHTTPSyncTarget("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) + with self.assertRaises(u1db.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): - tgt = target.SoledadHTTPSyncTarget("http://foo/foo") - - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, "[\r\n]", None) + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response("[\r\n]") def test_error_in_stream(self): - tgt = target.SoledadHTTPSyncTarget("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) + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response( + '[\r\n{"new_generation": 0},' + '\r\n{"error": "unavailable"}\r\n') - self.assertRaises(u1db.errors.BrokenSyncStream, - tgt._parse_sync_stream, - '[\r\n{"error": "?"}\r\n', None) + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response( + '[\r\n{"error": "unavailable"}\r\n') + with self.assertRaises(u1db.errors.BrokenSyncStream): + self.target._parse_received_doc_response('[\r\n{"error": "?"}\r\n') # # functions for TestRemoteSyncTargets # + def make_local_db_and_soledad_target(test, path='test'): test.startServer() db = test.request_state._create_database(os.path.basename(path)) |