-
Notifications
You must be signed in to change notification settings - Fork 46
feat(authz): support 'unscoped' wildcard sentinel in /v1/authz/search #303
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
Open
smoreinis
wants to merge
4
commits into
main
Choose a base branch
from
feat/authz-search-wildcard-sentinel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9656c7
feat(authz): map search 'unscoped' sentinel to no-filter path
smoreinis e323efe
docs(authz): formalize search 'unscoped' wildcard sentinel
smoreinis bd53109
fix(authz): require boolean unscoped sentinel
smoreinis 8dc47ed
test(authz): address greptile review findings
smoreinis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
94 changes: 94 additions & 0 deletions
94
agentex/tests/unit/adapters/authorization/test_adapter_agentex_authz_proxy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """Unit tests for AgentexAuthorizationProxy.list_resources sentinel handling. | ||
|
|
||
| The proxy maps a provider's wildcard sentinel ({"unscoped": true}) onto the | ||
| existing unscoped path (None == no id filter), while ordinary {"items": [...]} | ||
| responses pass through as an inclusion filter. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import AsyncMock, patch | ||
|
|
||
| import pytest | ||
| from src.adapters.authorization.adapter_agentex_authz_proxy import ( | ||
| AgentexAuthorizationProxy, | ||
| ) | ||
| from src.api.schemas.authorization_types import ( | ||
| AgentexResourceType, | ||
| AuthorizedOperationType, | ||
| ) | ||
|
|
||
| PROXY_TARGET = ( | ||
| "src.adapters.authorization.adapter_agentex_authz_proxy." | ||
| "HttpRequestHandler.post_with_error_handling" | ||
| ) | ||
|
|
||
|
|
||
| def _proxy() -> AgentexAuthorizationProxy: | ||
| return AgentexAuthorizationProxy(agentex_auth_url="http://auth.test") | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| @pytest.mark.asyncio | ||
| class TestListResourcesSentinel: | ||
| async def test_items_list_passes_through(self): | ||
| with patch(PROXY_TARGET, new=AsyncMock(return_value={"items": ["a", "b"]})): | ||
| result = await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| filter_operation=AuthorizedOperationType.read, | ||
| ) | ||
| assert result == ["a", "b"] | ||
|
|
||
| async def test_unscoped_true_returns_none(self): | ||
| with patch(PROXY_TARGET, new=AsyncMock(return_value={"unscoped": True})): | ||
| result = await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| ) | ||
| assert result is None | ||
|
|
||
| async def test_unscoped_wins_over_items(self): | ||
| with patch( | ||
| PROXY_TARGET, | ||
| new=AsyncMock(return_value={"unscoped": True, "items": ["x"]}), | ||
| ): | ||
| result = await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| ) | ||
| assert result is None | ||
|
|
||
| async def test_empty_items_is_not_a_sentinel(self): | ||
| with patch(PROXY_TARGET, new=AsyncMock(return_value={"items": []})): | ||
| result = await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| ) | ||
| assert result == [] | ||
|
|
||
| async def test_truthy_non_boolean_unscoped_is_not_a_sentinel(self): | ||
| # 1 is truthy but `1 is True` is False, so the strict identity check must | ||
| # not treat it as the sentinel; only the JSON boolean `true` qualifies. | ||
| with patch( | ||
| PROXY_TARGET, | ||
| new=AsyncMock(return_value={"unscoped": 1, "items": []}), | ||
| ): | ||
| result = await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| ) | ||
| assert result == [] | ||
|
|
||
| async def test_missing_unscoped_and_items_fails_closed(self): | ||
| # A malformed response with neither field must raise rather than silently | ||
| # return [] or None — the guard against a provider accidentally failing open. | ||
| with patch( | ||
| PROXY_TARGET, | ||
| new=AsyncMock(return_value={"unexpected_key": "val"}), | ||
| ): | ||
| with pytest.raises(KeyError): | ||
| await _proxy().list_resources( | ||
| principal={"user_id": "u"}, | ||
| filter_resource=AgentexResourceType.task, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.