|
7 | 7 | from a2a.types import ( |
8 | 8 | A2AError, |
9 | 9 | A2ARequest, |
10 | | - AgentAuthentication, |
| 10 | + APIKeySecurityScheme, |
11 | 11 | AgentCapabilities, |
12 | 12 | AgentCard, |
13 | 13 | AgentProvider, |
14 | 14 | AgentSkill, |
15 | 15 | Artifact, |
16 | 16 | CancelTaskRequest, |
17 | 17 | CancelTaskResponse, |
| 18 | + CancelTaskSuccessResponse, |
18 | 19 | ContentTypeNotSupportedError, |
19 | 20 | DataPart, |
20 | 21 | FileBase, |
|
23 | 24 | FileWithUri, |
24 | 25 | GetTaskPushNotificationConfigRequest, |
25 | 26 | GetTaskPushNotificationConfigResponse, |
| 27 | + GetTaskPushNotificationConfigSuccessResponse, |
26 | 28 | GetTaskRequest, |
27 | 29 | GetTaskResponse, |
| 30 | + GetTaskSuccessResponse, |
| 31 | + In, |
28 | 32 | InternalError, |
29 | 33 | InvalidParamsError, |
30 | 34 | InvalidRequestError, |
|
35 | 39 | JSONRPCRequest, |
36 | 40 | JSONRPCResponse, |
37 | 41 | Message, |
| 42 | + MessageSendParams, |
38 | 43 | MethodNotFoundError, |
| 44 | + OAuth2SecurityScheme, |
39 | 45 | Part, |
40 | 46 | PartBase, |
41 | 47 | PushNotificationAuthenticationInfo, |
42 | 48 | PushNotificationConfig, |
43 | 49 | PushNotificationNotSupportedError, |
| 50 | + Role, |
| 51 | + SecurityScheme, |
44 | 52 | SendMessageRequest, |
45 | 53 | SendMessageResponse, |
| 54 | + SendMessageSuccessResponse, |
46 | 55 | SendStreamingMessageRequest, |
47 | 56 | SendStreamingMessageResponse, |
| 57 | + SendStreamingMessageSuccessResponse, |
48 | 58 | SetTaskPushNotificationConfigRequest, |
49 | 59 | SetTaskPushNotificationConfigResponse, |
| 60 | + SetTaskPushNotificationConfigSuccessResponse, |
50 | 61 | Task, |
51 | 62 | TaskArtifactUpdateEvent, |
52 | 63 | TaskIdParams, |
|
55 | 66 | TaskPushNotificationConfig, |
56 | 67 | TaskQueryParams, |
57 | 68 | TaskResubscriptionRequest, |
58 | | - MessageSendParams, |
59 | 69 | TaskState, |
60 | 70 | TaskStatus, |
61 | 71 | TaskStatusUpdateEvent, |
62 | 72 | TextPart, |
63 | 73 | UnsupportedOperationError, |
64 | | - GetTaskSuccessResponse, |
65 | | - SendStreamingMessageSuccessResponse, |
66 | | - SendMessageSuccessResponse, |
67 | | - CancelTaskSuccessResponse, |
68 | | - Role, |
69 | | - SetTaskPushNotificationConfigSuccessResponse, |
70 | | - GetTaskPushNotificationConfigSuccessResponse, |
71 | 74 | ) |
72 | 75 |
|
| 76 | + |
73 | 77 | # --- Helper Data --- |
74 | 78 |
|
75 | | -MINIMAL_AGENT_AUTH: dict[str, Any] = {'schemes': ['Bearer']} |
76 | | -FULL_AGENT_AUTH: dict[str, Any] = { |
77 | | - 'schemes': ['Bearer', 'Basic'], |
78 | | - 'credentials': 'user:pass', |
| 79 | +MINIMAL_AGENT_SECURITY_SCHEME: dict[str, Any] = { |
| 80 | + 'type': 'apiKey', |
| 81 | + 'in': 'header', |
| 82 | + 'name': 'X-API-KEY', |
79 | 83 | } |
80 | 84 |
|
81 | 85 | MINIMAL_AGENT_SKILL: dict[str, Any] = { |
|
95 | 99 | } |
96 | 100 |
|
97 | 101 | MINIMAL_AGENT_CARD: dict[str, Any] = { |
98 | | - 'authentication': MINIMAL_AGENT_AUTH, |
99 | 102 | 'capabilities': {}, # AgentCapabilities is required but can be empty |
100 | 103 | 'defaultInputModes': ['text/plain'], |
101 | 104 | 'defaultOutputModes': ['application/json'], |
|
175 | 178 | # --- Test Functions --- |
176 | 179 |
|
177 | 180 |
|
178 | | -def test_agent_authentication_valid(): |
179 | | - auth = AgentAuthentication(**MINIMAL_AGENT_AUTH) |
180 | | - assert auth.schemes == ['Bearer'] |
181 | | - assert auth.credentials is None |
182 | | - |
183 | | - auth_full = AgentAuthentication(**FULL_AGENT_AUTH) |
184 | | - assert auth_full.schemes == ['Bearer', 'Basic'] |
185 | | - assert auth_full.credentials == 'user:pass' |
| 181 | +def test_security_scheme_valid(): |
| 182 | + scheme = SecurityScheme.model_validate(MINIMAL_AGENT_SECURITY_SCHEME) |
| 183 | + assert isinstance(scheme.root, APIKeySecurityScheme) |
| 184 | + assert scheme.root.type == 'apiKey' |
| 185 | + assert scheme.root.in_ == In.header |
| 186 | + assert scheme.root.name == 'X-API-KEY' |
186 | 187 |
|
187 | 188 |
|
188 | | -def test_agent_authentication_invalid(): |
| 189 | +def test_security_scheme_invalid(): |
189 | 190 | with pytest.raises(ValidationError): |
190 | | - AgentAuthentication( |
191 | | - credentials='only_creds' |
192 | | - ) # Missing schemes # type: ignore |
| 191 | + APIKeySecurityScheme( |
| 192 | + name='my_api_key', |
| 193 | + ) # Missing "in" # type: ignore |
193 | 194 |
|
194 | | - AgentAuthentication( |
195 | | - schemes=['Bearer'], |
196 | | - extra_field='extra', # type: ignore |
197 | | - ) # Extra field |
| 195 | + OAuth2SecurityScheme( |
| 196 | + description='OAuth2 scheme missing flows', |
| 197 | + ) # Missing "flows" |
198 | 198 |
|
199 | 199 |
|
200 | 200 | def test_agent_capabilities(): |
@@ -251,7 +251,6 @@ def test_agent_card_valid(): |
251 | 251 | card = AgentCard(**MINIMAL_AGENT_CARD) |
252 | 252 | assert card.name == 'TestAgent' |
253 | 253 | assert card.version == '1.0' |
254 | | - assert card.authentication.schemes == ['Bearer'] |
255 | 254 | assert len(card.skills) == 1 |
256 | 255 | assert card.skills[0].id == 'skill-123' |
257 | 256 | assert card.provider is None # Optional |
|
0 commit comments