Skip to content

Commit

Permalink
Rename verify validUntil & validAfter & add more tests for both state…
Browse files Browse the repository at this point in the history
…ments.
  • Loading branch information
aljones15 committed Nov 28, 2023
1 parent 4a62c7b commit c478bbc
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ for(const [version, mockCredential] of versionedCredentials) {
});
}
if(version === 2.0) {
it('should NOT verify "validFrom" in the future', () => {
it('should reject "validFrom" in the future', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-10-30T19:21:25Z';
Expand All @@ -788,7 +788,7 @@ for(const [version, mockCredential] of versionedCredentials) {
should.exist(error,
'Should throw error when verifying "validFrom" in future');
});
it('should verify "validFrom" in the past', () => {
it('should reject "validFrom" in the past', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-06-30T19:21:25Z';
Expand All @@ -802,7 +802,7 @@ for(const [version, mockCredential] of versionedCredentials) {
should.not.exist(error,
'Should not throw error when "validFrom" in past');
});
it('should NOT verify if "validUntil" in the past', () => {
it('should reject "validUntil" in the past', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validUntil = '2022-06-31T19:21:25Z';
Expand All @@ -816,7 +816,7 @@ for(const [version, mockCredential] of versionedCredentials) {
should.exist(error,
'Should throw error when "validUntil" in the past');
});
it('should verify if "validUntil" in the future', () => {
it('should reject "validUntil" in the future', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validUntil = '2025-10-31T19:21:25Z';
Expand All @@ -830,7 +830,7 @@ for(const [version, mockCredential] of versionedCredentials) {
should.not.exist(error,
'Should not throw error when "issuanceDate" is valid');
});
it('should verify if "validFrom" is before "validUntil"', () => {
it('should accept if now is between "validFrom" & "validUntil"', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-05-30T19:21:25Z';
Expand All @@ -845,6 +845,37 @@ for(const [version, mockCredential] of versionedCredentials) {
should.not.exist(error,
'Should NOT throw when now is between "validFrom" & "validUntil"');
});
it('should reject if now is after "validFrom" & "validUntil"', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2022-05-30T19:21:25Z';
credential.validUntil = '2023-05-30T19:21:25Z';
const now = '2024-06-30T19:21:25Z';
let error;
try {
vc._checkCredential({credential, now});
} catch(e) {
error = e;
}
should.exist(error,
'Should throw when now is after "validFrom" & "validUntil"');
});
it('should reject if now is before "validFrom" & "validUntil"', () => {
const credential = jsonld.clone(mockCredential);
credential.issuer = 'did:example:12345';
credential.validFrom = '2024-05-30T19:21:25Z';
credential.validUntil = '2025-05-30T19:21:25Z';
const now = '2023-06-30T19:21:25Z';
let error;
try {
vc._checkCredential({credential, now});
} catch(e) {
error = e;
}
should.exist(error,
'Should throw when now is before "validFrom" & "validUntil"');
});

}
it('should reject if "credentialSubject" is empty', () => {
const credential = jsonld.clone(mockCredential);
Expand Down

0 comments on commit c478bbc

Please sign in to comment.