-
Notifications
You must be signed in to change notification settings - Fork 336
fix: normalize api key scheme in alias #646
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
Wondr-design
wants to merge
5
commits into
a2aproject:main
Choose a base branch
from
Wondr-design:fix/security-scheme-in-alias
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.
+82
−4
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fa39eb5
fix: normalize api key scheme in alias
Wondr-design 133be71
test: parametrize api key in field handling
Wondr-design 9cfb80b
test: rename rest serialization test
Wondr-design e1f78a8
fix: annotate telemetry __enter__ with Self
Wondr-design c2b0c98
fix: use typing_extensions Self for telemetry
Wondr-design 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from httpx import ASGITransport, AsyncClient | ||
|
|
||
| from a2a.server.apps.rest.fastapi_app import A2ARESTFastAPIApplication | ||
| from a2a.types import ( | ||
| APIKeySecurityScheme, | ||
| AgentCapabilities, | ||
| AgentCard, | ||
| In, | ||
| SecurityScheme, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def agent_card_with_api_key() -> AgentCard: | ||
| api_key_scheme_data = { | ||
| 'type': 'apiKey', | ||
| 'name': 'X-API-KEY', | ||
| 'in': 'header', | ||
| } | ||
| api_key_scheme = APIKeySecurityScheme.model_validate(api_key_scheme_data) | ||
|
|
||
| return AgentCard( | ||
| name='APIKeyAgent', | ||
| description='An agent that uses API Key auth.', | ||
| url='http://example.com/apikey-agent', | ||
| version='1.0.0', | ||
| capabilities=AgentCapabilities(), | ||
| default_input_modes=['text/plain'], | ||
| default_output_modes=['text/plain'], | ||
| skills=[], | ||
| security_schemes={'api_key_auth': SecurityScheme(root=api_key_scheme)}, | ||
| security=[{'api_key_auth': []}], | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_rest_agent_card_with_api_key_scheme_alias( | ||
| agent_card_with_api_key: AgentCard, | ||
| ): | ||
| """Ensures REST agent card serialization uses the 'in' alias.""" | ||
| handler = mock.AsyncMock() | ||
| app_instance = A2ARESTFastAPIApplication(agent_card_with_api_key, handler) | ||
| app = app_instance.build( | ||
| agent_card_url='/.well-known/agent.json', rpc_url='' | ||
| ) | ||
|
|
||
| async with AsyncClient( | ||
| transport=ASGITransport(app=app), base_url='http://test' | ||
| ) as client: | ||
| response = await client.get('/.well-known/agent.json') | ||
|
|
||
| assert response.status_code == 200 | ||
| response_data = response.json() | ||
|
|
||
| security_scheme_json = response_data['securitySchemes']['api_key_auth'] | ||
| assert 'in' in security_scheme_json | ||
| assert security_scheme_json['in'] == 'header' | ||
| assert 'in_' not in security_scheme_json | ||
|
|
||
| parsed_card = AgentCard.model_validate(response_data) | ||
| parsed_scheme_wrapper = parsed_card.security_schemes['api_key_auth'] | ||
| assert parsed_scheme_wrapper.root.in_ == In.header |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't be manually edited. The alias should be added automatically from
BaseModelin https://github.com/a2aproject/a2a-python/blob/main/src/a2a/_base.py