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

Add tests for interactions between validUntil and validFrom #55

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add a new test to ensure type URLs are treated as an unordered set.
- Add new tests for `issuer.description` including Internationalization settings.
- Add new tests for `issuer.id` as a url and not a url.
- Add tests for interactions between `validFrom ` and `validUntil`.

## 1.0.0 - 2023-11-10

Expand Down
50 changes: 49 additions & 1 deletion tests/10-vcdm2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
createRequestBody,
createVerifyRequestBody
} from './mock.data.js';
import {createTimeStamp, proveVP} from './data-generator.js';
import assert from 'node:assert/strict';
import {createRequire} from 'module';
import {filterByTag} from 'vc-api-test-suite-implementations';
import http from 'http';
import {proveVP} from './data-generator.js';
import {randomFillSync} from 'node:crypto';
import receiveJson from './receive-json.js';

Expand Down Expand Up @@ -384,6 +384,54 @@ describe('Verifiable Credentials Data Model v2.0', function() {
await assert.rejects(
issue(require('./input/credential-validuntil-invalid-fail.json')));
});
it2('If a validUntil value also exists, the validFrom value MUST ' +
'express a datetime that is temporally the same or earlier than the ' +
'datetime expressed by the validUntil value.', async function() {
const positiveTest = require(
'./input/credential-validUntil-validFrom-ok.json');
positiveTest.validFrom = createTimeStamp({skew: -2});
positiveTest.validUntil = createTimeStamp({skew: 2});
await issue(positiveTest);
const negativeTest = require(
'./input/credential-validUntil-validFrom-fail.json');
negativeTest.validFrom = createTimeStamp({skew: 2});
negativeTest.validUntil = createTimeStamp({skew: -2});
let error;
let result;
try {
result = await issue(negativeTest);
} catch(e) {
error = e;
}
if(error) {
return;
}
assert.rejects(verify(result));
});
it2('If a validFrom value also exists, the validUntil value MUST ' +
'express a datetime that is temporally the same or later than the ' +
'datetime expressed by the validFrom value.', async function() {
const positiveTest = require(
'./input/credential-validUntil-validFrom-ok.json');
positiveTest.validFrom = createTimeStamp({skew: -2});
positiveTest.validUntil = createTimeStamp({skew: 2});
await issue(positiveTest);
const negativeTest = require(
'./input/credential-validUntil-validFrom-fail.json');
negativeTest.validFrom = createTimeStamp({skew: 2});
negativeTest.validUntil = createTimeStamp({skew: -2});
let error;
let result;
try {
result = await issue(negativeTest);
} catch(e) {
error = e;
}
if(error) {
return;
}
assert.rejects(verify(result));
});
// FIXME remove as this doesn't seem to be in the spec
it.skip('At least one proof mechanism, and the details necessary ' +
'to evaluate that proof, MUST be expressed for a credential or ' +
Expand Down
6 changes: 6 additions & 0 deletions tests/data-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ export async function proveVP({presentation, options = {}}) {
...options
});
}

export function createTimeStamp({date = new Date(), skew = 0}) {
date.setFullYear(date.getFullYear() + skew);
const isoString = date.toISOString();
return `${isoString.substring(0, isoString.length - 5)}Z`;
}
14 changes: 14 additions & 0 deletions tests/input/credential-validUntil-validFrom-fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": [
"https://www.w3.org/ns/credentials/v2"
],
"type": [
"VerifiableCredential"
],
"issuer": "did:example:issuer",
"validFrom": "FUTURE DATE",
"validUntil": "PAST DATE",
"credentialSubject": {
"id": "did:example:subject"
}
}
14 changes: 14 additions & 0 deletions tests/input/credential-validUntil-validFrom-ok.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": [
"https://www.w3.org/ns/credentials/v2"
],
"type": [
"VerifiableCredential"
],
"issuer": "did:example:issuer",
"validFrom": "PAST DATE",
"validUntil": "FUTURE DATE",
"credentialSubject": {
"id": "did:example:subject"
}
}