Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gateway/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion tests/gateway/test_document_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions tests/gateway/test_telegram_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading