From 527f2ff687faa120659cfefd82b8db26ddbfeafa Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 10 Apr 2017 18:51:45 -0700 Subject: [PATCH] Skip checksum validation on partial downloads If we get back some partial content, we can't validate the MD5. That's OK. Change-Id: Ic1d65272190af0d3d982f3cd06833cac5c791a1e Closes-Bug: 1642021 --- swiftclient/service.py | 1 + tests/unit/test_service.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/swiftclient/service.py b/swiftclient/service.py index c842d23..c5f815f 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -386,6 +386,7 @@ class _SwiftReader(object): # Some headers indicate the MD5 of the response # definitely *won't* match the ETag bad_md5_headers = set([ + 'content-range', 'x-object-manifest', 'x-static-large-object', ]) diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 0db5b7a..af32d84 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -141,6 +141,16 @@ class TestSwiftReader(unittest.TestCase): self.assertFalse(sr._expected_md5) self.assertIsNone(sr._actual_md5) + def test_create_with_content_range_header(self): + # md5 should not be initialized if large object headers are present + sr = self.sr('path', 'body', {'content-range': 'bytes 0-3/10', + 'etag': '"%s"' % ('0' * 32)}) + self.assertEqual(sr._path, 'path') + self.assertEqual(sr._body, 'body') + self.assertIsNone(sr._content_length) + self.assertFalse(sr._expected_md5) + self.assertIsNone(sr._actual_md5) + def test_create_with_ignore_checksum(self): # md5 should not be initialized if checksum is False sr = self.sr('path', 'body', {}, False)