Skip to content

Commit

Permalink
Add revocation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Dec 13, 2023
1 parent 81a14f8 commit e842826
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/credential/issue-verify-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
72 changes: 72 additions & 0 deletions tests/credential/revocation-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
103 changes: 103 additions & 0 deletions tests/credential/suspension-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -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);

Check failure on line 42 in tests/credential/suspension-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status

1) [chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 200 Received: 400 40 | const result = await response.json(); 41 | expect(response).toBeOK(); > 42 | expect(response.status()).toBe(StatusCodes.OK); | ^ 43 | expect(result.verified).toBe(true); 44 | expect(result.suspended).toBe(false); 45 | }); at /home/runner/work/credential-service/credential-service/tests/credential/suspension-flow.spec.ts:42:28

Check failure on line 42 in tests/credential/suspension-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status

1) [chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 200 Received: 400 40 | const result = await response.json(); 41 | expect(response).toBeOK(); > 42 | expect(response.status()).toBe(StatusCodes.OK); | ^ 43 | expect(result.verified).toBe(true); 44 | expect(result.suspended).toBe(false); 45 | }); at /home/runner/work/credential-service/credential-service/tests/credential/suspension-flow.spec.ts:42:28
expect(result.verified).toBe(true);
expect(result.suspended).toBe(false);

Check failure on line 44 in tests/credential/suspension-flow.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status

1) [chromium] › credential/suspension-flow.spec.ts:30:1 › Verify a credential's suspension status Error: expect(received).toBe(expected) // Object.is equality Expected: false Received: undefined 42 | expect(response.status()).toBe(StatusCodes.OK); 43 | expect(result.verified).toBe(true); > 44 | expect(result.suspended).toBe(false); | ^ 45 | }); 46 | 47 | test(' Verify a credential status after suspension', async ({ request }) => { at /home/runner/work/credential-service/credential-service/tests/credential/suspension-flow.spec.ts:44:27
});

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);
});
15 changes: 15 additions & 0 deletions tests/payloads/credential/credential-issue-jwt-revocation.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit e842826

Please sign in to comment.