diff --git a/tests/credential/issue-verify-flow.spec.ts b/tests/credential/issue-verify-flow.spec.ts index 8f90e509..56c3658a 100644 --- a/tests/credential/issue-verify-flow.spec.ts +++ b/tests/credential/issue-verify-flow.spec.ts @@ -76,7 +76,6 @@ test(' Verify a jsonld credential', async ({ request }) => { }, }); const result = await response.json(); - console.log(result); expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); expect(result.verified).toBe(true); diff --git a/tests/credential/revocation-flow.spec.ts b/tests/credential/revocation-flow.spec.ts new file mode 100644 index 00000000..0361f289 --- /dev/null +++ b/tests/credential/revocation-flow.spec.ts @@ -0,0 +1,72 @@ +import type { VerifiableCredential } from '@veramo/core'; + +import { test, expect } from '@playwright/test'; +import { StatusCodes } from 'http-status-codes'; +import * as fs from 'fs'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +const PAYLOADS_BASE_PATH = './tests/payloads/credential'; + +let jwtCredential: VerifiableCredential; + +test(' Issue a jwt credential with revocation statuslist', async ({ request }) => { + const credentialData = JSON.parse( + fs.readFileSync(`${PAYLOADS_BASE_PATH}/credential-issue-jwt-revocation.json`, 'utf-8') + ); + const response = await request.post(`/credential/issue`, { + data: JSON.stringify(credentialData), + headers: { + 'Content-Type': 'application/json', + }, + }); + jwtCredential = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(jwtCredential.proof.type).toBe('JwtProof2020'); +}); + +test(" Verify a credential's revocation status", async ({ request }) => { + const response = await request.post(`/credential/verify?verifyStatus=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const result = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(result.verified).toBe(true); + expect(result.revoked).toBe(false); +}); + +test(' Verify a credential status after revocation', async ({ request }) => { + const response = await request.post(`/credential/revoke?publish=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const result = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(result.revoked).toBe(true); + + const verificationResponse = await request.post(`/credential/verify?verifyStatus=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const verificationResult = await response.json(); + expect(verificationResponse).toBeOK(); + expect(verificationResponse.status()).toBe(StatusCodes.OK); + expect(verificationResult.verified).toBe(true); + expect(result.revoked).toBe(true); +}); diff --git a/tests/credential/suspension-flow.spec.ts b/tests/credential/suspension-flow.spec.ts new file mode 100644 index 00000000..21b93c0d --- /dev/null +++ b/tests/credential/suspension-flow.spec.ts @@ -0,0 +1,103 @@ +import type { VerifiableCredential } from '@veramo/core'; + +import { test, expect } from '@playwright/test'; +import { StatusCodes } from 'http-status-codes'; +import * as fs from 'fs'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +const PAYLOADS_BASE_PATH = './tests/payloads/credential'; + +let jwtCredential: VerifiableCredential; + +test(' Issue a jwt credential with suspension statuslist', async ({ request }) => { + const credentialData = JSON.parse( + fs.readFileSync(`${PAYLOADS_BASE_PATH}/credential-issue-jwt-revocation.json`, 'utf-8') + ); + credentialData.credentialStatus.statusPurpose = 'suspension'; + const response = await request.post(`/credential/issue`, { + data: JSON.stringify(credentialData), + headers: { + 'Content-Type': 'application/json', + }, + }); + jwtCredential = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(jwtCredential.proof.type).toBe('JwtProof2020'); +}); + +test(" Verify a credential's suspension status", async ({ request }) => { + const response = await request.post(`/credential/verify`, { + data: JSON.stringify({ + credential: jwtCredential, + verifyStatus: true, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const result = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(result.verified).toBe(true); + expect(result.suspended).toBe(false); +}); + +test(' Verify a credential status after suspension', async ({ request }) => { + const response = await request.post(`/credential/suspend?publish=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const result = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(result.suspended).toBe(true); + + const verificationResponse = await request.post(`/credential/verify?verifyStatus=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const verificationResult = await response.json(); + expect(verificationResponse).toBeOK(); + expect(verificationResponse.status()).toBe(StatusCodes.OK); + expect(verificationResult.verified).toBe(true); + expect(result.suspended).toBe(true); +}); + +test(' Verify a credential status after reinstating', async ({ request }) => { + const response = await request.post(`/credential/reinstate?publish=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const result = await response.json(); + expect(response).toBeOK(); + expect(response.status()).toBe(StatusCodes.OK); + expect(result.suspended).toBe(false); + + const verificationResponse = await request.post(`/credential/verify?verifyStatus=true`, { + data: JSON.stringify({ + credential: jwtCredential, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + const verificationResult = await response.json(); + expect(verificationResponse).toBeOK(); + expect(verificationResponse.status()).toBe(StatusCodes.OK); + expect(verificationResult.verified).toBe(true); + expect(result.suspended).toBe(false); +}); diff --git a/tests/payloads/credential/credential-issue-jwt-revocation.json b/tests/payloads/credential/credential-issue-jwt-revocation.json new file mode 100644 index 00000000..050d1f9f --- /dev/null +++ b/tests/payloads/credential/credential-issue-jwt-revocation.json @@ -0,0 +1,15 @@ +{ + "issuerDid": "did:cheqd:testnet:4JdgsZ4A8LegKXdsKE3v6X", + "subjectDid": "did:key:z6MkqJNR1DHxX2qxqDYx9tNDsXoNRVpaVvJkLPeCYqaARz1n", + "attributes": { + "gender": "male", + "name": "Bob" + }, + "@context": ["https://schema.org"], + "type": ["Person"], + "format": "jwt", + "credentialStatus": { + "statusPurpose": "revocation", + "statusListName": "testingstatuslist" + } +}