fix(upload): validate public image payloads
This commit is contained in:
1 parent
5d6e5987d1
commit
240f1f9903
6 files changed
+68
-10
No files matched your search
@@ -2,9 +2,19 @@ import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from app.belki.image_host import ImageHostClient, ImageHostError
|
||||
from app.main import MAX_JSON_BODY_BYTES, detect_raster_image_type, safe_upload_name
|
||||
|
||||
|
||||
class ImageHostClientTests(unittest.TestCase):
|
||||
def test_upload_input_helpers_accept_only_supported_raster_signatures(self) -> None:
|
||||
self.assertEqual(detect_raster_image_type(b"\x89PNG\r\n\x1a\ncontent"), "image/png")
|
||||
self.assertEqual(detect_raster_image_type(b"\xff\xd8\xffcontent"), "image/jpeg")
|
||||
self.assertEqual(detect_raster_image_type(b"RIFF\x00\x00\x00\x00WEBPcontent"), "image/webp")
|
||||
self.assertIsNone(detect_raster_image_type(b"<svg xmlns='http://www.w3.org/2000/svg'>"))
|
||||
self.assertEqual(safe_upload_name("../../report.png", "image/png"), "report.png")
|
||||
self.assertEqual(safe_upload_name("", "image/webp"), "screenshot.webp")
|
||||
self.assertEqual(MAX_JSON_BODY_BYTES, 20 * 1024 * 1024)
|
||||
|
||||
def test_default_client_targets_belki_image_host(self) -> None:
|
||||
with patch.dict("os.environ", {}, clear=True):
|
||||
self.assertEqual(ImageHostClient().api_url, "https://nyan.nyan404.ru")
|
||||
|
||||
Reference in new issue
Block a user