mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-10 02:38:26 +00:00
fix(channels): authenticate gateway command requests (#2742)
This commit is contained in:
parent
4ead2c6b19
commit
1336872b15
@ -997,7 +997,11 @@ class ChannelManager:
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient() as http:
|
||||
resp = await http.get(f"{self._gateway_url}{path}", timeout=10)
|
||||
resp = await http.get(
|
||||
f"{self._gateway_url}{path}",
|
||||
timeout=10,
|
||||
headers=create_internal_auth_headers(),
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
except Exception:
|
||||
|
||||
@ -466,6 +466,47 @@ class TestChannelManager:
|
||||
assert headers["Cookie"] == f"csrf_token={csrf_token}"
|
||||
assert headers["X-DeerFlow-Internal-Token"]
|
||||
|
||||
def test_fetch_gateway_includes_internal_auth_headers(self, monkeypatch):
|
||||
from app.channels.manager import ChannelManager
|
||||
|
||||
class MockResponse:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {"models": [{"name": "default"}]}
|
||||
|
||||
class MockAsyncClient:
|
||||
def __init__(self, *args, **kwargs):
|
||||
return None
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc, tb):
|
||||
return None
|
||||
|
||||
async def get(self, url, **kwargs):
|
||||
calls.append({"url": url, **kwargs})
|
||||
return MockResponse()
|
||||
|
||||
calls = []
|
||||
monkeypatch.setattr("app.channels.manager.httpx.AsyncClient", MockAsyncClient)
|
||||
|
||||
async def go():
|
||||
bus = MessageBus()
|
||||
store = ChannelStore(path=Path(tempfile.mkdtemp()) / "store.json")
|
||||
manager = ChannelManager(bus=bus, store=store, gateway_url="http://gateway:8001")
|
||||
|
||||
reply = await manager._fetch_gateway("/api/models", "models")
|
||||
|
||||
assert reply == "Available models:\n• default"
|
||||
assert calls[0]["url"] == "http://gateway:8001/api/models"
|
||||
assert calls[0]["timeout"] == 10
|
||||
assert calls[0]["headers"]["X-DeerFlow-Internal-Token"]
|
||||
|
||||
_run(go())
|
||||
|
||||
def test_handle_chat_calls_channel_receive_file_for_inbound_files(self, monkeypatch):
|
||||
from app.channels.manager import ChannelManager
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user