Skip to content

fix(toolbox-core)!: Throw PermissionError on unauthenticated tool invocation #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolbox-core/src/toolbox_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
for s in self.__required_authn_params.values():
req_auth_services.update(s)
req_auth_services.update(self.__required_authz_tokens)
raise ValueError(
raise PermissionError(
f"One or more of the following authn services are required to invoke this tool"
f": {','.join(req_auth_services)}"
)
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-core/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def test_run_tool_no_auth(self, toolbox: ToolboxClient):
"""Tests running a tool requiring auth without providing auth."""
tool = await toolbox.load_tool("get-row-by-id-auth")
with pytest.raises(
Exception,
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
await tool(id="2")
Expand Down Expand Up @@ -188,7 +188,7 @@ async def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxClient):
"""Tests running a tool with a param requiring auth, without auth."""
tool = await toolbox.load_tool("get-row-by-email-auth")
with pytest.raises(
ValueError,
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
await tool()
Expand Down
2 changes: 1 addition & 1 deletion packages/toolbox-core/tests/test_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def test_auth_with_load_tool_fail_no_token(

tool = sync_client.load_tool(tool_name_auth)
with pytest.raises(
ValueError,
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-auth-service",
):
tool(argA=15, argB=True)
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-core/tests/test_sync_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_run_tool_no_auth(self, toolbox: ToolboxSyncClient):
"""Tests running a tool requiring auth without providing auth."""
tool = toolbox.load_tool("get-row-by-id-auth")
with pytest.raises(
Exception,
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
tool(id="2")
Expand All @@ -156,7 +156,7 @@ def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxSyncClient):
"""Tests running a tool with a param requiring auth, without auth."""
tool = toolbox.load_tool("get-row-by-email-auth")
with pytest.raises(
ValueError,
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
tool()
Expand Down