Files
langgraph/libs/sdk-py/tests/test_auth.py
John Kennedyandopen-swe[bot] <open-swe@users.noreply.github.com> e837585311 fix: honor resource auth actions
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-07-09 03:21:57 +00:00

45 lines
1.0 KiB
Python

import pytest
from langgraph_sdk import Auth
def _handler():
async def handler(ctx, value):
return ctx is not None and value is not None
return handler
def test_resource_decorator_registers_specific_actions():
auth = Auth()
handler = auth.on.threads(actions=["read", "search"])(_handler())
assert auth._handlers == {
("threads", "read"): [handler],
("threads", "search"): [handler],
}
def test_resource_decorator_registers_single_action():
auth = Auth()
handler = auth.on.threads(actions="read")(_handler())
assert auth._handlers == {("threads", "read"): [handler]}
def test_resource_decorator_without_actions_registers_resource_wildcard():
auth = Auth()
handler = auth.on.threads(_handler())
assert auth._handlers == {("threads", "*"): [handler]}
def test_resource_decorator_rejects_mismatched_resources():
auth = Auth()
with pytest.raises(ValueError, match=r"Use @auth\.on"):
auth.on.threads(resources="assistants", actions="read")(_handler())