Skip to content

Commit

Permalink
Add test that asserts on baseProof component length.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Jul 10, 2024
1 parent 2d86515 commit b22274e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ export const shouldNotUseCborTags = ({proof}) => {
should.exist(result, 'Expected proof to be decoded.');
};

export const baseProofShouldHaveElementCount = ({
proof,
expectedLengths = [5, 6],
reason = 'Expected baseProof to have expected number of components'
}) => {
let error;
let result;
try {
// try to parse the base proof with no cbor tags
result = parseBaseProofValue({proof});
} catch(e) {
error = e;
}
should.not.exist(error, 'Expected proof to decode.');
should.exist(result, 'Expected proof to be decoded.');
Object.keys(result).length.should.be.oneOf(expectedLengths, reason);
};

export const shouldHaveMandatoryPointers = ({proof}) => {
const {mandatoryPointers} = parseBaseProofValue({proof});
should.exist(mandatoryPointers, 'Expected "mandatoryPointers" to exist.');
Expand Down
12 changes: 12 additions & 0 deletions tests/suites/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
import {
baseProofShouldHaveElementCount,
checkEncoding,
checkHmacKeyLength,
shouldBeMultibaseEncoded,
Expand Down Expand Up @@ -267,6 +268,17 @@ export function createSuite({
shouldHaveMandatoryPointers({proof});
}
});
it('Initialize components to an array that is the result of ' +
'CBOR-decoding the bytes that follow the three-byte BBS disclosure ' +
'proof header. If the result is not an array of five or six elements ' +
'— a byte array, a map of integers to integers, two arrays of ' +
'integers, and one or two byte arrays; an error MUST be raised and ' +
'SHOULD convey an error type of PROOF_VERIFICATION_ERROR.', function() {
this.test.link = 'https://w3c.github.io/vc-di-bbs/#:~:text=%22pseudonym_hidden_pid%22.-,Initialize%20components%20to%20an%20array%20that%20is%20the%20result%20of%20CBOR,be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_VERIFICATION_ERROR.,-Replace%20the%20second';
for(const proof of bbsProofs) {
baseProofShouldHaveElementCount({proof});
}
});
});
}
});
Expand Down

0 comments on commit b22274e

Please sign in to comment.