Skip to content

Commit

Permalink
Move proofChain tests into optional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Sep 24, 2024
1 parent 7038619 commit da5d08c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
35 changes: 18 additions & 17 deletions suites/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,6 @@ export function runDataIntegrityProofFormatTests({
shouldHaveProofValue({proof, expectedPrefix, encodingName});
}
});
it('If "proof.previousProof" property exists, it MUST be a string value ' +
'or unordered list of string values.',
function() {
for(const proof of proofs) {
if(proof.previousProof) {
proof.previousProof.should.be.
oneOf(['string', 'object'], 'Expected ' +
'"proof.previousProof" to be a string or an array.');
if(typeof proof.previousProof === 'object') {
for(const previousProof in proof.previousProof) {
previousProof.should.be.a('string', 'Expected ' +
'"previousProof" items to be a string.');
}
}
}
}
});
it('Cryptographic suite designers MUST use mandatory proof value ' +
'properties defined in Section 2.1 Proofs, and MAY define other ' +
'properties specific to their cryptographic suite.', async function() {
Expand Down Expand Up @@ -420,6 +403,24 @@ export function runDataIntegrityProofFormatTests({
}
});
}
if(optionalTests.proofChain) {
it('If "proof.previousProof" property exists, it MUST be a string ' +
'value or unordered list of string values.', function() {
for(const proof of proofs) {
if(proof.previousProof) {
proof.previousProof.should.be.
oneOf(['string', 'object'], 'Expected ' +
'"proof.previousProof" to be a string or an array.');
if(typeof proof.previousProof === 'object') {
for(const previousProof in proof.previousProof) {
previousProof.should.be.a('string', 'Expected ' +
'"previousProof" items to be a string.');
}
}
}
}
});
}
});
}

94 changes: 49 additions & 45 deletions suites/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,6 @@ export function runDataIntegrityProofVerifyTests({
before(async function() {
proofValueTests = shouldBeProofValue({credentials, verifier});
});
it('An OPTIONAL string value (proof.previousProof) or unordered list of ' +
'string values. Each value identifies another data integrity proof that ' +
'MUST verify before the current proof is processed.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=An%20OPTIONAL%20string%20value%20or%20unordered%20list%20of%20string%20values.%20Each%20value%20identifies%20another%20data%20integrity%20proof%20that%20MUST%20verify%20before%20the%20current%20proof%20is%20processed';
await verificationSuccess({
credential: credentials.clone('previousProofString'),
verifier,
reason: 'Should verify VC with a string "proof.previousProof".'
});
await verificationSuccess({
credential: credentials.clone('previousProofArray'),
verifier,
reason: 'Should verify VC with an Array "proof.previousProof".'
});
});
it('If an unordered list (proof), all referenced proofs in ' +
'the array MUST verify.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20an%20unordered%20list%2C%20all%20referenced%20proofs%20in%20the%20array%20MUST%20verify';
await verificationSuccess({
credential: credentials.clone('proofSet'),
verifier,
reason: 'Should verify VC with multiple proofs.'
});
});
it('If a proof with id equal to previousProof does not exist in ' +
'allProofs, an error MUST be raised and SHOULD convey an error type ' +
'of PROOF_GENERATION_ERROR.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20a%20proof%20with%20id%20equal%20to%20previousProof%20does%20not%20exist%20in%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
await verificationFail({
credential: credentials.clone('missingPreviousProofString'),
verifier,
reason: 'Should not verify VC with invalid "proof.previousProof".'
});
});
it('If any element of previousProof list has an id attribute that does ' +
'not match the id attribute of any element of allProofs, an error MUST ' +
'be raised and SHOULD convey an error type of PROOF_GENERATION_ERROR.',
async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20any%20element%20of%20previousProof%20list%20has%20an%20id%20attribute%20that%20does%20not%20match%20the%20id%20attribute%20of%20any%20element%20of%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
await verificationFail({
credential: credentials.clone('missingPreviousProofArray'),
verifier,
reason: 'Should not verify VC with invalid "proof.previousProof".'
});
});
it('When deserializing to RDF, implementations MUST ensure that the ' +
'base URL is set to null.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#securing-data-losslessly:~:text=When%20deserializing%20to%20RDF%2C%20implementations%20MUST%20ensure%20that%20the%20base%20URL%20is%20set%20to%20null.';
Expand Down Expand Up @@ -272,6 +227,55 @@ export function runDataIntegrityProofVerifyTests({
});
});
}
if(optionalTests.proofChain) {
it('An OPTIONAL string value (proof.previousProof) or unordered list ' +
'of string values. Each value identifies another data integrity proof ' +
'that MUST verify before the current proof is processed.',
async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=An%20OPTIONAL%20string%20value%20or%20unordered%20list%20of%20string%20values.%20Each%20value%20identifies%20another%20data%20integrity%20proof%20that%20MUST%20verify%20before%20the%20current%20proof%20is%20processed';
await verificationSuccess({
credential: credentials.clone('previousProofString'),
verifier,
reason: 'Should verify VC with a string "proof.previousProof".'
});
await verificationSuccess({
credential: credentials.clone('previousProofArray'),
verifier,
reason: 'Should verify VC with an Array "proof.previousProof".'
});
});
it('If an unordered list (proof), all referenced proofs in ' +
'the array MUST verify.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20an%20unordered%20list%2C%20all%20referenced%20proofs%20in%20the%20array%20MUST%20verify';
await verificationSuccess({
credential: credentials.clone('proofSet'),
verifier,
reason: 'Should verify VC with multiple proofs.'
});
});
it('If a proof with id equal to previousProof does not exist in ' +
'allProofs, an error MUST be raised and SHOULD convey an error type ' +
'of PROOF_GENERATION_ERROR.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20a%20proof%20with%20id%20equal%20to%20previousProof%20does%20not%20exist%20in%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
await verificationFail({
credential: credentials.clone('missingPreviousProofString'),
verifier,
reason: 'Should not verify VC with invalid "proof.previousProof".'
});
});
it('If any element of previousProof list has an id attribute that does ' +
'not match the id attribute of any element of allProofs, an error MUST ' +
'be raised and SHOULD convey an error type of PROOF_GENERATION_ERROR.',
async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20any%20element%20of%20previousProof%20list%20has%20an%20id%20attribute%20that%20does%20not%20match%20the%20id%20attribute%20of%20any%20element%20of%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
await verificationFail({
credential: credentials.clone('missingPreviousProofArray'),
verifier,
reason: 'Should not verify VC with invalid "proof.previousProof".'
});
});

}
});
}

Expand Down

0 comments on commit da5d08c

Please sign in to comment.