Skip to content

Commit

Permalink
improve related resources
Browse files Browse the repository at this point in the history
Signed-off-by: PatStLouis <[email protected]>
  • Loading branch information
PatStLouis authored and BigBlueHat committed Dec 17, 2024
1 parent cf38ee1 commit 2c61b4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
51 changes: 37 additions & 14 deletions tests/5-advanced-concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import {addPerTestMetadata, setupMatrix} from './helpers.js';
import {credential, relatedResource} from './fixtures.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createRequire} from 'module';
Expand All @@ -22,6 +23,8 @@ const {match} = filterByTag({tags: [tag]});
// 5. Advanced Concepts https://w3c.github.io/vc-data-model/#advanced-concepts
describe('Advanced Concepts', function() {
setupMatrix.call(this, match);
let positiveFixture;
let negativeFixture;
for(const [name, implementation] of match) {
const endpoints = new TestEndpoints({implementation, tag});

Expand Down Expand Up @@ -55,20 +58,40 @@ describe('Advanced Concepts', function() {
it('The value of the relatedResource property MUST be one or more ' +
'objects of the following form:', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#integrity-of-related-resources:~:text=The%20value%20of%20the%20relatedResource%20property%20MUST%20be%20one%20or%20more%20objects%20of%20the%20following%20form%3A`;
await assert.doesNotReject(endpoints.issue(require(
'./input/relatedResource/relatedResource-digest-sri-ok.json'
)), 'Failed to accept a VC with valid relatedResource objects.');
await assert.doesNotReject(endpoints.issue(require(
'./input/relatedResource/relatedResource-digest-multibase-ok.json'
)), 'Failed to accept a VC with valid relatedResource objects.');
await assert.doesNotReject(endpoints.issue(require(
'./input/relatedResource/relatedResource-with-mediaType-ok.json'
)),
'Failed to accept a VC with valid relatedResource.mediaType values.');
await assert.rejects(endpoints.issue(require(
'./input/relatedResource/relatedResource-list-of-strings-fail.json'
)),
'Failed to reject a VC with a relatedResource as an array of strings.');

positiveFixture = structuredClone(credential);

// digestSRI positive test
positiveFixture.relatedResource = {
id: relatedResource.id,
digestSRI: relatedResource.digestSRI,
};
await assert.doesNotReject(endpoints.issue(positiveFixture),
'Failed to accept a VC with valid relatedResource objects.');

// digestMultibase positive test
positiveFixture.relatedResource = {
id: relatedResource.id,
digestMultibase: relatedResource.digestMultibase,
};
await assert.doesNotReject(endpoints.issue(positiveFixture),
'Failed to accept a VC with valid relatedResource objects.');

// mediaType positive test
positiveFixture.relatedResource = [{
id: relatedResource.id,
mediaType: relatedResource.mediaType,
digestSRI: relatedResource.digestSRI,
}];
await assert.doesNotReject(endpoints.issue(positiveFixture),
'Failed to accept a VC with valid relatedResource mediaType.');

negativeFixture = structuredClone(credential);
negativeFixture.relatedResource = [{
id: relatedResource.id,
}];
await assert.rejects(endpoints.issue(negativeFixture),
'Failed to reject a VC with a relatedResource as an array of strings.');
});
it('The identifier for the resource is REQUIRED and conforms to the ' +
'format defined in Section 4.4 Identifiers.', async function() {
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ export const envelopedPresentation = {
type: 'EnvelopedVerifiablePresentation',
id: `data:application/vp+jwt,${vp_jwt}`
};

export const relatedResource = {
id: 'https://www.w3.org/ns/credentials/v2',
mediaType: 'application/ld+json',
digestSRI: 'sha256-24a18c90e9856d526111f29376e302d970b2bd10182e33959995b0207d7043b9',
digestMultibase: 'uMjRhMThjOTBlOTg1NmQ1MjYxMTFmMjkzNzZlMzAyZDk3MGIyYmQxMDE4MmUzMzk1OTk5NWIwMjA3ZDcwNDNiOQ',
};

0 comments on commit 2c61b4a

Please sign in to comment.