* refactor(channels): own setup and instance contracts * refactor(channels): isolate management contracts * refactor(channels): normalize activation contracts * fix(channels): enforce management contracts * refactor(channels): finish setup ownership migration * fix(channels): harden management contracts * fix(channels): enforce lazy loading and runtime ownership * fix(feishu): make multi-instance startup idempotent * fix(webui): render channel setup contracts cleanly * fix(feishu): stop websocket clients cleanly * fix(channels): enforce persistence and activation gates * fix(channels): preserve global feature action scope * fix(channels): apply defaults for single plugins * fix(channels): enforce management contract boundaries * refactor(feishu): remove identity helper indirection * fix(channels): preserve management setup contracts * refactor(channels): generalize instance settings UI * refactor(channels): package channel plugins with web UI metadata * refactor(channels): make built-ins self-contained packages * test(channels): colocate tests with channel packages * fix(dingtalk): use official brand icon * feat(channels): colocate webui translations * docs(channels): clarify plugin ownership * test(exec): remove output wait race * refactor(channels): unify plugin descriptors * fix(channels): enforce descriptor-owned contracts * refactor(channels): finish package-owned plugin setup * refactor(channels): use repository-owned packages only * fix(channels): self-describe dependencies and runtime state * fix(channels): warn about legacy entry points
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from nanobot.channels.feishu import runtime as feishu_module
|
|
from nanobot.channels.feishu.runtime import FeishuChannel
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_feishu_downloaded_media_filename_cannot_escape_media_dir(monkeypatch, tmp_path):
|
|
media_dir = tmp_path / "media"
|
|
media_dir.mkdir()
|
|
outside = tmp_path / "escaped.txt"
|
|
|
|
monkeypatch.setattr(feishu_module, "get_media_dir", lambda _channel: media_dir)
|
|
|
|
channel = FeishuChannel.__new__(FeishuChannel)
|
|
channel.logger = SimpleNamespace(
|
|
debug=lambda *args, **kwargs: None,
|
|
warning=lambda *args, **kwargs: None,
|
|
)
|
|
|
|
def fake_download(_message_id, _file_key, _resource_type):
|
|
return b"owned", "../escaped.txt"
|
|
|
|
channel._download_file_sync = fake_download
|
|
|
|
path_str, content = await channel._download_and_save_media(
|
|
"file", {"file_key": "fk_123"}, "msg_123"
|
|
)
|
|
|
|
saved_path = Path(path_str)
|
|
assert not outside.exists()
|
|
assert saved_path.parent == media_dir
|
|
assert saved_path.name == "escaped.txt"
|
|
assert saved_path.read_bytes() == b"owned"
|
|
assert content == f"[file: {saved_path}]"
|