Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 83 additions & 40 deletions tests/413.2-envelopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,36 @@ const should = chai.should();

const require = createRequire(import.meta.url);

const tag = 'EnvelopingProof';
const tag = 'vc2.0';
const {match} = filterByTag({tags: [tag]});

// 4.12.1 Enveloped Verifiable Credentials https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials
describe('VP - Enveloped Verifiable Credentials', function() {
setupMatrix.call(this, match);
for(const [name, implementation] of match) {
const endpoints = new TestEndpoints({implementation, tag});
const issuer_envelope_support =
endpoints.issuer.settings.tags.includes(
'EnvelopingProof');
const vpVerifier_envelope_support =
endpoints.vpVerifier.settings.tags.includes(
'EnvelopingProof');

describe(name, function() {
let issuedVc;
before(async function() {
try {
issuedVc = await endpoints.issue(require(
'./input/credential-ok.json'));
} catch(e) {
console.error(
`Issuer: ${name} failed to issue "credential-ok.json".`,
e
);
if(issuer_envelope_support) {
try {
issuedVc = await endpoints.issue(require(
'./input/credential-ok.json'));
} catch(e) {
console.error(
`Issuer: ${name} failed to issue "credential-ok.json".`,
e
);
}
} else {
issuedVc = null;
}
});
beforeEach(addPerTestMetadata);
Expand All @@ -48,34 +58,49 @@ describe('VP - Enveloped Verifiable Credentials', function() {
'terms as defined by the base context provided by this specification.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20%40context%20property%20of%20the%20object%20MUST%20be%20present%20and%20include%20a%20context%2C%20such%20as%20the%20base%20context%20for%20this%20specification%2C%20that%20defines%20at%20least%20the%20id%2C%20type%2C%20and%20EnvelopedVerifiableCredential%20terms%20as%20defined%20by%20the%20base%20context%20provided%20by%20this%20specification.`;
await assert.doesNotReject(endpoints.verifyVp(require(
'./input/presentation-enveloped-vc-ok.json')),
'Failed to accept a VP containing a enveloped VC.');
// TODO: add more `@context` variations to test handling?
await assert.rejects(endpoints.verifyVp(require(
'./input/presentation-enveloped-vc-missing-required-type-fail.json')),
'Failed to reject a VP containing an enveloped VC with a missing ' +
'`type`.');
if(!vpVerifier_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
await assert.doesNotReject(endpoints.verifyVp(require(
'./input/presentation-enveloped-vc-ok.json')),
'Failed to accept a VP containing a enveloped VC.');
// TODO: add more `@context` variations to test handling?
await assert.rejects(endpoints.verifyVp(require(
'./input/presentation-enveloped-vc-missing-type-fail.json')),
'Failed to reject a VP containing an enveloped VC with a missing ' +
'`type`.');
}
});

it('The id value of the object MUST be a data: URL [RFC2397] that ' +
'expresses a secured verifiable credential using an enveloping ' +
'security scheme, such as Securing Verifiable Credentials using JOSE ' +
'and COSE [VC-JOSE-COSE].', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20id%20value%20of%20the%20object%20MUST%20be%20a%20data%3A%20URL%20%5BRFC2397%5D%20that%20expresses%20a%20secured%20verifiable%20credential%20using%20an%20enveloping%20security%20scheme%2C%20such%20as%20Securing%20Verifiable%20Credentials%20using%20JOSE%20and%20COSE%20%5BVC%2DJOSE%2DCOSE%5D.`;
issuedVc.should.have.property('id').that.does
.include('data:',
`Expecting id field to be a 'data:' scheme URL [RFC2397].`);
const extractedCredential = extractIfEnveloped(issuedVc);
shouldBeCredential(extractedCredential);
if(!issuer_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
issuedVc.should.have.property('id').that.does
.include('data:',
`Expecting id field to be a 'data:' scheme URL [RFC2397].`);
const extractedCredential = extractIfEnveloped(issuedVc);
shouldBeCredential(extractedCredential);
}
});

it('The type value of the object MUST be EnvelopedVerifiableCredential.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20type%20value%20of%20the%20object%20MUST%20be%20EnvelopedVerifiableCredential.`;
issuedVc.should.have.property('type').that.does
.include('EnvelopedVerifiableCredential',
`Expecting type field to be EnvelopedVerifiableCredential`);
if(!issuer_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
issuedVc.should.have.property('type').that.does
.include('EnvelopedVerifiableCredential',
`Expecting type field to be EnvelopedVerifiableCredential`);
}
});
});
}
Expand All @@ -86,6 +111,9 @@ describe('VP - Enveloped Verifiable Presentations', function() {
setupMatrix.call(this, match);
for(const [name, implementation] of match) {
const endpoints = new TestEndpoints({implementation, tag});
const vpVerifier_envelope_support =
endpoints.vpVerifier.settings.tags.includes(
'EnvelopingProof');

describe(name, function() {
beforeEach(addPerTestMetadata);
Expand All @@ -96,33 +124,48 @@ describe('VP - Enveloped Verifiable Presentations', function() {
'terms as defined by the base context provided by this specification.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20%40context%20property%20of%20the%20object%20MUST%20be%20present%20and%20include%20a%20context%2C%20such%20as%20the%20base%20context%20for%20this%20specification%2C%20that%20defines%20at%20least%20the%20id%2C%20type%2C%20and%20EnvelopedVerifiablePresentation%20terms%20as%20defined%20by%20the%20base%20context%20provided%20by%20this%20specification.`;
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-context-fail.json')),
{name: 'HTTPError'},
'Failed to reject Enveloped VP missing contexts.');
if(!vpVerifier_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-context-fail.json')),
{name: 'HTTPError'},
'Failed to reject Enveloped VP missing contexts.');
}
});

it('The id value of the object MUST be a data: URL [RFC2397] that ' +
'expresses a secured verifiable presentation using an enveloping ' +
'securing mechanism, such as Securing Verifiable Credentials using ' +
'JOSE and COSE [VC-JOSE-COSE].', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20id%20value%20of%20the%20object%20MUST%20be%20a%20data%3A%20URL%20%5BRFC2397%5D%20that%20expresses%20a%20secured%20verifiable%20presentation%20using%20an%20enveloping%20securing%20mechanism%2C%20such%20as%20Securing%20Verifiable%20Credentials%20using%20JOSE%20and%20COSE%20%5BVC%2DJOSE%2DCOSE%5D.`;
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-id-fail.json')),
{name: 'HTTPError'},
'Failed to reject Enveloped VP with an id that is not a data url.');
if(!vpVerifier_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-id-fail.json')),
{name: 'HTTPError'},
'Failed to reject Enveloped VP with an id that is not a data url.');
}
});

it('The type value of the object MUST be ' +
'EnvelopedVerifiablePresentation.', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20type%20value%20of%20the%20object%20MUST%20be%20EnvelopedVerifiablePresentation.`;
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-type-fail.json')),
{name: 'HTTPError'},
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".');
if(!vpVerifier_envelope_support) {
this.test.cell.skipMessage = 'No envelope support.';
this.skip();
} else {
await assert.rejects(
endpoints.verifyVp(require(
'./input/enveloped-presentation-type-fail.json')),
{name: 'HTTPError'},
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".');
}
});
});
}
Expand Down