forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(routing): support did:key in RFC0211 (openwallet-foundation#950)
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
f48f3c1
commit dc45c01
Showing
4 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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
103 changes: 103 additions & 0 deletions
103
packages/core/src/modules/routing/services/__tests__/MediatorService.test.ts
This file contains 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,103 @@ | ||
import { getAgentConfig, getMockConnection, mockFunction } from '../../../../../tests/helpers' | ||
import { EventEmitter } from '../../../../agent/EventEmitter' | ||
import { InboundMessageContext } from '../../../../agent/models/InboundMessageContext' | ||
import { IndyWallet } from '../../../../wallet/IndyWallet' | ||
import { DidExchangeState } from '../../../connections' | ||
import { KeylistUpdateAction, KeylistUpdateMessage } from '../../messages' | ||
import { MediationRole, MediationState } from '../../models' | ||
import { MediationRecord } from '../../repository' | ||
import { MediationRepository } from '../../repository/MediationRepository' | ||
import { MediatorRoutingRepository } from '../../repository/MediatorRoutingRepository' | ||
import { MediatorService } from '../MediatorService' | ||
|
||
const agentConfig = getAgentConfig('MediatorService') | ||
|
||
jest.mock('../../repository/MediationRepository') | ||
const MediationRepositoryMock = MediationRepository as jest.Mock<MediationRepository> | ||
|
||
jest.mock('../../repository/MediatorRoutingRepository') | ||
const MediatorRoutingRepositoryMock = MediatorRoutingRepository as jest.Mock<MediatorRoutingRepository> | ||
|
||
jest.mock('../../../../wallet/IndyWallet') | ||
const WalletMock = IndyWallet as jest.Mock<IndyWallet> | ||
|
||
const mediationRepository = new MediationRepositoryMock() | ||
const mediatorRoutingRepository = new MediatorRoutingRepositoryMock() | ||
|
||
const wallet = new WalletMock() | ||
|
||
const mediatorService = new MediatorService( | ||
mediationRepository, | ||
mediatorRoutingRepository, | ||
agentConfig, | ||
wallet, | ||
new EventEmitter(agentConfig) | ||
) | ||
|
||
const mockConnection = getMockConnection({ | ||
state: DidExchangeState.Completed, | ||
}) | ||
|
||
describe('MediatorService', () => { | ||
describe('processKeylistUpdateRequest', () => { | ||
test('processes base58 encoded recipient keys', async () => { | ||
const mediationRecord = new MediationRecord({ | ||
connectionId: 'connectionId', | ||
role: MediationRole.Mediator, | ||
state: MediationState.Granted, | ||
threadId: 'threadId', | ||
recipientKeys: ['8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K'], | ||
}) | ||
|
||
mockFunction(mediationRepository.getByConnectionId).mockResolvedValue(mediationRecord) | ||
|
||
const keyListUpdate = new KeylistUpdateMessage({ | ||
updates: [ | ||
{ | ||
action: KeylistUpdateAction.add, | ||
recipientKey: '79CXkde3j8TNuMXxPdV7nLUrT2g7JAEjH5TreyVY7GEZ', | ||
}, | ||
{ | ||
action: KeylistUpdateAction.remove, | ||
recipientKey: '8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K', | ||
}, | ||
], | ||
}) | ||
|
||
const messageContext = new InboundMessageContext(keyListUpdate, { connection: mockConnection }) | ||
await mediatorService.processKeylistUpdateRequest(messageContext) | ||
|
||
expect(mediationRecord.recipientKeys).toEqual(['79CXkde3j8TNuMXxPdV7nLUrT2g7JAEjH5TreyVY7GEZ']) | ||
}) | ||
|
||
test('processes did:key encoded recipient keys', async () => { | ||
const mediationRecord = new MediationRecord({ | ||
connectionId: 'connectionId', | ||
role: MediationRole.Mediator, | ||
state: MediationState.Granted, | ||
threadId: 'threadId', | ||
recipientKeys: ['8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K'], | ||
}) | ||
|
||
mockFunction(mediationRepository.getByConnectionId).mockResolvedValue(mediationRecord) | ||
|
||
const keyListUpdate = new KeylistUpdateMessage({ | ||
updates: [ | ||
{ | ||
action: KeylistUpdateAction.add, | ||
recipientKey: 'did:key:z6MkkbTaLstV4fwr1rNf5CSxdS2rGbwxi3V5y6NnVFTZ2V1w', | ||
}, | ||
{ | ||
action: KeylistUpdateAction.remove, | ||
recipientKey: 'did:key:z6MkmjY8GnV5i9YTDtPETC2uUAW6ejw3nk5mXF5yci5ab7th', | ||
}, | ||
], | ||
}) | ||
|
||
const messageContext = new InboundMessageContext(keyListUpdate, { connection: mockConnection }) | ||
await mediatorService.processKeylistUpdateRequest(messageContext) | ||
|
||
expect(mediationRecord.recipientKeys).toEqual(['79CXkde3j8TNuMXxPdV7nLUrT2g7JAEjH5TreyVY7GEZ']) | ||
}) | ||
}) | ||
}) |