|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
| 14 | + |
| 15 | + |
14 | 16 | import inspect
|
15 |
| -from typing import AsyncGenerator, Callable |
| 17 | +from typing import AsyncGenerator, Callable, Mapping |
16 | 18 | from unittest.mock import AsyncMock, Mock
|
17 | 19 |
|
18 | 20 | import pytest
|
@@ -92,6 +94,12 @@ def auth_header_key() -> str:
|
92 | 94 | return "test-auth_token"
|
93 | 95 |
|
94 | 96 |
|
| 97 | +@pytest.fixture |
| 98 | +def unused_auth_getters() -> dict[str, Callable[[], str]]: |
| 99 | + """Provides an auth getter for a service not required by sample_tool.""" |
| 100 | + return {"unused-auth-service": lambda: "unused-token-value"} |
| 101 | + |
| 102 | + |
95 | 103 | def test_create_func_docstring_one_param_real_schema():
|
96 | 104 | """
|
97 | 105 | Tests create_func_docstring with one real ParameterSchema instance.
|
@@ -432,3 +440,32 @@ def test_tool_add_auth_token_getters_conflict_with_existing_client_header(
|
432 | 440 |
|
433 | 441 | with pytest.raises(ValueError, match=expected_error_message):
|
434 | 442 | tool_instance.add_auth_token_getters(new_auth_getters_causing_conflict)
|
| 443 | + |
| 444 | + |
| 445 | +def test_add_auth_token_getters_unused_token( |
| 446 | + http_session: ClientSession, |
| 447 | + sample_tool_params: list[ParameterSchema], |
| 448 | + sample_tool_description: str, |
| 449 | + unused_auth_getters: Mapping[str, Callable[[], str]], |
| 450 | +): |
| 451 | + """ |
| 452 | + Tests ValueError when add_auth_token_getters is called with a getter for |
| 453 | + an unused authentication service. |
| 454 | + """ |
| 455 | + tool_instance = ToolboxTool( |
| 456 | + session=http_session, |
| 457 | + base_url=TEST_BASE_URL, |
| 458 | + name=TEST_TOOL_NAME, |
| 459 | + description=sample_tool_description, |
| 460 | + params=sample_tool_params, |
| 461 | + required_authn_params={}, |
| 462 | + required_authz_tokens=[], |
| 463 | + auth_service_token_getters={}, |
| 464 | + bound_params={}, |
| 465 | + client_headers={}, |
| 466 | + ) |
| 467 | + |
| 468 | + expected_error_message = "Authentication source\(s\) \`unused-auth-service\` unused by tool \`sample_tool\`." |
| 469 | + |
| 470 | + with pytest.raises(ValueError, match=expected_error_message): |
| 471 | + tool_instance.add_auth_token_getters(unused_auth_getters) |
0 commit comments