Skip to content

Check implementation ZCAP expirations. #126

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import {Implementation} from './Implementation.js';
import {implementerFiles} from '../implementations/index.js';

export const rawImplementations = implementerFiles;

const keyValues = implementerFiles.map(
implementation => [implementation.name, new Implementation(implementation)]);

Expand All @@ -27,7 +29,7 @@
* @param {Function<boolean>} options.filter - A function to
* filter the map's entries, that returns true or false.
*
* @returns {Object<string, Map>} Returns an object with matching

Check warning on line 32 in lib/main.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
* and non-matching maps.
*/
export const filterImplementations = ({
Expand Down Expand Up @@ -59,7 +61,7 @@
* @param {string} [options.property='issuers'] - The property to search for on
* an implementation.
*
* @returns {Object<string, Map>} Returns an object with matching

Check warning on line 64 in lib/main.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
* and non-matching maps.
*/
export const filterByTag = ({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"devDependencies": {
"chai": "^4.3.3",
"chai-datetime": "^1.8.1",
"cross-env": "^7.0.3",
"eslint": "^8.55.0",
"eslint-config-digitalbazaar": "^5.0.1",
Expand Down
13 changes: 0 additions & 13 deletions test/Example.spec.js

This file was deleted.

69 changes: 69 additions & 0 deletions test/implementations.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import chai from 'chai';
import chaiDateTime from 'chai-datetime';
const should = chai.should();
chai.use(chaiDateTime);

import {allImplementations, rawImplementations} from '../lib/main.js';

describe('Loading implementations', () => {
it('should result in no errors.', async () => {
should.exist(allImplementations);
});

describe('Implementations using DID:key identifiers', () => {
allImplementations.forEach(implementation => {
const {issuers, verifiers} = implementation;

const isDidKeyFilter = ({settings: {id}}) =>
id && id.startsWith('did:key');

describe(implementation.settings.name, () => {
issuers?.filter(isDidKeyFilter)
.map(({settings: {id}}, index) => {
describe(`issuer[${index}].id`, () => {
it('should not specify a fragment', () => {
chai.expect(id).not.match(/#/);
});
});
});

verifiers?.filter(isDidKeyFilter)
.map(({settings: {id}}, index) => {
describe(`verifier[${index}].id`, () => {
it('should not specify a fragment', () => {
chai.expect(id).not.match(/#/);
});
});
});
});
});
});

describe('Implementations using ZCAPs', () => {
rawImplementations.forEach(implementation => {
Object.keys(implementation)
.filter(key => Array.isArray(implementation[key]))
.forEach(implementationType => {
describe(`${implementation.name} - ${implementationType}`, () => {
implementation[implementationType]
?.filter(({zcap}) => zcap?.capability)
.forEach(issuer => {
it(`ZCAP should not be expired for ${issuer.id}`, () => {
const expiration = JSON.parse(issuer.zcap.capability).expires;
const today = new Date();
const nextMonth = new Date(
today.getFullYear(), today.getMonth() + 1, today.getDate());
chai.expect(new Date(expiration)).to.be.afterDate(nextMonth);
});
});
});
});
});
});
});