summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2023-03-10 09:22:34 -0800
committerTim Burke <tim.burke@gmail.com>2023-03-14 11:56:03 -0700
commit6adb8bb17fe55a33d3605944653ca956eabc9ece (patch)
treea9063c9b4ee681201cd1d7b421f59298ca6560a9 /test
parent0f2b567953c9cdcd566eff30d15aefa717ee47db (diff)
downloadpython-swiftclient-6adb8bb17fe55a33d3605944653ca956eabc9ece.tar.gz
service: Check content-length before etag
If the received content-length does not match expectations, of course the etag won't match! Co-Authored-By: Alistair Coles <alistairncoles@gmail.com> Change-Id: I1a0c066c11b94718fffbb11e13b82d0b16e01626
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_service.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/test/unit/test_service.py b/test/unit/test_service.py
index 1176a1f..b6db22d 100644
--- a/test/unit/test_service.py
+++ b/test/unit/test_service.py
@@ -196,8 +196,24 @@ class TestSwiftReader(unittest.TestCase):
# Check error is raised if SwiftReader doesn't read the same length
# as the content length it is created with
- sr = self.sr('path', BytesIO(b'body'), {'content-length': 5})
- self.assertRaises(SwiftError, _consume, sr)
+ sr = self.sr('path', BytesIO(b'body'), {'content-length': 5,
+ 'etag': 'bad etag'})
+ with self.assertRaises(SwiftError) as cm:
+ _consume(sr)
+ self.assertEqual(
+ "'Error downloading path: read_length != content_length, 4 != 5'",
+ str(cm.exception))
+
+ # Check error is raised if SwiftReader doesn't calculate the expected
+ # hash
+ sr = self.sr('path', BytesIO(b'body'), {'content-length': 4,
+ 'etag': 'bad etag'})
+ with self.assertRaises(SwiftError) as cm:
+ _consume(sr)
+ self.assertEqual(
+ "'Error downloading path: md5sum != etag, "
+ "841a2d689ad86bd1611447453c22c6fc != bad etag'",
+ str(cm.exception))
sr = self.sr('path', BytesIO(b'body'), {'content-length': 4})
_consume(sr)