Skip to content

Commit 1fd4463

Browse files
committed
Refactor helper function getCredentialStatus().
1 parent 829a01f commit 1fd4463

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

tests/20-verify.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('StatusList2021 Credentials (Verify)', function() {
3131
let setSuspensionStatusList;
3232
let publishRevocationStatusList;
3333
let publishSuspensionStatusList;
34-
before(async function() {
34+
beforeEach(async function() {
3535
// get a VC issued by DB
3636
const {match} = filterImplementations({filter: ({value}) => {
3737
// FIXME: Make issuer name configurable via env variable
@@ -110,6 +110,11 @@ describe('StatusList2021 Credentials (Verify)', function() {
110110
publishStatusList: publishRevocationStatusList, statusInfo,
111111
statusPurpose: 'revocation'
112112
});
113+
// get the status of the VC after it is revoked
114+
const {status} = await getCredentialStatus({
115+
verifiableCredential: revokedVc
116+
});
117+
status.should.equal(true);
113118
// try to verify the credential after revocation, should fail since it
114119
// has now been revoked
115120
const {
@@ -140,6 +145,11 @@ describe('StatusList2021 Credentials (Verify)', function() {
140145
publishStatusList: publishSuspensionStatusList, statusInfo,
141146
statusPurpose: 'suspension'
142147
});
148+
// get the status of the VC after it is suspended
149+
const {status} = await getCredentialStatus({
150+
verifiableCredential: suspendedVc
151+
});
152+
status.should.equal(true);
143153
// try to verify the credential after suspension, should fail since it
144154
// has now been suspended
145155
const {

tests/30-interop.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ describe('StatusList2021 Credentials (Interop "statusPurpose: revocation")',
2929
this.rowLabel = 'Issuer';
3030
this.columnLabel = 'Verifier';
3131
for(const [issuerName, {endpoints}] of issuerMatches) {
32-
let issuedVc;
32+
let issuer;
3333
before(async function() {
34-
const [issuer] = endpoints.filter(
35-
endpoint => endpoint.settings.tags.includes('Revocation'));
36-
issuedVc = issueVc({issuer});
34+
([issuer] = endpoints.filter(
35+
endpoint => endpoint.settings.tags.includes('Revocation')));
3736
});
3837
for(const [verifierName, {endpoints}] of verifierMatches) {
3938
const [verifier] = endpoints;
4039
it(`${verifierName} should verify ${issuerName}`, async function() {
4140
this.test.cell = {rowId: issuerName, columnId: verifierName};
42-
const {data: vc, error: err} = await issuedVc;
41+
const {data: vc, error: err} = await issueVc({issuer});
4342
should.not.exist(err);
4443
should.exist(vc);
4544
const body = createRequestBody({vc});

tests/helpers.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,30 @@ export const ISOTimeStamp = ({date = new Date()} = {}) => {
2323
};
2424

2525
export const getCredentialStatus = async ({verifiableCredential}) => {
26+
// get SLC for the VC
2627
const {credentialStatus} = verifiableCredential;
27-
const {statusListCredential} = credentialStatus;
28-
// get StatusList Credential for the VC
29-
const {data: slc} = await httpClient.get(
30-
statusListCredential, {agent});
31-
const {credentialSubject: {encodedList}} = slc;
28+
if(Array.isArray(credentialStatus)) {
29+
throw new Error('Multiple credential statuses not supported.');
30+
}
31+
let slcUrl;
32+
let statusListIndexProperty;
33+
if(credentialStatus.type === 'RevocationList2020Status') {
34+
slcUrl = credentialStatus.revocationListCredential;
35+
statusListIndexProperty = 'revocationListIndex';
36+
} else {
37+
slcUrl = credentialStatus.statusListCredential;
38+
statusListIndexProperty = 'statusListIndex';
39+
}
40+
if(!slcUrl) {
41+
throw new Error('Status list credential missing from credential status.');
42+
}
43+
const {data: slc} = await httpClient.get(slcUrl, {agent});
44+
const {encodedList} = slc.credentialSubject;
3245
const list = await decodeList({encodedList});
3346
const statusListIndex = parseInt(
34-
credentialStatus.statusListIndex, 10);
47+
credentialStatus[statusListIndexProperty], 10);
3548
const status = list.getStatus(statusListIndex);
36-
return {status, statusListCredential};
49+
return {status, statusListCredential: slcUrl};
3750
};
3851

3952
export const issueVc = async ({issuer}) => {
@@ -102,8 +115,5 @@ export async function updateStatus({
102115
should.not.exist(err2);
103116
should.exist(result2);
104117
statusCode2.should.equal(204);
105-
// get the status of the VC
106-
const {status} = await getCredentialStatus({verifiableCredential: vc});
107-
status.should.equal(true);
108118
return vc;
109119
}

0 commit comments

Comments
 (0)