Skip to content

Commit

Permalink
fix: add e2e tests for jwt revocation, sdk verification for jwt and a…
Browse files Browse the repository at this point in the history
…noncreds (#244)

Signed-off-by: Javier Ribó <[email protected]>
  • Loading branch information
elribonazo committed Jul 19, 2024
1 parent 2391f01 commit 5c2519b
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@anoncreds @credential @sdkverification
Feature: Verify Anoncreds presentation
The Edge Agent should be able to receive a verifiable credential from Cloud Agent and then send a presentation to another edge agent who will verify it

Scenario: SDKs Anoncreds Verification
Given Cloud Agent is connected to Edge Agent
When Cloud Agent offers '1' anonymous credential
Then Edge Agent should receive the credentials offer from Cloud Agent
When Edge Agent accepts the credentials offer from Cloud Agent
And Cloud Agent should see all credentials were accepted
Then Edge Agent wait to receive issued credentials from Cloud Agent
And Edge Agent process issued credentials from Cloud Agent
Then Verifier Edge Agent will request Edge Agent to verify the anonymous credential
When Edge Agent sends the verification proof
Then Verifier Edge Agent should see the verification proof is verified
23 changes: 23 additions & 0 deletions integration-tests/e2e-tests/features/verify_jwt_credential.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@jwt @credential @sdkverification
Feature: Verify JWT presentation
The Edge Agent should be able to receive a verifiable credential from Cloud Agent and then send a presentation to another edge agent who will verify it

Scenario: SDKs JWT Verification
Given Cloud Agent is connected to Edge Agent
When Cloud Agent offers '1' jwt credentials
Then Edge Agent should receive the credentials offer from Cloud Agent
When Edge Agent accepts the credentials offer from Cloud Agent
And Cloud Agent should see all credentials were accepted
Then Edge Agent wait to receive issued credentials from Cloud Agent
And Edge Agent process issued credentials from Cloud Agent
Then Verifier Edge Agent will request Edge Agent to verify the JWT credential
When Edge Agent sends the verification proof
Then Verifier Edge Agent should see the verification proof is verified

Scenario: SDKs JWT Revoked Verification
Given Cloud Agent is connected to Edge Agent
And Edge Agent has '1' jwt credentials issued by Cloud Agent
When Cloud Agent revokes '1' credentials
Then Verifier Edge Agent will request Edge Agent to verify the JWT credential
When Edge Agent sends the verification proof
Then Verifier Edge Agent should see the verification proof is verified false
2 changes: 1 addition & 1 deletion integration-tests/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
"resolutions": {
"wrap-ansi": "^7.0.0"
}
}
}
25 changes: 20 additions & 5 deletions integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,27 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
})
}

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

static execute(callback: (sdk: SDK.Agent, messages: {
credentialOfferStack: Message[];
issuedCredentialStack: Message[];
proofRequestStack: Message[];
revocationStack: Message[],
presentationMessagesStack: Message[]

}) => Promise<void>): Interaction {
return Interaction.where("#actor uses wallet sdk", async actor => {
await callback(WalletSdk.as(actor).sdk, {
credentialOfferStack: WalletSdk.as(actor).messages.credentialOfferStack,
issuedCredentialStack: WalletSdk.as(actor).messages.issuedCredentialStack,
proofRequestStack: WalletSdk.as(actor).messages.proofRequestStack,
revocationStack: WalletSdk.as(actor).messages.revocationStack,
presentationMessagesStack: WalletSdk.as(actor).messages.presentationMessagesStack
})
})
}
Expand Down Expand Up @@ -115,6 +124,8 @@ class MessageQueue {
proofRequestStack: Message[] = []
issuedCredentialStack: Message[] = []
revocationStack: Message[] = []
presentationMessagesStack: Message[] = [];

receivedMessages: string[] = []

enqueue(message: Message) {
Expand Down Expand Up @@ -144,22 +155,26 @@ class MessageQueue {
this.processingId = setInterval(() => {
if (!this.isEmpty()) {
const message: Message = this.dequeue()

const piUri = message.piuri;

// checks if sdk already received message
if (this.receivedMessages.includes(message.id)) {
return
}

this.receivedMessages.push(message.id)

if (message.piuri.includes("/offer-credential")) {

if (piUri === SDK.ProtocolType.DidcommOfferCredential) {
this.credentialOfferStack.push(message)
} else if (message.piuri.includes("/present-proof")) {
} else if (piUri === SDK.ProtocolType.DidcommRequestPresentation) {
this.proofRequestStack.push(message)
} else if (message.piuri.includes("/issue-credential")) {
} else if (piUri === SDK.ProtocolType.DidcommIssueCredential) {
this.issuedCredentialStack.push(message)
} else if (message.piuri.includes("/revoke")) {
} else if (piUri === SDK.ProtocolType.PrismRevocation) {
this.revocationStack.push(message)
} else if (piUri === SDK.ProtocolType.DidcommPresentation) {
this.presentationMessagesStack.push(message)
}
} else {
clearInterval(this.processingId!)
Expand Down
96 changes: 88 additions & 8 deletions integration-tests/e2e-tests/src/steps/EdgeAgentSteps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import SDK from "@atala/prism-wallet-sdk"
import { Given, Then, When } from "@cucumber/cucumber"
import { Actor, Notepad } from "@serenity-js/core"
import { EdgeAgentWorkflow } from "../workflow/EdgeAgentWorkflow"
import { CloudAgentWorkflow } from "../workflow/CloudAgentWorkflow"
import { Utils } from "../Utils"


Given("{actor} has '{int}' jwt credentials issued by {actor}",
async function (edgeAgent: Actor, numberOfIssuedCredentials: number, cloudAgent: Actor) {
const recordIdList = []
Expand Down Expand Up @@ -38,19 +40,19 @@ Given("{actor} has '{int}' anonymous credentials issued by {actor}",
)

Given("{actor} has created a backup",
async function(edgeAgent: Actor) {
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.createBackup(edgeAgent)
}
)

Given("{actor} creates '{}' peer DIDs",
async function(edgeAgent: Actor, numberOfDids: number) {
async function (edgeAgent: Actor, numberOfDids: number) {
await EdgeAgentWorkflow.createPeerDids(edgeAgent, numberOfDids)
}
)

Given("{actor} creates '{}' prism DIDs",
async function(edgeAgent: Actor, numberOfDids: number) {
async function (edgeAgent: Actor, numberOfDids: number) {
await EdgeAgentWorkflow.createPrismDids(edgeAgent, numberOfDids)
}
)
Expand Down Expand Up @@ -148,31 +150,109 @@ Then("{actor} wait to receive issued credentials from {actor}",
)

Then("a new SDK can be restored from {actor}",
async function(edgeAgent: Actor) {
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.createNewWalletFromBackup(edgeAgent)
}
)

Then("a new SDK cannot be restored from {actor} with wrong seed",
async function(edgeAgent: Actor) {
async function (edgeAgent: Actor) {
await EdgeAgentWorkflow.createNewWalletFromBackupWithWrongSeed(edgeAgent)
}
)

Then("a new {actor} is restored from {actor}",
async function(newAgent: Actor, edgeAgent: Actor) {
async function (newAgent: Actor, edgeAgent: Actor) {
await EdgeAgentWorkflow.backupAndRestoreToNewAgent(newAgent, edgeAgent)
}
)

Then("{actor} should have the expected values from {actor}",
async function(copyEdgeAgent: Actor, originalEdgeAgent: Actor) {
async function (copyEdgeAgent: Actor, originalEdgeAgent: Actor) {
await EdgeAgentWorkflow.copyAgentShouldMatchOriginalAgent(copyEdgeAgent, originalEdgeAgent)
}
)

Then("{actor} is dismissed",
async function(edgeAgent: Actor) {
async function (edgeAgent: Actor) {
await edgeAgent.dismiss()
}
)

Then("{actor} will request {actor} to verify the anonymous credential",
async function (verifierEdgeAgent: Actor, holderEdgeAgent: Actor) {

await EdgeAgentWorkflow.createPeerDids(holderEdgeAgent, 1)
const holderDID = await holderEdgeAgent.answer(Notepad.notes().get("lastPeerDID"));

await EdgeAgentWorkflow.initiatePresentationRequest(
verifierEdgeAgent,
SDK.Domain.CredentialType.AnonCreds,
holderDID,
{
attributes: {
name: {
name: 'name',
restrictions: {}
}
}
}
)
}
)

Then("{actor} will request {actor} to verify the JWT credential",
async function (verifierEdgeAgent: Actor, holderEdgeAgent: Actor) {

await EdgeAgentWorkflow.createPeerDids(holderEdgeAgent, 1)
const holderDID = await holderEdgeAgent.answer(Notepad.notes().get("lastPeerDID"));

await EdgeAgentWorkflow.initiatePresentationRequest(
verifierEdgeAgent,
SDK.Domain.CredentialType.JWT,
holderDID,
{
claims: {
"automation-required": {
type: 'string',
pattern: 'required value'
}
}
}
)
}
)

When("{actor} sends the verification proof", async (
edgeAgent: Actor,
) => {
await EdgeAgentWorkflow.waitForProofRequest(
edgeAgent
)
await EdgeAgentWorkflow.presentVerificationRequest(
edgeAgent
)
})

Then("{actor} should see the verification proof is verified", async (
edgeAgent: Actor,
) => {
await EdgeAgentWorkflow.waitForPresentationMessage(
edgeAgent
)
await EdgeAgentWorkflow.verifyPresentation(
edgeAgent
)
})

Then("{actor} should see the verification proof is verified false", async (
edgeAgent: Actor,
) => {
await EdgeAgentWorkflow.waitForPresentationMessage(
edgeAgent
)
await EdgeAgentWorkflow.verifyPresentation(
edgeAgent,
false
)
})
Loading

0 comments on commit 5c2519b

Please sign in to comment.