Skip to content

Commit

Permalink
Fix reuse of existing status mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Jul 10, 2024
1 parent ba146ff commit 9cedba5
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
148 changes: 130 additions & 18 deletions test/mocha/20-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
});
});
});

0 comments on commit 9cedba5

Please sign in to comment.