diff --git a/lib/status.js b/lib/status.js index 75e8004..36ab1ae 100644 --- a/lib/status.js +++ b/lib/status.js @@ -28,7 +28,7 @@ export async function setStatus({ // try to get an existing mapping let mapping; try { - mapping = await mappings.get({configId, credentialId, statusPurpose}); + ({mapping} = await mappings.get({configId, credentialId, statusPurpose})); } catch(e) { if(e.name !== 'NotFoundError') { throw e; diff --git a/test/mocha/20-status.js b/test/mocha/20-status.js index 79ac629..2480fbf 100644 --- a/test/mocha/20-status.js +++ b/test/mocha/20-status.js @@ -496,26 +496,102 @@ describe('status APIs', () => { // then revoke VC const zcapClient = helpers.createZcapClient({capabilityAgent}); - let error; - try { - await zcapClient.write({ - url: `${statusInstanceId}/credentials/status`, - capability: statusInstanceRootZcap, - json: { - credentialId, - indexAllocator: statusListOptions.indexAllocator, - credentialStatus: { - type: 'BitstringStatusListEntry', - statusPurpose: 'revocation', - statusListCredential, - statusListIndex + { + let error; + try { + await zcapClient.write({ + url: `${statusInstanceId}/credentials/status`, + capability: statusInstanceRootZcap, + json: { + credentialId, + indexAllocator: statusListOptions.indexAllocator, + credentialStatus: { + type: 'BitstringStatusListEntry', + statusPurpose: 'revocation', + statusListCredential, + statusListIndex + } } - } - }); - } catch(e) { - error = e; + }); + } catch(e) { + error = e; + } + assertNoError(error); + } + + // force refresh status list + await zcapClient.write({ + url: `${statusListCredential}?refresh=true`, + capability: statusInstanceRootZcap, + json: {} + }); + + // check status of VC has changed + ({status} = await helpers.getCredentialStatus({ + statusListCredential, statusListIndex + })); + status.should.equal(true); + + // then unrevoke VC to ensure it can be switched back + { + let error; + try { + await zcapClient.write({ + url: `${statusInstanceId}/credentials/status`, + capability: statusInstanceRootZcap, + json: { + credentialId, + indexAllocator: statusListOptions.indexAllocator, + credentialStatus: { + type: 'BitstringStatusListEntry', + statusPurpose: 'revocation', + statusListCredential, + statusListIndex + }, + status: false + } + }); + } catch(e) { + error = e; + } + assertNoError(error); + } + + // force refresh status list + await zcapClient.write({ + url: `${statusListCredential}?refresh=true`, + capability: statusInstanceRootZcap, + json: {} + }); + + // check status of VC has changed + ({status} = await helpers.getCredentialStatus({ + statusListCredential, statusListIndex + })); + status.should.equal(false); + + // then revoke VC again with only status type and purpose now that + // it has been registered with the status system + { + let error; + try { + await zcapClient.write({ + url: `${statusInstanceId}/credentials/status`, + capability: statusInstanceRootZcap, + json: { + credentialId, + credentialStatus: { + type: 'BitstringStatusListEntry', + statusPurpose: 'revocation' + }, + status: true + } + }); + } catch(e) { + error = e; + } + assertNoError(error); } - assertNoError(error); // force refresh status list await zcapClient.write({ @@ -529,6 +605,42 @@ describe('status APIs', () => { statusListCredential, statusListIndex })); status.should.equal(true); + + // then unrevoke VC again with only status type and purpose now that + // it has been registered with the status system + { + let error; + try { + await zcapClient.write({ + url: `${statusInstanceId}/credentials/status`, + capability: statusInstanceRootZcap, + json: { + credentialId, + credentialStatus: { + type: 'BitstringStatusListEntry', + statusPurpose: 'revocation' + }, + status: false + } + }); + } catch(e) { + error = e; + } + assertNoError(error); + } + + // force refresh status list + await zcapClient.write({ + url: `${statusListCredential}?refresh=true`, + capability: statusInstanceRootZcap, + json: {} + }); + + // check status of VC has changed + ({status} = await helpers.getCredentialStatus({ + statusListCredential, statusListIndex + })); + status.should.equal(false); }); }); });