Skip to content

Commit

Permalink
Add revocation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Oct 8, 2024
1 parent 2a73053 commit e3c63d4
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/controllers/api/accreditation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class AccreditationController {
AccreditationRequestType.attest,
])
.bail(),
query('accreditationName').exists().isString().withMessage('accreditationName is required').bail(),
body('issuerDid').exists().isDID().bail(),
body('subjectDid').exists().isDID().bail(),
body('schemas').exists().isArray().withMessage('schemas must be a array').bail(),
Expand All @@ -48,7 +49,9 @@ export class AccreditationController {
.custom((value) => typeof value === 'string' || (Array.isArray(value) && typeof value[0] === 'string'))
.withMessage('schema type must be a string'),
body('parentAccreditation').optional().isString().withMessage('parentAccreditation must be a string').bail(),
body('rootAuthorization').optional().withMessage('rootAuthorization must be a string').bail(),
body('rootAuthorization').optional().isString().withMessage('rootAuthorization must be a string').bail(),
body('trustFramework').optional().isString().withMessage('trustFramework must be a string').bail(),
body('trustFrameworkId').optional().isString().withMessage('trustFrameworkId must be a string').bail(),
query('accreditationType')
.custom((value, { req }) => {
const { parentAccreditation, rootAuthorization, trustFramework, trustFrameworkId } = req.body;
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/payloads/accreditation/authorize-jwt-revocation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"issuerDid": "did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA",
"subjectDid": "did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578",
"@context": ["https://schema.org"],
"type": ["Person"],
"format": "jwt",
"credentialStatus": {
"statusPurpose": "revocation",
"statusListName": "testingstatuslist"
},
"schemas": [
{
"url": "https://schema.org/Learn",
"type": "Learn"
}
],
"accreditationName": "authorizeAccreditation",
"trustFrameworkId": "https://learn.cheqd.io/governance/start",
"trustFramework": "cheqd Governance Framework"
}
83 changes: 83 additions & 0 deletions tests/e2e/sequential/accreditation/revocation-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { VerifiableCredential } from '@veramo/core';
import * as fs from 'fs';
import { test, expect } from '@playwright/test';
import { StatusCodes } from 'http-status-codes';
import { CONTENT_TYPE, PAYLOADS_PATH } from '../../constants';

test.use({ storageState: 'playwright/.auth/user.json' });

let jwtCredential: VerifiableCredential;

test(' Issue an Accreditation with revocation statuslist', async ({ request }) => {
const payload = JSON.parse(
fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/authorize-jwt-revocation.json`, 'utf-8')
);
const response = await request.post(`/trust-registry/accreditation/issue`, {
data: JSON.stringify(payload),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
jwtCredential = await response.json();
expect(response).toBeOK();
expect(response.status()).toBe(StatusCodes.OK);
expect(jwtCredential.proof.type).toBe('JwtProof2020');
expect(jwtCredential.proof).toHaveProperty('jwt');
expect(typeof jwtCredential.issuer === 'string' ? jwtCredential.issuer : jwtCredential.issuer.id).toBe(
payload.issuerDid
);
expect(jwtCredential.type).toContain('VerifiableCredential');
expect(jwtCredential.credentialSubject.id).toBe(payload.subjectDid);
expect(jwtCredential.credentialStatus).toMatchObject({
type: 'StatusList2021Entry',
statusPurpose: 'revocation',
});
expect(jwtCredential.credentialStatus).toHaveProperty('statusListIndex');
expect(jwtCredential.credentialStatus).toHaveProperty('id');
});

test(" Verify a Accreditation's revocation status", async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
credential: jwtCredential,
}),
headers: {
'Content-Type': 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 Accreditation status after revocation', async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/revoke?publish=true`, {
data: JSON.stringify({
credential: jwtCredential,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await response.json();
expect(response).toBeOK();
expect(response.status()).toBe(StatusCodes.OK);
expect(result.revoked).toBe(true);
expect(result.published).toBe(true);

const verificationResponse = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
credential: jwtCredential,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const verificationResult = await verificationResponse.json();
expect(verificationResponse).toBeOK();
expect(verificationResponse.status()).toBe(StatusCodes.OK);
expect(verificationResult.verified).toBe(true);
expect(verificationResult.revoked).toBe(true);
});

0 comments on commit e3c63d4

Please sign in to comment.