From 2eaf098c5db9738a9f766dbdf14eb4bbf120ceb6 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 20 Jun 2024 16:19:25 +0000 Subject: [PATCH] upload: Content-type is always defined. --- zerver/lib/upload/__init__.py | 2 +- zerver/lib/upload/base.py | 2 +- zerver/lib/upload/local.py | 2 +- zerver/lib/upload/s3.py | 2 +- zerver/tests/test_upload_s3.py | 12 ------------ 5 files changed, 4 insertions(+), 16 deletions(-) diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py index 70d8ea08c3..35e3d7a117 100644 --- a/zerver/lib/upload/__init__.py +++ b/zerver/lib/upload/__init__.py @@ -119,7 +119,7 @@ def sanitize_name(value: str) -> str: def upload_message_attachment( uploaded_file_name: str, uploaded_file_size: int, - content_type: Optional[str], + content_type: str, file_data: bytes, user_profile: UserProfile, target_realm: Optional[Realm] = None, diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py index ad7007c924..b679e9cb8f 100644 --- a/zerver/lib/upload/base.py +++ b/zerver/lib/upload/base.py @@ -38,7 +38,7 @@ class ZulipUploadBackend: self, path_id: str, uploaded_file_size: int, - content_type: Optional[str], + content_type: str, file_data: bytes, user_profile: UserProfile, target_realm: Realm, diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py index 673ae6c38e..10c3ed2ed1 100644 --- a/zerver/lib/upload/local.py +++ b/zerver/lib/upload/local.py @@ -81,7 +81,7 @@ class LocalUploadBackend(ZulipUploadBackend): self, path_id: str, uploaded_file_size: int, - content_type: Optional[str], + content_type: str, file_data: bytes, user_profile: UserProfile, target_realm: Realm, diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py index d242398069..80f90b00b7 100644 --- a/zerver/lib/upload/s3.py +++ b/zerver/lib/upload/s3.py @@ -205,7 +205,7 @@ class S3UploadBackend(ZulipUploadBackend): self, path_id: str, uploaded_file_size: int, - content_type: Optional[str], + content_type: str, file_data: bytes, user_profile: UserProfile, target_realm: Realm, diff --git a/zerver/tests/test_upload_s3.py b/zerver/tests/test_upload_s3.py index 309958acea..186c57dc08 100644 --- a/zerver/tests/test_upload_s3.py +++ b/zerver/tests/test_upload_s3.py @@ -95,18 +95,6 @@ class S3Test(ZulipTestCase): # Ensure the correct realm id of the target realm is used instead of the bot's realm. self.assertTrue(url.startswith(f"/user_uploads/{zulip_realm.id}/")) - @use_s3_backend - def test_upload_message_attachment_s3_with_undefined_content_type(self) -> None: - bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0] - - user_profile = self.example_user("hamlet") - url = upload_message_attachment("dummy.txt", len(b"zulip!"), None, b"zulip!", user_profile) - - path_id = re.sub(r"/user_uploads/", "", url) - self.assertEqual(b"zulip!", bucket.Object(path_id).get()["Body"].read()) - uploaded_file = Attachment.objects.get(owner=user_profile, path_id=path_id) - self.assert_length(b"zulip!", uploaded_file.size) - @use_s3_backend def test_delete_message_attachment(self) -> None: bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]