Skip to content

Commit

Permalink
Only test mixed VCs with VP 2.0 & improve VP test titles.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Feb 5, 2024
1 parent e6a3d3d commit eb376fe
Showing 1 changed file with 101 additions and 106 deletions.
207 changes: 101 additions & 106 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,116 +544,111 @@ for(const [version, mockCredential] of versionedCredentials) {
});
});

describe('test for multiple credentials', async () => {
const credentialsCount = [5, 25, 50, 100];

for(const count of credentialsCount) {
it(`cause error when credentials are tampered [${count}]`, async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential,
version
describe(`VerifiablePresentations Version ${version} w/ multiple VCs`,
async () => {
const credentialsCount = [5, 25, 50, 100];
for(const count of credentialsCount) {
it(`should error when credentials are tampered [${count}]`,
async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential,
version
});
// tampering with the first two credentials id
presentation.verifiableCredential[0].id = 'test:some_fake_id';
presentation.verifiableCredential[1].id =
'test:some_other_fake_id';
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const credentialResults = result.credentialResults;
const credentialOne = result.credentialResults[0];
const credentialTwo = result.credentialResults[1];
const firstErrorMsg = result.credentialResults[0].error.errors[0]
.message;
result.verified.should.be.a('boolean');
result.verified.should.be.false;
credentialOne.verified.should.be.a('boolean');
credentialOne.verified.should.be.false;
credentialOne.credentialId.should.be.a('string');
credentialOne.credentialId.should.equal('test:some_fake_id');
credentialTwo.verified.should.be.a('boolean');
credentialTwo.verified.should.be.false;
credentialTwo.credentialId.should.be.a('string');
credentialTwo.credentialId.should.equal(
'test:some_other_fake_id');
for(let i = 2; i < credentialResults.length; ++i) {
const credential = credentialResults[i];
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
firstErrorMsg.should.contain('Invalid signature.');
});

// tampering with the first two credentials id
presentation.verifiableCredential[0].id = 'test:some_fake_id';
presentation.verifiableCredential[1].id = 'test:some_other_fake_id';

const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const credentialResults = result.credentialResults;
const credentialOne = result.credentialResults[0];
const credentialTwo = result.credentialResults[1];
const firstErrorMsg = result.credentialResults[0].error.errors[0]
.message;

result.verified.should.be.a('boolean');
result.verified.should.be.false;

credentialOne.verified.should.be.a('boolean');
credentialOne.verified.should.be.false;
credentialOne.credentialId.should.be.a('string');
credentialOne.credentialId.should.equal('test:some_fake_id');

credentialTwo.verified.should.be.a('boolean');
credentialTwo.verified.should.be.false;
credentialTwo.credentialId.should.be.a('string');
credentialTwo.credentialId.should.equal('test:some_other_fake_id');

for(let i = 2; i < credentialResults.length; ++i) {
const credential = credentialResults[i];
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}

firstErrorMsg.should.contain('Invalid signature.');
});
it('should not cause error when credentials are correct', async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential,
version
it(`should not error when credentials are correct [${count}]`,
async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential,
version
});
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const credentialResults = result.credentialResults;
result.verified.should.be.a('boolean');
result.verified.should.be.true;
for(const credential of credentialResults) {
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
});
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const credentialResults = result.credentialResults;

result.verified.should.be.a('boolean');
result.verified.should.be.true;

for(const credential of credentialResults) {
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
});
it.only('should not cause error when credentials have mixed contexts',
async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential: mockData.credentials.mixed,
version
if(version === 2.0) {
it(`should not error when credentials have mixed contexts ` +
`[${count}]`, async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential: mockData.credentials.mixed,
version
});
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
const credentialResults = result.credentialResults;
result.verified.should.be.a('boolean');
result.verified.should.be.true;
for(const credential of credentialResults) {
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
});
const credentialResults = result.credentialResults;

result.verified.should.be.a('boolean');
result.verified.should.be.true;

for(const credential of credentialResults) {
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
});
}
});
}
}
});

describe('_checkCredential', () => {
it('should reject a credentialSubject.id that is not a URI', () => {
Expand Down

0 comments on commit eb376fe

Please sign in to comment.