Skip to content

Commit

Permalink
test: add connectionless presentation and verification end-to-end test
Browse files Browse the repository at this point in the history
Signed-off-by: chereseeriepa <cherese.eriepa@outlook.com>
  • Loading branch information
chereseeriepa committed Nov 18, 2024
1 parent f28fbaf commit 02a3d6c
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 261 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
@connectionless @credential-offer
Feature: Edge SDK Connectionless Credential Offer
@connectionless
Feature: connectionless
The Edge Agent should receive and present a credential connectionless

Scenario: Receive a credential without a connection
Scenario: Receive and verify a credential (connectionless)
Given Cloud Agent is not connected to Edge Agent
When Cloud Agent has a connectionless credential offer invitation
And Cloud Agent shares invitation to Edge Agent
Then Edge Agent accepts the connectionless credential offer invitation
Then Edge Agent should receive the connectionless credential offer
And Edge Agent should receive the connectionless credential offer
Then Edge Agent accepts the connectionless credential offer
Then Edge Agent should receive the connectionless credential
And Edge Agent processes the issued connectionless credential from Cloud Agent
And Edge Agent should receive the connectionless credential
Then Edge Agent processes the issued connectionless credential from Cloud Agent
When Cloud Agent has a connectionless presentation invitation
And Cloud Agent shares invitation to Edge Agent
Then Edge Agent accepts the connectionless presentation invitation
And Edge Agent should receive the connectionless presentation request
When Edge Agent sends the present-proof
Then Cloud Agent should see the present-proof is verified
12 changes: 3 additions & 9 deletions integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
issuedCredentialStack: SDK.Domain.Message[]
proofRequestStack: SDK.Domain.Message[]
revocationStack: SDK.Domain.Message[],
presentationMessagesStack: SDK.Domain.Message[],
enqueue(message: SDK.Domain.Message): Promise<void>
presentationMessagesStack: SDK.Domain.Message[]

}) => Promise<void>): Interaction {
return Interaction.where("#actor uses wallet sdk", async actor => {
Expand All @@ -127,12 +126,7 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
issuedCredentialStack: WalletSdk.as(actor).messages.issuedCredentialStack,
proofRequestStack: WalletSdk.as(actor).messages.proofRequestStack,
revocationStack: WalletSdk.as(actor).messages.revocationStack,
presentationMessagesStack: WalletSdk.as(actor).messages.presentationMessagesStack,

enqueue: async (message: SDK.Domain.Message) => {
// Ensure to call the async method properly
await WalletSdk.as(actor).messages.enqueue(message);
}
presentationMessagesStack: WalletSdk.as(actor).messages.presentationMessagesStack
})
})
}
Expand Down Expand Up @@ -272,7 +266,7 @@ class MessageQueue {
} else if (piUri === SDK.ProtocolType.DidcommPresentation) {
this.presentationMessagesStack.push(message)
} else {
console.log(piUri)
console.warn('Unhandled messaged with piuri', piUri)
}
} else {
clearInterval(this.processingId!)
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/e2e-tests/src/steps/CloudAgentSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ Given("{actor} has a connectionless credential offer invitation", async function
await CloudAgentWorkflow.createConnectionlessCredentialOfferInvitation(cloudAgent)
})

Given("{actor} has a connectionless presentation invitation", async function (cloudAgent: Actor) {
await CloudAgentWorkflow.createConnectionlessPresentationInvitation(cloudAgent)
})
37 changes: 21 additions & 16 deletions integration-tests/e2e-tests/src/steps/EdgeAgentSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,21 @@ When("{actor} accepts the connectionless credential offer invitation",
}
)

When("{actor} accepts the connectionless presentation invitation",
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.acceptPresentationInvitation(edgeAgent)
}
)

Then("{actor} should receive the connectionless credential offer",
async function (edgeAgent: Actor) {
try {
await EdgeAgentWorkflow.waitForCredentialOffer(edgeAgent, 1)
} catch (error) {
// NOTE: sometimes the listener fails, so we fall back to getting the messages from
// pluto
await EdgeAgentWorkflow.loadMessagesFromPluto(edgeAgent)
await EdgeAgentWorkflow.waitForCredentialOffer(edgeAgent, 1)
}
await EdgeAgentWorkflow.waitForCredentialOffer(edgeAgent, 1)
}
)

Then("{actor} should receive the connectionless presentation request",
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.waitForProofRequest(edgeAgent)
}
)

Expand All @@ -343,16 +348,10 @@ When("{actor} accepts the connectionless credential offer",
}
)


Then("{actor} should receive the connectionless credential",
async function (edgeAgent: Actor) {
try {
await EdgeAgentWorkflow.waitToReceiveCredentialIssuance(edgeAgent, 1)
} catch (error) {
// NOTE: sometimes the listener fails, so we fall back to getting the messages from
// pluto
await EdgeAgentWorkflow.loadMessagesFromPluto(edgeAgent)
await EdgeAgentWorkflow.waitToReceiveCredentialIssuance(edgeAgent, 1)
}
await EdgeAgentWorkflow.waitToReceiveCredentialIssuance(edgeAgent, 1)
}
)

Expand All @@ -362,3 +361,9 @@ Then("{actor} processes the issued connectionless credential from {actor}",
await EdgeAgentWorkflow.processIssuedCredential(edgeAgent, recordId)
}
)

Then("{actor} should receive the verification proof",
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.waitForPresentationMessage(edgeAgent, 1)
}
)
34 changes: 34 additions & 0 deletions integration-tests/e2e-tests/src/workflow/CloudAgentWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ export class CloudAgentWorkflow {
)
}

static async createConnectionlessPresentationInvitation(cloudAgent: Actor) {
const proof = new ProofRequestAux()
proof.schemaId = "https://schema.org/Person"
proof.trustIssuers = [CloudAgentConfiguration.publishedDid]

const presentProofRequest = {
options: {
challenge: randomUUID(), // random seed prover has to sign to prevent replay attacks
domain: CloudAgentConfiguration.agentUrl
},
goalCode: 'present-vp',
goal: 'Request presentation',
credentialFormat: 'JWT',
proofs: [
proof
]
}

await cloudAgent.attemptsTo(
Send.a(PostRequest.to("present-proof/presentations/invitation").with(presentProofRequest)),
Ensure.that(LastResponse.status(), equals(HttpStatusCode.Created)),
Notepad.notes().set(
"invitation",
LastResponse.body().invitation.invitationUrl
),
Notepad.notes().set(
"presentationId",
LastResponse.body().presentationId
)
)
}



static async offerCredential(cloudAgent: Actor) {
const credential = new CreateIssueCredentialRecordRequest()
credential.claims = {
Expand Down
24 changes: 5 additions & 19 deletions integration-tests/e2e-tests/src/workflow/EdgeAgentWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export class EdgeAgentWorkflow {
)
}

static async acceptCredentialOfferInvitation(edgeAgent: Actor): Promise<void> {
await this.connect(edgeAgent)
}
static acceptCredentialOfferInvitation = this.connect
static acceptPresentationInvitation = this.connect

static async waitForCredentialOffer(edgeAgent: Actor, numberOfCredentialOffer: number) {
await edgeAgent.attemptsTo(
Expand All @@ -36,20 +35,6 @@ export class EdgeAgentWorkflow {
)
}

// NOTE: sometimes the listener fails, so we have to fallback to
// the messages in pluto
static async loadMessagesFromPluto (edgeAgent: Actor) {
await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
const msgs = await sdk.pluto.getAllMessages()

await Promise.all(
msgs.map(msg => messages.enqueue(msg))
)
})
)
}

static async waitToReceiveCredentialIssuance(edgeAgent: Actor, expectedNumberOfCredentials: number) {
await edgeAgent.attemptsTo(
Wait.upTo(Duration.ofSeconds(60)).until(
Expand Down Expand Up @@ -172,9 +157,11 @@ export class EdgeAgentWorkflow {
WalletSdk.execute(async (sdk, messages) => {
const credentials = await sdk.verifiableCredentials()
const credential = credentials[0]

const requestPresentationMessage = RequestPresentation.fromMessage(
messages.proofRequestStack.shift()!,
)

const presentation = await sdk.createPresentationForRequestProof(
requestPresentationMessage,
credential,
Expand All @@ -184,8 +171,7 @@ export class EdgeAgentWorkflow {
} catch (e) {
//
}
}
)
})
)
}

Expand Down
Loading

0 comments on commit 02a3d6c

Please sign in to comment.