Skip to content

Commit

Permalink
feat(core): allow general access to rest endpoints, except inspector …
Browse files Browse the repository at this point in the history
…ones (#612)
  • Loading branch information
Dacksus authored Jan 22, 2025
1 parent 379809f commit 3b7969e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/src/uagents/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ async def __call__(self, scope, receive, send): # pylint: disable=too-many-bra
# check if the request is for a REST endpoint
handlers = self._get_rest_handler_details(request_method, request_path)
if handlers:
if "127.0.0.1" not in scope["client"]:
if (
request_path in RESERVED_ENDPOINTS
and "127.0.0.1" not in scope["client"]
):
await self._asgi_send(send, 403, body={"error": "forbidden"})
return
await self._handle_rest(headers, handlers, send, receive)
Expand Down
8 changes: 2 additions & 6 deletions python/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,15 @@ async def _(_ctx: Context):


@pytest.mark.order(6)
async def test_rest_wrong_client():
@agent.on_rest_get("/get-wrong-client", Response)
async def _(_ctx: Context):
return Response(text="Hi there!")

async def test_inspector_rest_wrong_client():
mock_send = AsyncMock()
with patch("uagents.asgi._read_asgi_body") as mock_receive:
mock_receive.return_value = b""
await agent._server(
scope={
"type": "http",
"method": "GET",
"path": "/get-wrong-client",
"path": "/agent_info",
"client": ("agentverse.ai",),
},
receive=None,
Expand Down

0 comments on commit 3b7969e

Please sign in to comment.