dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00581
[PATCH 20/33] test_pack: Test checksum and length mismatch conditions.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I5c58fcc1ba7910d7eba7d746f92128aca5feb044
---
dulwich/tests/test_pack.py | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/dulwich/tests/test_pack.py b/dulwich/tests/test_pack.py
index f364031..dcaffff 100644
--- a/dulwich/tests/test_pack.py
+++ b/dulwich/tests/test_pack.py
@@ -378,6 +378,31 @@ class TestPack(PackTests):
p = self.get_pack(pack1_sha)
self.assertEquals(pack1_sha, p.name())
+ def test_length_mismatch(self):
+ data = self.get_pack_data(pack1_sha)
+ index = self.get_pack_index(pack1_sha)
+ self.assertTrue(Pack.from_objects(data, index).data)
+
+ data._file.seek(12)
+ bad_file = StringIO()
+ write_pack_header(bad_file, 9999)
+ bad_file.write(data._file.read())
+ bad_file = StringIO(bad_file.getvalue())
+ bad_data = PackData('', file=bad_file)
+ bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index)
+ self.assertRaises(AssertionError, lambda: bad_pack.data)
+
+ def test_checksum_mismatch(self):
+ data = self.get_pack_data(pack1_sha)
+ index = self.get_pack_index(pack1_sha)
+ self.assertTrue(Pack.from_objects(data, index).data)
+
+ data._file.seek(0)
+ bad_file = StringIO(data._file.read()[:-20] + ('\xff' * 20))
+ bad_data = PackData('', file=bad_file)
+ bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index)
+ self.assertRaises(ChecksumMismatch, lambda: bad_pack.data)
+
class WritePackTests(TestCase):
--
1.7.3.1
References