-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(askar): anoncrypt messages unpacking (#1332)
Signed-off-by: Ariel Gentile <[email protected]>
- Loading branch information
Showing
3 changed files
with
149 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1,98 @@ | ||
import type { SubjectMessage } from './transport/SubjectInboundTransport' | ||
import type { AnonCredsTestsAgent } from '../packages/anoncreds/tests/legacyAnonCredsSetup' | ||
|
||
import indySdk from 'indy-sdk' | ||
import { Subject } from 'rxjs' | ||
|
||
import { getAgentOptions, makeConnection, waitForBasicMessage } from '../packages/core/tests/helpers' | ||
import { | ||
getAskarAnonCredsIndyModules, | ||
getLegacyAnonCredsModules, | ||
} from '../packages/anoncreds/tests/legacyAnonCredsSetup' | ||
import { getAgentOptions } from '../packages/core/tests/helpers' | ||
|
||
import { AskarModule } from '@aries-framework/askar' | ||
import { Agent, DependencyManager, InjectionSymbols } from '@aries-framework/core' | ||
import { IndySdkModule, IndySdkStorageService, IndySdkWallet } from '@aries-framework/indy-sdk' | ||
import { Agent, AutoAcceptCredential, MediatorPickupStrategy } from '@aries-framework/core' | ||
|
||
import { e2eTest } from './e2e-test' | ||
import { SubjectInboundTransport } from './transport/SubjectInboundTransport' | ||
import { SubjectOutboundTransport } from './transport/SubjectOutboundTransport' | ||
|
||
// FIXME: Re-include in tests when Askar NodeJS wrapper performance is improved | ||
describe.skip('E2E Askar-Indy SDK Wallet Subject tests', () => { | ||
let recipientAgent: Agent | ||
let senderAgent: Agent | ||
|
||
afterEach(async () => { | ||
if (recipientAgent) { | ||
await recipientAgent.shutdown() | ||
await recipientAgent.wallet.delete() | ||
} | ||
|
||
if (senderAgent) { | ||
await senderAgent.shutdown() | ||
await senderAgent.wallet.delete() | ||
} | ||
const recipientAgentOptions = getAgentOptions( | ||
'E2E Askar Subject Recipient', | ||
{ | ||
mediatorPickupStrategy: MediatorPickupStrategy.PickUpV1, | ||
}, | ||
getAskarAnonCredsIndyModules({ | ||
autoAcceptCredentials: AutoAcceptCredential.ContentApproved, | ||
}) | ||
|
||
test('Wallet Subject flow - Indy Sender / Askar Receiver ', async () => { | ||
// Sender is an Agent using Indy SDK Wallet | ||
const senderDependencyManager = new DependencyManager() | ||
senderDependencyManager.registerContextScoped(InjectionSymbols.Wallet, IndySdkWallet) | ||
senderDependencyManager.registerSingleton(InjectionSymbols.StorageService, IndySdkStorageService) | ||
senderAgent = new Agent( | ||
getAgentOptions( | ||
'E2E Wallet Subject Sender Indy', | ||
{ endpoints: ['rxjs:sender'] }, | ||
{ indySdk: new IndySdkModule({ indySdk }) } | ||
), | ||
senderDependencyManager | ||
) | ||
|
||
// Recipient is an Agent using Askar Wallet | ||
recipientAgent = new Agent( | ||
getAgentOptions( | ||
'E2E Wallet Subject Recipient Askar', | ||
{ endpoints: ['rxjs:recipient'] }, | ||
{ askar: new AskarModule() } | ||
) | ||
) | ||
|
||
await e2eWalletTest(senderAgent, recipientAgent) | ||
) | ||
const mediatorAgentOptions = getAgentOptions( | ||
'E2E Askar Subject Mediator', | ||
{ | ||
endpoints: ['rxjs:mediator'], | ||
autoAcceptMediationRequests: true, | ||
}, | ||
getAskarAnonCredsIndyModules({ | ||
autoAcceptCredentials: AutoAcceptCredential.ContentApproved, | ||
}) | ||
|
||
test('Wallet Subject flow - Askar Sender / Askar Recipient ', async () => { | ||
// Sender is an Agent using Askar Wallet | ||
senderAgent = new Agent( | ||
getAgentOptions('E2E Wallet Subject Sender Askar', { endpoints: ['rxjs:sender'] }, { askar: new AskarModule() }) | ||
) | ||
|
||
// Recipient is an Agent using Askar Wallet | ||
recipientAgent = new Agent( | ||
getAgentOptions( | ||
'E2E Wallet Subject Recipient Askar', | ||
{ endpoints: ['rxjs:recipient'] }, | ||
{ askar: new AskarModule() } | ||
) | ||
) | ||
|
||
await e2eWalletTest(senderAgent, recipientAgent) | ||
) | ||
const senderAgentOptions = getAgentOptions( | ||
'E2E Indy SDK Subject Sender', | ||
{ | ||
endpoints: ['rxjs:sender'], | ||
mediatorPollingInterval: 1000, | ||
mediatorPickupStrategy: MediatorPickupStrategy.PickUpV1, | ||
}, | ||
getLegacyAnonCredsModules({ | ||
autoAcceptCredentials: AutoAcceptCredential.ContentApproved, | ||
}) | ||
) | ||
|
||
test('Wallet Subject flow - Indy Sender / Indy Recipient ', async () => { | ||
// Sender is an Agent using Indy SDK Wallet | ||
const senderDependencyManager = new DependencyManager() | ||
senderDependencyManager.registerContextScoped(InjectionSymbols.Wallet, IndySdkWallet) | ||
senderDependencyManager.registerSingleton(InjectionSymbols.StorageService, IndySdkStorageService) | ||
senderAgent = new Agent( | ||
getAgentOptions( | ||
'E2E Wallet Subject Sender Indy', | ||
{ endpoints: ['rxjs:sender'] }, | ||
{ indySdk: new IndySdkModule({ indySdk }) } | ||
), | ||
senderDependencyManager | ||
) | ||
describe.skip('E2E Askar-AnonCredsRS-IndyVDR Subject tests', () => { | ||
let recipientAgent: AnonCredsTestsAgent | ||
let mediatorAgent: AnonCredsTestsAgent | ||
let senderAgent: AnonCredsTestsAgent | ||
|
||
// Recipient is an Agent using Indy Wallet | ||
const recipientDependencyManager = new DependencyManager() | ||
recipientDependencyManager.registerContextScoped(InjectionSymbols.Wallet, IndySdkWallet) | ||
recipientDependencyManager.registerSingleton(InjectionSymbols.StorageService, IndySdkStorageService) | ||
recipientAgent = new Agent( | ||
getAgentOptions( | ||
'E2E Wallet Subject Recipient Indy', | ||
{ endpoints: ['rxjs:recipient'] }, | ||
{ indySdk: new IndySdkModule({ indySdk }) } | ||
), | ||
recipientDependencyManager | ||
) | ||
|
||
await e2eWalletTest(senderAgent, recipientAgent) | ||
beforeEach(async () => { | ||
recipientAgent = new Agent(recipientAgentOptions) | ||
mediatorAgent = new Agent(mediatorAgentOptions) | ||
senderAgent = new Agent(senderAgentOptions) | ||
}) | ||
}) | ||
|
||
export async function e2eWalletTest(senderAgent: Agent, recipientAgent: Agent) { | ||
const recipientMessages = new Subject<SubjectMessage>() | ||
const senderMessages = new Subject<SubjectMessage>() | ||
|
||
const subjectMap = { | ||
'rxjs:recipient': recipientMessages, | ||
'rxjs:sender': senderMessages, | ||
} | ||
|
||
// Recipient Setup | ||
recipientAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
recipientAgent.registerInboundTransport(new SubjectInboundTransport(recipientMessages)) | ||
await recipientAgent.initialize() | ||
|
||
// Sender Setup | ||
senderAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
senderAgent.registerInboundTransport(new SubjectInboundTransport(senderMessages)) | ||
await senderAgent.initialize() | ||
afterEach(async () => { | ||
await recipientAgent.shutdown() | ||
await recipientAgent.wallet.delete() | ||
await mediatorAgent.shutdown() | ||
await mediatorAgent.wallet.delete() | ||
await senderAgent.shutdown() | ||
await senderAgent.wallet.delete() | ||
}) | ||
|
||
// Make connection between sender and recipient | ||
const [recipientSenderConnection, senderRecipientConnection] = await makeConnection(recipientAgent, senderAgent) | ||
expect(recipientSenderConnection).toBeConnectedWith(senderRecipientConnection) | ||
test('Full Subject flow (connect, request mediation, issue, verify)', async () => { | ||
const mediatorMessages = new Subject<SubjectMessage>() | ||
const senderMessages = new Subject<SubjectMessage>() | ||
|
||
// Sender sends a basic message and Recipient waits for it | ||
await senderAgent.basicMessages.sendMessage(senderRecipientConnection.id, 'Hello') | ||
await waitForBasicMessage(recipientAgent, { | ||
content: 'Hello', | ||
}) | ||
const subjectMap = { | ||
'rxjs:mediator': mediatorMessages, | ||
'rxjs:sender': senderMessages, | ||
} | ||
|
||
// Recipient sends a basic message and Sender waits for it | ||
await recipientAgent.basicMessages.sendMessage(recipientSenderConnection.id, 'How are you?') | ||
await waitForBasicMessage(senderAgent, { | ||
content: 'How are you?', | ||
// Recipient Setup | ||
recipientAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
await recipientAgent.initialize() | ||
|
||
// Mediator Setup | ||
mediatorAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
mediatorAgent.registerInboundTransport(new SubjectInboundTransport(mediatorMessages)) | ||
await mediatorAgent.initialize() | ||
|
||
// Sender Setup | ||
senderAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) | ||
senderAgent.registerInboundTransport(new SubjectInboundTransport(senderMessages)) | ||
await senderAgent.initialize() | ||
|
||
await e2eTest({ | ||
mediatorAgent, | ||
senderAgent, | ||
recipientAgent, | ||
}) | ||
}) | ||
} | ||
}) |