From f8099c3a48a55b22e62ebc4fc8ef29f1509f5ad5 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 4 Dec 2023 20:07:24 +0000 Subject: [PATCH] Date checks return datetime verbatim & use seconds in test data. --- lib/index.js | 9 ++++----- test/10-verify.spec.js | 4 ++-- test/helpers.js | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index b69d61eb..0ee1fa58 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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}).`); } } } @@ -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) { @@ -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}).`); } } } diff --git a/test/10-verify.spec.js b/test/10-verify.spec.js index e3fbfd76..a9a40543 100644 --- a/test/10-verify.spec.js +++ b/test/10-verify.spec.js @@ -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}); @@ -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}).`); }); } diff --git a/test/helpers.js b/test/helpers.js index 3648836d..f5e51ef0 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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'; }