Skip to content

Commit

Permalink
Add invalidExpires gen & test.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Sep 6, 2024
1 parent 619753c commit e820614
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 14 additions & 2 deletions suites/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,20 @@ export function runDataIntegrityProofVerifyTests({
'at the end of the value, or with a time zone offset relative ' +
'to UTC.', async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=MUST%20be%20specified%20as%20an%20%5BXMLSCHEMA11%2D2%5D%20dateTimeStamp%20string%2C%20either%20in%20Universal%20Coordinated%20Time%20(UTC)%2C%20denoted%20by%20a%20Z%20at%20the%20end%20of%20the%20value%2C%20or%20with%20a%20time%20zone%20offset%20relative%20to%20UTC';
const credential = credentials.clone('invalidCreated');
await verificationFail({credential, verifier});
await verificationFail({
credential: credentials.clone('invalidCreated'),
verifier
});
});
it('If present (expires), it MUST be an [XMLSCHEMA11-2] dateTimeStamp ' +
'string, either in Universal Coordinated Time (UTC), denoted by a Z ' +
'at the end of the value, or with a time zone offset relative to UTC.',
async function() {
this.test.link = 'https://w3c.github.io/vc-data-integrity/#proofs:~:text=If%20present%2C%20it%20MUST%20be%20an%20%5BXMLSCHEMA11%2D2%5D%20dateTimeStamp%20string%2C%20either%20in%20Universal%20Coordinated%20Time%20(UTC)%2C%20denoted%20by%20a%20Z%20at%20the%20end%20of%20the%20value%2C%20or%20with%20a%20time%20zone%20offset%20relative%20to%20UTC.';
await verificationFail({
credential: credentials.clone('invalidExpires'),
verifier
});
});
// we can't tell if its interpreted correctly but we can ensure their
// verifier at least takes timestamps without Z or an offset.
Expand Down
26 changes: 20 additions & 6 deletions vc-generator/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const generators = {
noOffsetCreated,
noOffsetExpires,
invalidCreated,
invalidExpires,
createdOneYearAgo
},
// creates test vectors for Authentication Purpose tests
Expand Down Expand Up @@ -173,13 +174,23 @@ function noVerificationMethod({suite, selectiveSuite, credential, ...args}) {
return {...args, suite, selectiveSuite, credential};
}

function invalidCreated({suite, selectiveSuite, credential, ...args}) {
function invalidCreated({suite, selectiveSuite, ...args}) {
// suite.date will be used as created when signing
suite.date = 'invalidDate';
if(selectiveSuite) {
selectiveSuite.date = 'invalidDate';
}
return {...args, suite, selectiveSuite, credential};
return {...args, suite, selectiveSuite};
}

function invalidExpires({suite, selectiveSuite, ...args}) {
suite.proof = suite.proof || {};
suite.proof.expires = 'invalidDate';
if(selectiveSuite) {
selectiveSuite.proof = selectiveSuite.proof || {};
selectiveSuite.proof.expires = 'invalidDate';
}
return {...args, suite, selectiveSuite};
}

function createdOneYearAgo({
Expand Down Expand Up @@ -214,7 +225,8 @@ function invalidProofType({
suite.type = proofType;
if(selectiveSuite) {
const proofId = 'urn:uuid:no-proof-type-test';
suite.proof = {id: proofId};
suite.proof = suite.proof || {};
suite.proof.id = proofId;
selectiveSuite._cryptosuite.options.proofId = proofId;
selectiveSuite.type = proofType;
}
Expand Down Expand Up @@ -252,11 +264,13 @@ function noOffsetCreated({suite, selectiveSuite, ...args}) {
}

function noOffsetExpires({suite, selectiveSuite, ...args}) {
const expires = new Date().toISOString().replace(/\.\d+Z$/, '');
// lop off ms precision from ISO timestamp
suite.proof = {expires};
const expires = new Date().toISOString().replace(/\.\d+Z$/, '');
suite.proof = suite.proof || {};
suite.proof.expires = expires;
if(selectiveSuite) {
selectiveSuite.proof = {...suite.proof, ...selectiveSuite.proof};
selectiveSuite.proof = selectiveSuite.proof || {};
selectiveSuite.proof.expires = expires;
}
return {...args, suite, selectiveSuite};
}
Expand Down

0 comments on commit e820614

Please sign in to comment.