Skip to content

Commit

Permalink
Add more tests and assertions for status list creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Feb 22, 2024
1 parent f3a565c commit 3f53ccd
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 3 deletions.
164 changes: 161 additions & 3 deletions test/mocha/20-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,89 @@ describe('status APIs', () => {
should.exist(result.id);
result.id.should.equal(statusListId);

// FIXME: get status list and make assertions on it
// get status list and make assertions on it
const slc = await helpers.getStatusListCredential({statusListId});
should.exist(slc);
slc.should.include.keys([
'id', 'credentialSubject', 'issuanceDate', 'expirationDate'
]);
slc.id.should.equal(statusListOptions.credentialId);
slc.id.should.equal(statusListId);
slc.credentialSubject.should.include.keys([
'id', 'type', 'encodedList', 'statusPurpose'
]);
});

// FIXME: add test with `credential ID` that doesn't match status instance
it('creates a status list with non-equal credential ID', async () => {
// suffix must match
const suffix = `/status-lists/${uuid()}`;
const statusListId = `${statusInstanceId}${suffix}`;
const statusListOptions = {
credentialId: `https://foo.example/anything/111${suffix}`,
type: 'StatusList2021',
indexAllocator: `urn:uuid:${uuid()}`,
length: 131072,
statusPurpose: 'revocation'
};
let error;
let result;
try {
result = await helpers.createStatusList({
url: statusListId,
capabilityAgent,
capability: statusInstanceRootZcap,
statusListOptions
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.id);
result.id.should.equal(statusListId);

// get status list and make assertions on it
const slc = await helpers.getStatusListCredential({statusListId});
should.exist(slc);
slc.should.include.keys([
'id', 'credentialSubject', 'issuanceDate', 'expirationDate'
]);
slc.id.should.equal(statusListOptions.credentialId);
slc.id.should.not.equal(statusListId);
slc.credentialSubject.should.include.keys([
'id', 'type', 'encodedList', 'statusPurpose'
]);
});

it('create fails w/ non-matching credential ID suffix', async () => {
// suffix must match
const localId = uuid();
const suffix = `/status-lists/${localId}`;
const statusListId = `${statusInstanceId}${suffix}`;
const statusListOptions = {
credentialId: `https://foo.example/not-allowed/${localId}`,
type: 'StatusList2021',
indexAllocator: `urn:uuid:${uuid()}`,
length: 131072,
statusPurpose: 'revocation'
};
let error;
let result;
try {
result = await helpers.createStatusList({
url: statusListId,
capabilityAgent,
capability: statusInstanceRootZcap,
statusListOptions
});
} catch(e) {
error = e;
}
should.not.exist(result);
should.exist(error);
error.data.message.should.equal(
'Credential ID must end in status list suffix ' +
`("/status-lists/${localId}").`);
});

it('creates a terse "StatusList2021" status list', async () => {
const statusListId = `${statusInstanceId}/status-lists/revocation/0`;
Expand All @@ -81,7 +160,86 @@ describe('status APIs', () => {
should.exist(result.id);
result.id.should.equal(statusListId);

// FIXME: get status list and make assertions on it
// get status list and make assertions on it
const slc = await helpers.getStatusListCredential({statusListId});
should.exist(slc);
slc.should.include.keys([
'id', 'credentialSubject', 'issuanceDate', 'expirationDate'
]);
slc.id.should.equal(statusListId);
slc.credentialSubject.should.include.keys([
'id', 'type', 'encodedList', 'statusPurpose'
]);
});

it('creates a terse status list with non-equal credential ID', async () => {
// suffix must match
const suffix = `/status-lists/revocation/0`;
const statusListId = `${statusInstanceId}${suffix}`;
const statusListOptions = {
credentialId: `https://foo.example/anything/111/${suffix}`,
type: 'StatusList2021',
indexAllocator: `urn:uuid:${uuid()}`,
length: 131072,
statusPurpose: 'revocation'
};
let error;
let result;
try {
result = await helpers.createStatusList({
url: statusListId,
capabilityAgent,
capability: statusInstanceRootZcap,
statusListOptions
});
} catch(e) {
error = e;
}
assertNoError(error);
should.exist(result.id);
result.id.should.equal(statusListId);

// get status list and make assertions on it
const slc = await helpers.getStatusListCredential({statusListId});
should.exist(slc);
slc.should.include.keys([
'id', 'credentialSubject', 'issuanceDate', 'expirationDate'
]);
slc.id.should.equal(statusListOptions.credentialId);
slc.id.should.not.equal(statusListId);
slc.credentialSubject.should.include.keys([
'id', 'type', 'encodedList', 'statusPurpose'
]);
});

it('create terse fails w/ non-matching credential ID suffix', async () => {
// suffix must match
const suffix = `/status-lists/revocation/0`;
const statusListId = `${statusInstanceId}${suffix}`;
const statusListOptions = {
credentialId: `https://foo.example/not-allowed/revocation/0`,
type: 'StatusList2021',
indexAllocator: `urn:uuid:${uuid()}`,
length: 131072,
statusPurpose: 'revocation'
};
let error;
let result;
try {
result = await helpers.createStatusList({
url: statusListId,
capabilityAgent,
capability: statusInstanceRootZcap,
statusListOptions
});
} catch(e) {
error = e;
}
should.not.exist(result);
should.exist(error);
error.data.message.should.equal(
'Credential ID must end in status list suffix ' +
'("/status-lists/revocation/0").');
});
});

Expand Down
5 changes: 5 additions & 0 deletions test/mocha/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ export async function getCredentialStatus({
return {status, statusListCredential, statusListIndex};
}

export async function getStatusListCredential({statusListId}) {
const {data: slc} = await httpClient.get(statusListId, {agent: httpsAgent});
return slc;
}

export async function provisionDependencies() {
const secret = '53ad64ce-8e1d-11ec-bb12-10bf48838a41';
const handle = 'test';
Expand Down

0 comments on commit 3f53ccd

Please sign in to comment.