Skip to content

Commit d7c3311

Browse files
authored
fix(toolbox-core): Expose authorization token requirements on ToolboxTool (#294)
* fix(toolbox-core): Expose authz token requirements from ToolboxTool This is used in a future PR where we inspect this protected value from the wrapper classes to implement self-authenticated tools. * chore: Fix unit tests * chore: Delint
1 parent a2d4ef1 commit d7c3311

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

packages/toolbox-core/src/toolbox_core/sync_tool.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ def _bound_params(
108108
return self.__async_tool._bound_params
109109

110110
@property
111-
def _required_auth_params(self) -> Mapping[str, list[str]]:
112-
return self.__async_tool._required_auth_params
111+
def _required_authn_params(self) -> Mapping[str, list[str]]:
112+
return self.__async_tool._required_authn_params
113+
114+
@property
115+
def _required_authz_tokens(self) -> Sequence[str]:
116+
return self.__async_tool._required_authz_tokens
113117

114118
@property
115119
def _auth_service_token_getters(

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ def _bound_params(
155155
return MappingProxyType(self.__bound_parameters)
156156

157157
@property
158-
def _required_auth_params(self) -> Mapping[str, list[str]]:
158+
def _required_authn_params(self) -> Mapping[str, list[str]]:
159159
return MappingProxyType(self.__required_authn_params)
160160

161+
@property
162+
def _required_authz_tokens(self) -> Sequence[str]:
163+
return tuple(self.__required_authz_tokens)
164+
161165
@property
162166
def _auth_service_token_getters(
163167
self,

packages/toolbox-core/tests/test_sync_tool.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,23 @@ def test_toolbox_sync_tool_underscore_bound_params_property(
155155
assert toolbox_sync_tool._bound_params == mock_async_tool._bound_params
156156

157157

158-
def test_toolbox_sync_tool_underscore_required_auth_params_property(
158+
def test_toolbox_sync_tool_underscore_required_authn_params_property(
159159
toolbox_sync_tool: ToolboxSyncTool, mock_async_tool: MagicMock
160160
):
161-
"""Tests the _required_auth_params property."""
161+
"""Tests the _required_authn_params property."""
162162
assert (
163-
toolbox_sync_tool._required_auth_params == mock_async_tool._required_auth_params
163+
toolbox_sync_tool._required_authn_params
164+
== mock_async_tool._required_authn_params
165+
)
166+
167+
168+
def test_toolbox_sync_tool_underscore_required_authz_tokens_property(
169+
toolbox_sync_tool: ToolboxSyncTool, mock_async_tool: MagicMock
170+
):
171+
"""Tests the _required_authz_tokens property."""
172+
assert (
173+
toolbox_sync_tool._required_authz_tokens
174+
== mock_async_tool._required_authz_tokens
164175
)
165176

166177

packages/toolbox-core/tests/test_tool.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,16 +575,28 @@ def test_toolbox_tool_underscore_bound_params_property(toolbox_tool: ToolboxTool
575575
bound_params["new_param"] = "new_value"
576576

577577

578-
def test_toolbox_tool_underscore_required_auth_params_property(
578+
def test_toolbox_tool_underscore_required_authn_params_property(
579579
toolbox_tool: ToolboxTool,
580580
):
581-
"""Tests the _required_auth_params property returns an immutable MappingProxyType."""
582-
required_auth_params = toolbox_tool._required_auth_params
583-
assert required_auth_params == {"message": ["service_a"]}
584-
assert isinstance(required_auth_params, MappingProxyType)
581+
"""Tests the _required_authn_params property returns an immutable MappingProxyType."""
582+
required_authn_params = toolbox_tool._required_authn_params
583+
assert required_authn_params == {"message": ["service_a"]}
584+
assert isinstance(required_authn_params, MappingProxyType)
585585
# Verify immutability
586586
with pytest.raises(TypeError):
587-
required_auth_params["new_param"] = ["new_service"]
587+
required_authn_params["new_param"] = ["new_service"]
588+
589+
590+
def test_toolbox_tool_underscore_required_authz_tokens_property(
591+
toolbox_tool: ToolboxTool,
592+
):
593+
"""Tests the _required_authz_tokens property returns an immutable MappingProxyType."""
594+
required_authz_tokens = toolbox_tool._required_authz_tokens
595+
assert required_authz_tokens == ("service_b",)
596+
assert isinstance(required_authz_tokens, tuple)
597+
# Verify immutability
598+
with pytest.raises(TypeError):
599+
required_authz_tokens[0] = "new_service"
588600

589601

590602
def test_toolbox_tool_underscore_auth_service_token_getters_property(

0 commit comments

Comments
 (0)