tmux-amq/tests/test_endpoint_authorization.py

26 lines
1.1 KiB
Python
Raw Normal View History

import asyncio
import json
from tamq.service import Service
from tamq.store import Store
from tamq import service
def test_send_rejects_endpoint_target_not_attached(tmp_path, monkeypatch):
monkeypatch.setattr(service, "validate_targets", lambda repos: None)
async def run():
path = tmp_path / "tamq.sock"
store = Store(tmp_path / "queue.sqlite3")
store.register_endpoint("ep", 1, "tamq", ["source"])
instance = Service(path, store)
server = await asyncio.start_unix_server(instance.handle, path=str(path))
try:
reader, writer = await asyncio.open_unix_connection(str(path))
payload = {"op":"send","endpoint_id":"ep","sender_repo":"source","target_repo":"other","body":"hello"}
writer.write((json.dumps(payload) + "\n").encode()); await writer.drain()
assert json.loads(await reader.readline())["ok"] is False
writer.close(); await writer.wait_closed()
finally:
server.close(); await server.wait_closed(); instance.close()
asyncio.run(run())