Skip to content

Commit

Permalink
Date checks return datetime verbatim & use seconds in test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Dec 6, 2023
1 parent d8f75b1 commit f8099c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,13 @@ export function _checkCredential({
}
// check if `now` is before `issuanceDate` on verification
if(mode === 'verify') {
let {issuanceDate} = credential;
assertDateString({credential, prop: 'issuanceDate'});
// check if `now` is before `issuanceDate`
issuanceDate = new Date(issuanceDate);
const issuanceDate = new Date(credential.issuanceDate);
if(now < issuanceDate) {
throw new Error(
`The current date time (${now.toISOString()}) is before the ` +
`"issuanceDate" (${issuanceDate.toISOString()}).`);
`"issuanceDate" (${credential.issuanceDate}).`);
}
}
}
Expand All @@ -634,7 +633,7 @@ export function _checkCredential({
if(now > validUntil) {
throw new Error(
`The current date time (${now.toISOString()}) is after ` +
`"validUntil" (${validUntil.toISOString()}).`);
`"validUntil" (${credential.validUntil}).`);
}
}
if(validFrom) {
Expand All @@ -644,7 +643,7 @@ export function _checkCredential({
if(now < validFrom) {
throw new Error(
`The current date time (${now.toISOString()}) is before ` +
`"validFrom" (${validFrom.toISOString()}).`);
`"validFrom" (${credential.validFrom}).`);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ for(const [version, mockCredential] of versionedCredentials) {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.issuanceDate = createSkewedTimeStamp({skewYear: 1});
const now = createSkewedTimeStamp({skewYear: 0});
const now = new Date();
let error;
try {
vc._checkCredential({credential, now});
Expand All @@ -794,7 +794,7 @@ for(const [version, mockCredential] of versionedCredentials) {
should.exist(error,
'Should throw error when "now" is before "issuanceDate"');
error.message.should.contain(
`The current date time (${now}) is before the ` +
`The current date time (${now.toISOString()}) is before the ` +
`"issuanceDate" (${credential.issuanceDate}).`);
});
}
Expand Down
3 changes: 2 additions & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
*/
export function createSkewedTimeStamp({date = new Date(), skewYear}) {
date.setFullYear(date.getFullYear() + skewYear);
return date.toISOString();
const isoString = date.toISOString();
return isoString.substr(0, isoString.length - 5) + 'Z';
}

0 comments on commit f8099c3

Please sign in to comment.