From be6e259dfcbb23533c8fcddd8a150a1be91a0ac5 Mon Sep 17 00:00:00 2001 From: Maxim Esipov Date: Tue, 19 May 2026 18:10:43 +0300 Subject: [PATCH] feat(gateway): accept rar and 7z document uploads --- gateway/platforms/base.py | 2 ++ tests/gateway/test_document_cache.py | 12 +++++++++- tests/gateway/test_telegram_documents.py | 28 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index d39601546886..e7d058a03778 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -1034,6 +1034,8 @@ def validate_media_delivery_path(path: str) -> Optional[str]: ".ini": "text/plain", ".cfg": "text/plain", ".zip": "application/zip", + ".rar": "application/vnd.rar", + ".7z": "application/x-7z-compressed", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", diff --git a/tests/gateway/test_document_cache.py b/tests/gateway/test_document_cache.py index cc756cea85f7..b0505d27239b 100644 --- a/tests/gateway/test_document_cache.py +++ b/tests/gateway/test_document_cache.py @@ -151,7 +151,17 @@ def test_all_extensions_have_mime_types(self): @pytest.mark.parametrize( "ext", - [".pdf", ".md", ".txt", ".zip", ".docx", ".xlsx", ".pptx"], + [ + ".pdf", + ".md", + ".txt", + ".zip", + ".rar", + ".7z", + ".docx", + ".xlsx", + ".pptx", + ], ) def test_expected_extensions_present(self, ext): assert ext in SUPPORTED_DOCUMENT_TYPES diff --git a/tests/gateway/test_telegram_documents.py b/tests/gateway/test_telegram_documents.py index 8b2e1943cc24..c96a6642ca28 100644 --- a/tests/gateway/test_telegram_documents.py +++ b/tests/gateway/test_telegram_documents.py @@ -262,6 +262,34 @@ async def test_zip_document_cached(self, adapter): assert event.media_urls and event.media_urls[0].endswith("archive.zip") assert event.media_types == ["application/zip"] + @pytest.mark.asyncio + @pytest.mark.parametrize( + ("filename", "mime_type", "expected_mime"), + [ + ("assets.rar", "application/vnd.rar", "application/vnd.rar"), + ("assets.7z", "application/x-7z-compressed", "application/x-7z-compressed"), + ], + ) + async def test_archive_document_cached(self, adapter, filename, mime_type, expected_mime): + """RAR/7z uploads should be cached like zip archives for CLI inspection.""" + archive_bytes = b"archive-bytes" + file_obj = _make_file_obj(archive_bytes) + doc = _make_document( + file_name=filename, + mime_type=mime_type, + file_size=len(archive_bytes), + file_obj=file_obj, + ) + msg = _make_message(document=doc) + update = _make_update(msg) + + await adapter._handle_media_message(update, MagicMock()) + event = adapter.handle_message.call_args[0][0] + assert event.media_urls and event.media_urls[0].endswith(filename) + assert os.path.exists(event.media_urls[0]) + assert event.media_types == [expected_mime] + assert event.text == "" + @pytest.mark.asyncio async def test_png_document_is_routed_as_image(self, adapter): """Telegram documents that are really PNGs should use the image path."""