Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enveloped proofs helper functions #114

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
61 changes: 54 additions & 7 deletions tests/1-3-conformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
*/

import {addPerTestMetadata, setupMatrix} from './helpers.js';
import {checkRequiredProperties, shouldBeSecured} from './assertions.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createRequire} from 'module';
import {filterByTag} from 'vc-test-suite-implementations';
import {TestEndpoints} from './TestEndpoints.js';

// eslint-disable-next-line no-unused-vars
const should = chai.should();

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

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

Expand All @@ -23,16 +26,60 @@ describe('Basic Conformance', function() {
const endpoints = new TestEndpoints({implementation, tag});

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".`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably store this error and ensure it shows up in the report so they know that the issuance failed.

e
);
}
});
beforeEach(addPerTestMetadata);
it('Conforming document (compliance): VCDM "MUST be enforced." ' +
'("all relevant normative statements in Sections 4. Basic Concepts, ' +
'5. Advanced Concepts, and 6. Syntaxes")', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#identifiers:~:text=of%20this%20document-,MUST%20be%20enforced.,-A%20conforming%20document`;
it('A conforming document MUST be secured by at least one securing ' +
'mechanism as described in Section 4.12 Securing Mechanisms.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#securing-mechanisms:~:text=A%20conforming%20document%20MUST%20be%20secured%20by%20at%20least%20one%20securing%20mechanism%20as%20described%20in%20Section%204.12%20Securing%20Mechanisms.`;
// covers both embedded and enveloped dynamically
should.exist(issuedVc, `Expected ${name} to have issued a VC.`);
shouldBeSecured(name, issuedVc);
});
it('A conforming issuer implementation MUST include all ' +
'required properties in the conforming documents it produces.',
async function() {
this.test.link = `https://www.w3.org/TR/vc-data-model-2.0/#conformance:~:text=MUST%20include%20all%20required%20properties%20in%20the%20conforming%20documents%20it%20produces`;
should.exist(issuedVc, `Expected ${name} to have issued a VC.`);
checkRequiredProperties(name, issuedVc);
});
it('A conforming issuer implementation MUST secure the ' +
'conforming documents it produces using a securing mechanism' +
'described in Section 4.12 Securing Mechanisms.',
async function() {
this.test.link = `https://www.w3.org/TR/vc-data-model-2.0/#conformance:~:text=MUST%20include%20all%20required%20properties%20in%20the%20conforming%20documents%20it%20produces`;
should.exist(issuedVc, `Expected ${name} to have issued a VC.`);
shouldBeSecured(name, issuedVc);
});
it('A conforming verifier implementation MUST perform ' +
'verification on a conforming document as described in' +
'Section 4.12 Securing Mechanisms.',
async function() {
this.test.link = `https://www.w3.org/TR/vc-data-model-2.0/#conformance:~:text=MUST%20include%20all%20required%20properties%20in%20the%20conforming%20documents%20it%20produces`;
await assert.doesNotReject(endpoints.verify(issuedVc),
'Failed to verify credential.');
});
it('A conforming verifier implementation MUST check ' +
'that each required property satisfies the normative requirements' +
'for that property.',
async function() {
this.test.link = `https://www.w3.org/TR/vc-data-model-2.0/#conformance:~:text=MUST%20include%20all%20required%20properties%20in%20the%20conforming%20documents%20it%20produces`;
this.test.cell.skipMessage = 'Tested by other tests in this suite.';
Copy link
Contributor

@aljones15 aljones15 Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be handled by awaiting a previous call, you can do something like this

async function testSomething(){
  return endpoints.post('goo');
}

// store a promise here
const somethingTest = testSomething();

// await the promise
it('assertion 1', async function() {
  await somethingTest;
})

// await the promise again
it('assertion 2', async function() {
  await somethingTest;
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't go that far. In fact, I realized when going back through the MUSTs just now that all of Section 1 Introduction (of which 1.3 Conformance is a part) is non-normative...so we can remove the 1-3-conformance.js file altogether (and should for maintainability).

Let's merge this PR first, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since you've brought them all in the way you have, we could do what @aljones15 is suggesting. It'll make the code read a little strangely (all the test's will get called outside of any it() and then their results awaited in each it()), but if y'all feel this will comfort developers and spec reviewers who will see those MUSTs and wonder why they're not tested, I'm more than happy for these to stay.

Just still on the fence as to whether the await approach is worth the effort. Maybe let's discuss it soon.

this.skip();
});
it('verifiers MUST produce errors when non-conforming documents ' +
'are detected.', async function() {
it('A conforming verifier implementation MUST produce errors ' +
'when non-conforming documents are detected.', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=MUST%20produce%20errors%20when%20non%2Dconforming%20documents%20are%20detected.`;
const doc = {
type: ['NonconformingDocument']
Expand Down
101 changes: 0 additions & 101 deletions tests/412-securing-mechanisms.js

This file was deleted.

90 changes: 2 additions & 88 deletions tests/413-verifiable-presentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SPDX-License-Identifier: LicenseRef-w3c-3-clause-bsd-license-2008 OR LicenseRef-w3c-test-suite-license-2023
*/

import {addPerTestMetadata, setupMatrix} from './helpers.js';
import {addPerTestMetadata, setupMatrix}
from './helpers.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createRequire} from 'module';
Expand Down Expand Up @@ -83,93 +84,6 @@ describe('Verifiable Presentations', function() {
}
});

// 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});

describe(name, function() {
beforeEach(addPerTestMetadata);

it('The @context property of the object MUST be present and include a ' +
'context, such as the base context for this specification, that ' +
'defines at least the id, type, and EnvelopedVerifiableCredential ' +
'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`.');
this.skip();
});

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.`;
// TODO: implement test
this.test.cell.skipMessage = 'TBD';
this.skip();
});

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.`;
// TODO: implement test
this.test.cell.skipMessage = 'TBD';
this.skip();
});
});
}
});

// 4.12.2 Enveloped Verifiable Presentations https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations
describe('VP - Enveloped Verifiable Presentations', function() {
setupMatrix.call(this, match);
for(const [name] of match) {

describe(name, function() {
beforeEach(addPerTestMetadata);

it('The @context property of the object MUST be present and include a ' +
'context, such as the base context for this specification, that ' +
'defines at least the id, type, and EnvelopedVerifiablePresentation ' +
'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.`;
// TODO: implement test
this.test.cell.skipMessage = 'TBD';
this.skip();
});

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.`;
// TODO: implement test
this.test.cell.skipMessage = 'TBD';
this.skip();
});

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.`;
// TODO: implement test
this.test.cell.skipMessage = 'TBD';
this.skip();
});
});
}
});

// 4.12.4 Presentations Including Holder Claims https://w3c.github.io/vc-data-model/#presentations-including-holder-claims
describe('VP - Presentations Including Holder Claims', function() {
setupMatrix.call(this, match);
Expand Down
Loading