diff --git a/tests/assertions.js b/tests/assertions.js index c8bbe3f..d8d01fa 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -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.'); diff --git a/tests/suites/create.js b/tests/suites/create.js index efc7f32..c5de976 100644 --- a/tests/suites/create.js +++ b/tests/suites/create.js @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ import { + baseProofShouldHaveElementCount, checkEncoding, checkHmacKeyLength, shouldBeMultibaseEncoded, @@ -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}); + } + }); }); } });