mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-30 14:56:01 +00:00
Keep dict-backed channel configs compatible with both allow_from and allowFrom without losing empty-list semantics, and add focused regression coverage for the allow-list boundary. Made-with: Cursor
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
from types import SimpleNamespace
|
|
|
|
from nanobot.bus.events import OutboundMessage
|
|
from nanobot.bus.queue import MessageBus
|
|
from nanobot.channels.base import BaseChannel
|
|
|
|
|
|
class _DummyChannel(BaseChannel):
|
|
name = "dummy"
|
|
|
|
async def start(self) -> None:
|
|
return None
|
|
|
|
async def stop(self) -> None:
|
|
return None
|
|
|
|
async def send(self, msg: OutboundMessage) -> None:
|
|
return None
|
|
|
|
|
|
def test_is_allowed_requires_exact_match() -> None:
|
|
channel = _DummyChannel(SimpleNamespace(allow_from=["allow@email.com"]), MessageBus())
|
|
|
|
assert channel.is_allowed("allow@email.com") is True
|
|
assert channel.is_allowed("attacker|allow@email.com") is False
|
|
|
|
|
|
def test_is_allowed_supports_dict_allow_from_alias() -> None:
|
|
channel = _DummyChannel({"allowFrom": ["alice"]}, MessageBus())
|
|
|
|
assert channel.is_allowed("alice") is True
|
|
|
|
|
|
def test_is_allowed_denies_empty_dict_allow_from() -> None:
|
|
channel = _DummyChannel({"allow_from": []}, MessageBus())
|
|
|
|
assert channel.is_allowed("alice") is False
|