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 <[email protected]>
  • Loading branch information
chereseeriepa committed Nov 18, 2024
1 parent f28fbaf commit e660883
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 240 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
14 changes: 13 additions & 1 deletion integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,19 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
})
}

static requestCredentialStackSize(): QuestionAdapter<number> {
return Question.about("request credential messages stack", actor => {
return WalletSdk.as(actor).messages.presentationMessagesStack.length
})
}

static execute(callback: (sdk: SDK.Agent, messages: {
credentialOfferStack: SDK.Domain.Message[]
issuedCredentialStack: SDK.Domain.Message[]
proofRequestStack: SDK.Domain.Message[]
revocationStack: SDK.Domain.Message[],
presentationMessagesStack: SDK.Domain.Message[],
requestCredentialStack: SDK.Domain.Message[],
enqueue(message: SDK.Domain.Message): Promise<void>

}) => Promise<void>): Interaction {
Expand All @@ -128,6 +135,7 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
proofRequestStack: WalletSdk.as(actor).messages.proofRequestStack,
revocationStack: WalletSdk.as(actor).messages.revocationStack,
presentationMessagesStack: WalletSdk.as(actor).messages.presentationMessagesStack,
requestCredentialStack: WalletSdk.as(actor).messages.requestCredentialStack,

enqueue: async (message: SDK.Domain.Message) => {
// Ensure to call the async method properly
Expand Down Expand Up @@ -221,6 +229,7 @@ class MessageQueue {
issuedCredentialStack: SDK.Domain.Message[] = []
revocationStack: SDK.Domain.Message[] = []
presentationMessagesStack: SDK.Domain.Message[] = []
requestCredentialStack: SDK.Domain.Message[] = []

receivedMessages: string[] = []

Expand Down Expand Up @@ -271,8 +280,11 @@ class MessageQueue {
this.revocationStack.push(message)
} else if (piUri === SDK.ProtocolType.DidcommPresentation) {
this.presentationMessagesStack.push(message)
} else if (piUri === SDK.ProtocolType.DidcommRequestCredential) {
this.requestCredentialStack.push(message)
} else {
console.log(piUri)
console.warn('Unhandled messaged with piuri', piUri)
// console.log(SDK.ProtocolType)
}
} 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
14 changes: 8 additions & 6 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 @@ -44,7 +43,9 @@ export class EdgeAgentWorkflow {
const msgs = await sdk.pluto.getAllMessages()

await Promise.all(
msgs.map(msg => messages.enqueue(msg))
msgs.map(msg => {
return messages.enqueue(msg)
})
)
})
)
Expand Down Expand Up @@ -172,9 +173,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 +187,7 @@ export class EdgeAgentWorkflow {
} catch (e) {
//
}
}
)
})
)
}

Expand Down
Loading

0 comments on commit e660883

Please sign in to comment.