-
Notifications
You must be signed in to change notification settings - Fork 0
A2A Zero Trust Modernization and Refactoring #23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ const AgentService = require('../../src/services/agent'); | |
| describe('AgentService', () => { | ||
| let agentService; | ||
| let mockDb; | ||
| let mockA2AService; | ||
|
|
||
| beforeEach(() => { | ||
| mockDb = { | ||
|
|
@@ -11,7 +12,10 @@ describe('AgentService', () => { | |
| findAllAgents: jest.fn(), | ||
| updateAgent: jest.fn(), | ||
| }; | ||
| agentService = new AgentService(mockDb); | ||
| mockA2AService = { | ||
| executeTransfer: jest.fn() | ||
| }; | ||
| agentService = new AgentService(mockDb, {}, mockA2AService); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fallback tests hit delegation pathMedium Severity The Additional Locations (1)Reviewed by Cursor Bugbot for commit 0d11f38. Configure here. |
||
| }); | ||
|
|
||
| describe('registerAgent', () => { | ||
|
|
@@ -85,4 +89,67 @@ describe('AgentService', () => { | |
| expect(result.success).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('performA2ATransfer', () => { | ||
| it('should delegate to a2aService if provided', async () => { | ||
| const transferParams = { | ||
| fromAgentId: 'agent1', | ||
| toAgentId: 'agent2', | ||
| amount: 100, | ||
| currency: 'USD' | ||
| }; | ||
| const expectedResult = { success: true, transferId: 'tx123' }; | ||
| mockA2AService.executeTransfer.mockResolvedValue(expectedResult); | ||
|
|
||
| const result = await agentService.performA2ATransfer(transferParams); | ||
|
|
||
| expect(mockA2AService.executeTransfer).toHaveBeenCalledWith({ | ||
| fromAgentId: 'agent1', | ||
| toAgentId: 'agent2', | ||
| amount: 100, | ||
| ucpPayload: { currency: 'USD' } | ||
| }); | ||
| expect(result).toEqual(expectedResult); | ||
| }); | ||
|
|
||
| it('should fallback to local logic if a2aService is not provided', async () => { | ||
| const localAgentService = new AgentService(mockDb); | ||
| const fromAgent = { | ||
| id: 'agent1', | ||
| config: { limits: { perTransaction: 500 }, authorizedCounterparties: ['agent2'] } | ||
| }; | ||
| const toAgent = { id: 'agent2' }; | ||
|
|
||
| mockDb.findAgentById.mockResolvedValueOnce(fromAgent); | ||
| mockDb.findAgentById.mockResolvedValueOnce(toAgent); | ||
|
|
||
| const result = await localAgentService.performA2ATransfer({ | ||
| fromAgentId: 'agent1', | ||
| toAgentId: 'agent2', | ||
| amount: 100, | ||
| currency: 'USD' | ||
| }); | ||
|
|
||
| expect(result.success).toBe(true); | ||
| expect(result.amount).toBe(100); | ||
| }); | ||
|
|
||
| it('should throw error in fallback if amount exceeds limit', async () => { | ||
| const localAgentService = new AgentService(mockDb); | ||
| const fromAgent = { | ||
| id: 'agent1', | ||
| config: { limits: { perTransaction: 50 } } | ||
| }; | ||
|
|
||
| mockDb.findAgentById.mockResolvedValueOnce(fromAgent); | ||
| mockDb.findAgentById.mockResolvedValueOnce({ id: 'agent2' }); | ||
|
|
||
| await expect(localAgentService.performA2ATransfer({ | ||
| fromAgentId: 'agent1', | ||
| toAgentId: 'agent2', | ||
| amount: 100, | ||
| currency: 'USD' | ||
| })).rejects.toThrow('Zero Trust Validation Failed: Amount 100 exceeds agent per-transaction limit of 50'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fallback test wrong error textMedium Severity The Reviewed by Cursor Bugbot for commit 0d11f38. Configure here. |
||
| }); | ||
| }); | ||
| }); | ||


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.
Delegation omits mandate parameter
Medium Severity
When
a2aServiceis injected,performA2ATransfercallsexecuteTransferwithout amandate. Under strict mandate mode,A2AServicerejects every such call, so agent-initiated transfers cannot succeed through this entry point even though UCP can pass a mandate to the same service.Reviewed by Cursor Bugbot for commit 0d11f38. Configure here.