Add media tests for a CMYK JPEG image (#17786)
This commit is contained in:
parent
a5e16a4ab5
commit
57efc8c03e
|
@ -0,0 +1 @@
|
|||
Add a test for downloading and thumbnailing a CMYK JPEG.
|
|
@ -60,7 +60,7 @@ from synapse.util import Clock
|
|||
|
||||
from tests import unittest
|
||||
from tests.server import FakeChannel
|
||||
from tests.test_utils import SMALL_PNG
|
||||
from tests.test_utils import SMALL_CMYK_JPEG, SMALL_PNG
|
||||
from tests.unittest import override_config
|
||||
from tests.utils import default_config
|
||||
|
||||
|
@ -187,6 +187,68 @@ small_png_with_transparency = TestImage(
|
|||
# different versions of Pillow.
|
||||
)
|
||||
|
||||
small_cmyk_jpeg = TestImage(
|
||||
SMALL_CMYK_JPEG,
|
||||
b"image/jpeg",
|
||||
b".jpeg",
|
||||
# These values were sourced simply by seeing at what the tests produced at
|
||||
# the time of writing. If this changes, the tests will fail.
|
||||
unhexlify(
|
||||
b"ffd8ffe000104a46494600010100000100010000ffdb00430006"
|
||||
b"040506050406060506070706080a100a0a09090a140e0f0c1017"
|
||||
b"141818171416161a1d251f1a1b231c1616202c20232627292a29"
|
||||
b"191f2d302d283025282928ffdb0043010707070a080a130a0a13"
|
||||
b"281a161a28282828282828282828282828282828282828282828"
|
||||
b"2828282828282828282828282828282828282828282828282828"
|
||||
b"2828ffc00011080020002003012200021101031101ffc4001f00"
|
||||
b"0001050101010101010000000000000000010203040506070809"
|
||||
b"0a0bffc400b5100002010303020403050504040000017d010203"
|
||||
b"00041105122131410613516107227114328191a1082342b1c115"
|
||||
b"52d1f02433627282090a161718191a25262728292a3435363738"
|
||||
b"393a434445464748494a535455565758595a636465666768696a"
|
||||
b"737475767778797a838485868788898a92939495969798999aa2"
|
||||
b"a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9ca"
|
||||
b"d2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7"
|
||||
b"f8f9faffc4001f01000301010101010101010100000000000001"
|
||||
b"02030405060708090a0bffc400b5110002010204040304070504"
|
||||
b"0400010277000102031104052131061241510761711322328108"
|
||||
b"144291a1b1c109233352f0156272d10a162434e125f11718191a"
|
||||
b"262728292a35363738393a434445464748494a53545556575859"
|
||||
b"5a636465666768696a737475767778797a82838485868788898a"
|
||||
b"92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9"
|
||||
b"bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8"
|
||||
b"e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00fa"
|
||||
b"a68a28a0028a28a0028a28a0028a28a00fffd9"
|
||||
),
|
||||
unhexlify(
|
||||
b"ffd8ffe000104a46494600010100000100010000ffdb00430006"
|
||||
b"040506050406060506070706080a100a0a09090a140e0f0c1017"
|
||||
b"141818171416161a1d251f1a1b231c1616202c20232627292a29"
|
||||
b"191f2d302d283025282928ffdb0043010707070a080a130a0a13"
|
||||
b"281a161a28282828282828282828282828282828282828282828"
|
||||
b"2828282828282828282828282828282828282828282828282828"
|
||||
b"2828ffc00011080001000103012200021101031101ffc4001f00"
|
||||
b"0001050101010101010000000000000000010203040506070809"
|
||||
b"0a0bffc400b5100002010303020403050504040000017d010203"
|
||||
b"00041105122131410613516107227114328191a1082342b1c115"
|
||||
b"52d1f02433627282090a161718191a25262728292a3435363738"
|
||||
b"393a434445464748494a535455565758595a636465666768696a"
|
||||
b"737475767778797a838485868788898a92939495969798999aa2"
|
||||
b"a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9ca"
|
||||
b"d2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7"
|
||||
b"f8f9faffc4001f01000301010101010101010100000000000001"
|
||||
b"02030405060708090a0bffc400b5110002010204040304070504"
|
||||
b"0400010277000102031104052131061241510761711322328108"
|
||||
b"144291a1b1c109233352f0156272d10a162434e125f11718191a"
|
||||
b"262728292a35363738393a434445464748494a53545556575859"
|
||||
b"5a636465666768696a737475767778797a82838485868788898a"
|
||||
b"92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9"
|
||||
b"bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8"
|
||||
b"e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00fa"
|
||||
b"a68a28a00fffd9"
|
||||
),
|
||||
)
|
||||
|
||||
small_lossless_webp = TestImage(
|
||||
unhexlify(
|
||||
b"524946461a000000574542505650384c0d0000002f0000001007" b"1011118888fe0700"
|
||||
|
|
|
@ -66,6 +66,7 @@ from tests.media.test_media_storage import (
|
|||
SVG,
|
||||
TestImage,
|
||||
empty_file,
|
||||
small_cmyk_jpeg,
|
||||
small_lossless_webp,
|
||||
small_png,
|
||||
small_png_with_transparency,
|
||||
|
@ -1916,6 +1917,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase):
|
|||
test_images = [
|
||||
small_png,
|
||||
small_png_with_transparency,
|
||||
small_cmyk_jpeg,
|
||||
small_lossless_webp,
|
||||
empty_file,
|
||||
SVG,
|
||||
|
@ -2400,7 +2402,7 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
if expected_body is not None:
|
||||
self.assertEqual(
|
||||
channel.result["body"], expected_body, channel.result["body"]
|
||||
channel.result["body"], expected_body, channel.result["body"].hex()
|
||||
)
|
||||
else:
|
||||
# ensure that the result is at least some valid image
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
Utilities for running the unit tests
|
||||
"""
|
||||
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
import warnings
|
||||
|
@ -138,3 +139,21 @@ SMALL_PNG = unhexlify(
|
|||
b"0000001f15c4890000000a49444154789c63000100000500010d"
|
||||
b"0a2db40000000049454e44ae426082"
|
||||
)
|
||||
|
||||
# A small CMYK-encoded JPEG image used in some tests.
|
||||
#
|
||||
# Generated with:
|
||||
# img = PIL.Image.new('CMYK', (1, 1), (0, 0, 0, 0))
|
||||
# img.save('minimal_cmyk.jpg', 'JPEG')
|
||||
#
|
||||
# Resolution: 1x1, MIME type: image/jpeg, Extension: jpeg, Size: 4 KiB
|
||||
SMALL_CMYK_JPEG = base64.b64decode("""
|
||||
/9j/7gAOQWRvYmUAZAAAAAAA/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCww
|
||||
ZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/8
|
||||
AAFAgAAQABBEMRAE0RAFkRAEsRAP/EAB8AAAEFAQEBAQEBAAAAAAAAAAABA
|
||||
gMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNR
|
||||
YQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkN
|
||||
ERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlp
|
||||
eYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5
|
||||
ebn6Onq8fLz9PX29/j5+v/aAA4EQwBNAFkASwAAPwD3+vf69/r3+v/Z
|
||||
""")
|
||||
|
|
Loading…
Reference in New Issue