Skip to content

Commit b6e4274

Browse files
committed
Add package command to run allure tests
Signed-off-by: PatStLouis <[email protected]>
1 parent 026e2bc commit b6e4274

14 files changed

+1534
-7
lines changed

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"type": "module",
1010
"scripts": {
1111
"test": "mocha tests/ --reporter @digitalbazaar/mocha-w3c-interop-reporter --reporter-options abstract=\"$PWD/abstract.hbs\",reportDir=\"$PWD/reports\",respec=\"$PWD/respecConfig.json\",suiteLog='./suite.log',templateData=\"$PWD/reports/index.json\",title=\"VC v2.0 Interoperability Report\" --timeout 15000 --preserve-symlinks",
12+
"test-allure": "npx mocha tests/ -R allure-mocha -O 'resultsDir=allure-results'",
1213
"lint": "eslint ."
1314
},
1415
"repository": {
@@ -55,12 +56,5 @@
5556
"eslint-config-digitalbazaar": "^4.0.1",
5657
"eslint-plugin-jsdoc": "^39.3.3",
5758
"eslint-plugin-unicorn": "^43.0.0"
58-
},
59-
"mocha": {
60-
"parallel": false,
61-
"reporter": "allure-mocha",
62-
"reporterOptions": {
63-
"resultsDir": "allure-results"
64-
}
6559
}
6660
}

tmp/4.03-contexts.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright 2022 - 2024 Digital Bazaar, Inc.
3+
*
4+
* SPDX-License-Identifier: LicenseRef-w3c-3-clause-bsd-license-2008 OR LicenseRef-w3c-test-suite-license-2023
5+
*/
6+
7+
import {addPerTestMetadata, setupMatrix} from '../tests/helpers.js';
8+
import {createInvalidVp, createLocalVp} from '../tests/data-generator.js';
9+
import assert from 'node:assert/strict';
10+
import chai from 'chai';
11+
import {createRequire} from 'module';
12+
import {filterByTag} from 'vc-test-suite-implementations';
13+
import {injectOrReject} from '../tests/assertions.js';
14+
import {klona} from 'klona';
15+
import {TestEndpoints} from '../tests/TestEndpoints.js';
16+
17+
// eslint-disable-next-line no-unused-vars
18+
const should = chai.should();
19+
20+
const require = createRequire(import.meta.url);
21+
const baseContextUrl = 'https://www.w3.org/ns/credentials/v2';
22+
23+
const tag = 'vc2.0';
24+
const {match} = filterByTag({tags: [tag]});
25+
26+
// 4.2 Verifiable Credentials https://w3c.github.io/vc-data-model/#verifiable-credentials
27+
// There are no actual MUSTs here, just references to other sections.
28+
29+
// 4.3 Contexts https://w3c.github.io/vc-data-model/#contexts
30+
describe('Contexts', function() {
31+
setupMatrix.call(this, match);
32+
for(const [name, implementation] of match) {
33+
const endpoints = new TestEndpoints({implementation, tag});
34+
35+
describe(name, function() {
36+
beforeEach(addPerTestMetadata);
37+
38+
it('Verifiable credentials MUST include a @context property.',
39+
async function() {
40+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Verifiable%20credentials%20and%20verifiable%20presentations%20MUST%20include%20a%20%40context%20property.`;
41+
// positive @context test
42+
const vc = await endpoints.issue(require(
43+
'../tests/input/credential-ok.json'));
44+
vc.should.have.property('@context').to.be.an('array',
45+
'Failed to respond with a VC with intact `@context`.');
46+
// negative @context test
47+
await injectOrReject(endpoints,
48+
'./input/credential-no-context-fail-or-inject.json');
49+
50+
});
51+
it('Verifiable presentations MUST include a @context property.',
52+
async function() {
53+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Verifiable%20credentials%20and%20verifiable%20presentations%20MUST%20include%20a%20%40context%20property.`;
54+
const validVp = await createLocalVp({
55+
presentation: require('../tests/input/presentation-ok.json')
56+
});
57+
await assert.doesNotReject(
58+
endpoints.verifyVp(validVp),
59+
`verifier ${name} rejected VP with valid @context.`
60+
);
61+
const invalidVp = klona(validVp);
62+
delete invalidVp['@context'];
63+
await assert.rejects(endpoints.verifyVp(invalidVp),
64+
'Failed to reject a VP with a missing @context.');
65+
});
66+
it('Verifiable credentials: The value of the @context property ' +
67+
'MUST be an ordered set where the first item is a URL with the value ' +
68+
'https://www.w3.org/ns/credentials/v2.', async function() {
69+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=The%20value%20of%20the%20%40context%20property%20MUST%20be%20an%20ordered%20set%20where%20the%20first%20item%20is%20a%20URL%20with%20the%20value%20https%3A//www.w3.org/ns/credentials/v2.`;
70+
//positive issue test
71+
const vc = await endpoints.issue(require(
72+
'../tests/input/credential-ok.json'));
73+
assert(Array.isArray(vc['@context']),
74+
'Failed to support `@context` as an Array.');
75+
assert.strictEqual(vc['@context'][0], baseContextUrl,
76+
'Failed to keep `@context` order intact.'
77+
);
78+
// negative issue test
79+
await injectOrReject(endpoints,
80+
'./input/credential-missing-base-context-fail-or-inject.json');
81+
});
82+
it('Verifiable presentations: The value of the @context ' +
83+
'property MUST be an ordered set where the first item is a URL with ' +
84+
'the value https://www.w3.org/ns/credentials/v2.', async function() {
85+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=The%20value%20of%20the%20%40context%20property%20MUST%20be%20an%20ordered%20set%20where%20the%20first%20item%20is%20a%20URL%20with%20the%20value%20https%3A//www.w3.org/ns/credentials/v2.`;
86+
const vpInvalidContextOrder = await createInvalidVp({
87+
presentation: require('../tests/input/presentation-context-order-fail.json')
88+
});
89+
await assert.rejects(endpoints.verifyVp(vpInvalidContextOrder),
90+
91+
'Failed to reject a VP that has the wrong context order.');
92+
const vp = createLocalVp({
93+
presentation: require('../tests/input/presentation-ok.json')
94+
});
95+
vp['@context'] = [
96+
'https://www.w3.org/ns/credentials/examples/v2',
97+
'https://www.w3.org/ns/credentials/v2'
98+
];
99+
await assert.rejects(endpoints.verifyVp(vp),
100+
'Failed to reject a VP with unordered @context.');
101+
await assert.rejects(endpoints.verifyVp(
102+
require('../tests/input/presentation-missing-base-context-fail.json')),
103+
104+
'Failed to reject a VP that lacked the VC base context URL.');
105+
});
106+
it('Verifiable Credential `@context`: "Subsequent items in the ' +
107+
'ordered set MUST be composed of any combination of URLs and/or ' +
108+
'objects where each is processable as a JSON-LD Context."',
109+
async function() {
110+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Subsequent%20items%20in%20the%20ordered%20set%20MUST%20be%20composed%20of%20any%20combination%20of%20URLs%20and/or%20objects%2C%20where%20each%20is%20processable%20as%20a%20JSON%2DLD%20Context.`;
111+
await assert.doesNotReject(endpoints.issue(require(
112+
'../tests/input/credential-context-combo1-ok.json')),
113+
'Failed to support multiple `@context` URLs.');
114+
await assert.doesNotReject(endpoints.issue(require(
115+
'../tests/input/credential-context-combo2-ok.json')),
116+
'Failed to support objects in the `@context` Array.');
117+
await assert.rejects(endpoints.issue(require(
118+
'../tests/input/credential-context-combo3-fail.json')),
119+
120+
'Failed to reject a VC with an invalid `@context` URL.');
121+
await assert.rejects(endpoints.issue(require(
122+
'../tests/input/credential-context-combo4-fail.json')),
123+
124+
'Failed to reject a VC with an unsupported `@context` value type ' +
125+
'(number).');
126+
});
127+
it('Verifiable Presentation `@context`: "Subsequent items in the ' +
128+
'ordered set MUST be composed of any combination of URLs and/or ' +
129+
'objects where each is processable as a JSON-LD Context."',
130+
async function() {
131+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Subsequent%20items%20in%20the%20ordered%20set%20MUST%20be%20composed%20of%20any%20combination%20of%20URLs%20and/or%20objects%2C%20where%20each%20is%20processable%20as%20a%20JSON%2DLD%20Context.`;
132+
await assert.doesNotReject(
133+
endpoints.verifyVp(await createLocalVp({
134+
presentation:
135+
require('../tests/input/presentation-context-combo1-ok.json')
136+
})),
137+
'Failed to support multiple `@context` URLs in a VP.');
138+
await assert.doesNotReject(
139+
endpoints.verifyVp(await createLocalVp({
140+
presentation:
141+
require('../tests/input/presentation-context-combo2-ok.json')
142+
})),
143+
'Failed to support objects in the `@context` Array in a VP.');
144+
// first create a valid VP
145+
const vp = await createLocalVp({
146+
presentation: require('../tests/input/presentation-vc-ok.json')
147+
});
148+
// then inject incorrect `@context` values and test verification
149+
vp['@context'][1] = 'https://example.com';
150+
await assert.rejects(endpoints.verifyVp(vp),
151+
'Failed to reject a VP with an invalid `@context` URL.');
152+
vp['@context'][1] = 'https ://not-a-url/contexts/example/v1';
153+
await assert.rejects(endpoints.verifyVp(vp),
154+
'Failed to reject a VP with an invalid `@context` URL.');
155+
vp['@context'][1] = 123192875;
156+
await assert.rejects(endpoints.verifyVp(vp),
157+
'Failed to reject a VP with an unsupported `@context` value type ' +
158+
'(number).');
159+
});
160+
});
161+
}
162+
});

tmp/4.04-identifiers.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2022 - 2024 Digital Bazaar, Inc.
3+
*
4+
* SPDX-License-Identifier: LicenseRef-w3c-3-clause-bsd-license-2008 OR LicenseRef-w3c-test-suite-license-2023
5+
*/
6+
7+
import {addPerTestMetadata, setupMatrix} from '../tests/helpers.js';
8+
import assert from 'node:assert/strict';
9+
import chai from 'chai';
10+
import {createRequire} from 'module';
11+
import {filterByTag} from 'vc-test-suite-implementations';
12+
import {TestEndpoints} from '../tests/TestEndpoints.js';
13+
14+
// eslint-disable-next-line no-unused-vars
15+
const should = chai.should();
16+
17+
const require = createRequire(import.meta.url);
18+
19+
const tag = 'vc2.0';
20+
const {match} = filterByTag({tags: [tag]});
21+
22+
// 4.4 Identifiers https://w3c.github.io/vc-data-model/#identifiers
23+
describe('Identifiers', function() {
24+
setupMatrix.call(this, match);
25+
for(const [name, implementation] of match) {
26+
const endpoints = new TestEndpoints({implementation, tag});
27+
28+
describe(name, function() {
29+
beforeEach(addPerTestMetadata);
30+
31+
it('If present, the value of the id property MUST be a single URL, ' +
32+
'which MAY be dereferenceable.', async function() {
33+
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=If%20present%2C%20the%20value%20of%20the%20id%20property%20MUST%20be%20a%20single%20URL%2C%20which%20MAY%20be%20dereferenceable.`;
34+
await assert.doesNotReject(endpoints.issue(
35+
require('../tests/input/credential-id-other-ok.json')),
36+
'Failed to accept a VC with a DID credentialSubject identifier.');
37+
await assert.rejects(
38+
endpoints.issue(require(
39+
'../tests/input/credential-id-nonidentifier-fail.json')),
40+
41+
'Failed to reject a credential with a `null` identifier.');
42+
43+
await assert.doesNotReject(endpoints.issue(require(
44+
'../tests/input/credential-id-single-ok.json')),
45+
'Failed to accept a VC with a valid identifier.');
46+
await assert.doesNotReject(endpoints.issue(require(
47+
'../tests/input/credential-id-subject-single-ok.json')),
48+
'Failed to accept a VC with a valid credentialSubject identifier');
49+
await assert.rejects(endpoints.issue(require(
50+
'../tests/input/credential-id-multi-fail.json')),
51+
52+
'Failed to reject a VC with multiple `id` values.');
53+
await assert.rejects(endpoints.issue(require(
54+
'../tests/input/credential-id-subject-multi-fail.json')),
55+
56+
'Failed to reject a VC with multiple credentialSubject identifiers.');
57+
58+
await assert.rejects(
59+
endpoints.issue(require('../tests/input/credential-id-not-url-fail.json')),
60+
61+
'Failed to reject a credential with an invalid identifier.');
62+
});
63+
});
64+
}
65+
});

0 commit comments

Comments
 (0)