forked from mtusi2026/mtusi2026lab5
Исправить проверку целостности PNG
This commit is contained in:
@@ -135,6 +135,16 @@ class AttachmentsTest(unittest.TestCase):
|
||||
original = self.c.call('GET', '/api/v1/attachments/' + a['id'] + '/content', actor=self.a)
|
||||
self.assertEqual(original['bytes'], source)
|
||||
|
||||
def test_png_requires_complete_iend_and_valid_crc(self):
|
||||
png = small_png()
|
||||
for missing in range(1, 13):
|
||||
with self.subTest(missing_final_bytes=missing):
|
||||
self.upload(raw=png[:-missing], status=415)
|
||||
with self.subTest(corrupt_iend_crc=True):
|
||||
self.upload(raw=png[:-1] + bytes([png[-1] ^ 1]), status=415)
|
||||
# A rejected upload must not prevent subsequent valid processing.
|
||||
self.ready(self.upload(raw=png)['json'])
|
||||
|
||||
def test_corrupt_and_wrong_mime(self):
|
||||
for raw, mime in ((b'not an image', 'image/png'), (self.png[:40], 'image/png'),
|
||||
(self.png, 'image/jpeg'), (self.png, 'text/plain'), (b'', 'image/png')):
|
||||
|
||||
Reference in New Issue
Block a user