Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(7) Add invalid date test #33

Merged
merged 8 commits into from
Jul 3, 2024
12 changes: 10 additions & 2 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as base64url from 'base64url-universal';
import {
allowUnsafeCanonize,
invalidCborEncoding,
invalidStringEncoding
invalidStringEncoding,
passCreated
} from './vc-generator/generators.js';
import {
deriveCredentials,
Expand Down Expand Up @@ -130,7 +131,8 @@ export async function verifySetup({credentials, keyTypes, suite}) {
suiteName: suite,
keys
});
const {mandatory} = generators;
const {mandatory, created} = generators;
const {invalidCreated} = created;
const {invalidCryptosuite, invalidProofType} = mandatory;
disclosed.invalid.proofTypeAndCryptosuite =
await deriveCredentials({
Expand Down Expand Up @@ -207,6 +209,12 @@ export async function verifySetup({credentials, keyTypes, suite}) {
}
}
disclosed.invalid.valuePrefix = valuePrefix;
disclosed.invalid.created = await deriveCredentials({
keys,
vectors: transformVectors(subjectNestedObjects),
suiteName: suite,
generators: [invalidCreated, passCreated]
});
return {
base,
disclosed
Expand Down
8 changes: 8 additions & 0 deletions tests/suites/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ export function verifySuite({
verifier
});
});
it('If proofConfig.created is set and if the value is not a valid ' +
TallTed marked this conversation as resolved.
Show resolved Hide resolved
'[XMLSCHEMA11-2] datetime, 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-di-bbs/#:~:text=If%20proofConfig.created%20is%20set%20and%20if%20the%20value%20is%20not%20a%20valid%20%5BXMLSCHEMA11%2D2%5D%20datetime%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
const credential = cloneTestVector(disclosed?.invalid?.created);
//FIXME assert on error code or message when available
await verificationFail({credential, verifier});
});
it('MUST fail to verify a base proof.', async function() {
const credential = cloneTestVector(base);
await verificationFail({credential, verifier});
Expand Down
8 changes: 8 additions & 0 deletions tests/vc-generator/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export function allowUnsafeCanonize({suite, selectiveSuite, ...args}) {
return {...args, suite, selectiveSuite};
}

export function passCreated({suite, ...args}) {
suite._cryptosuite = stubMethods({
object: suite._cryptosuite,
stubs: {createVerifyData: stubs.stubVerifyData({deleteCreated: false})},
});
return {...args, suite};
}

export function invalidStringEncoding({suite, selectiveSuite, ...args}) {
suite._cryptosuite = stubMethods({
object: suite._cryptosuite,
Expand Down
1 change: 1 addition & 0 deletions tests/vc-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export async function deriveCredentials({
suite: getSuite({suite: suiteName, signer, mandatoryPointers}),
selectiveSuite: getSuite({suite: suiteName, signer, selectivePointers}),
credential: _credential,
// add the ability to overwrite the defaults
...initialParams
};
// call each generator on itself to produce accumulated invalid suites
Expand Down