Skip to content

Commit

Permalink
Further consolidate and refactor test suite code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Jul 10, 2024
1 parent 12da53d commit e944a75
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 111 deletions.
120 changes: 52 additions & 68 deletions test/mocha/20-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,27 @@ import {
} from './assertions/testTerseBitstringStatusList.js';

describe('issue', () => {
describe('eddsa-rdfc-2022', () => {
const options = {
const suites = {
'eddsa-rdfc-2022': {
suiteName: 'eddsa-rdfc-2022',
algorithm: 'Ed25519',
issueOptions: {},
statusOptions: {}
};
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);

// to reduce runtime and because a different suite should not change
// the results, only this suite runs against these tests
testIssueWithOAuth2(options);
testIssueCrashRecovery(options);
testStatusScaling(options);
});

describe('ecdsa-rdfc-2019, P-256', () => {
const options = {
statusOptions: {},
tags: ['general']
},
'ecdsa-rdfc-2019, P-256': {
suiteName: 'ecdsa-rdfc-2019',
algorithm: 'P-256',
issueOptions: {},
statusOptions: {}
};
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});

describe('ecdsa-rdfc-2019, P-384', () => {
const options = {
},
'ecdsa-rdfc-2019, P-384': {
suiteName: 'ecdsa-rdfc-2019',
algorithm: 'P-384',
issueOptions: {},
statusOptions: {}
};
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});

describe('ecdsa-sd-2023', () => {
const options = {
},
'ecdsa-sd-2023': {
suiteName: 'ecdsa-sd-2023',
algorithm: 'P-256',
issueOptions: {},
Expand All @@ -65,15 +42,10 @@ describe('issue', () => {
suiteName: 'ecdsa-rdfc-2019',
algorithm: 'P-256'
},
terseIssueOptions: {mandatoryPointers: ['/issuer']}
};
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});

describe('bbs-2023', () => {
const options = {
terseIssueOptions: {mandatoryPointers: ['/issuer']},
tags: ['sd']
},
'bbs-2023': {
suiteName: 'bbs-2023',
algorithm: 'Bls12381G2',
issueOptions: {},
Expand All @@ -82,16 +54,10 @@ describe('issue', () => {
suiteName: 'ecdsa-rdfc-2019',
algorithm: 'P-256'
},
terseIssueOptions: {mandatoryPointers: ['/issuer']}
};
testIssueWithoutStatus(options);
testIssueSd(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});

describe('ecdsa-xi-2023, P-256', () => {
const options = {
terseIssueOptions: {mandatoryPointers: ['/issuer']},
tags: ['sd']
},
'ecdsa-xi-2023': {
suiteName: 'ecdsa-xi-2023',
algorithm: 'P-256',
issueOptions: {
Expand All @@ -101,24 +67,42 @@ describe('issue', () => {
// sign status list with simple ECDSA
suiteName: 'ecdsa-rdfc-2019',
algorithm: 'P-256'
}
};

testIssueWithoutStatus(options);
testIssueXi(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});

describe('Ed25519Signature2020', () => {
const options = {
},
tags: ['xi']
},
Ed25519Signature2020: {
suiteName: 'Ed25519Signature2020',
algorithm: 'Ed25519',
issueOptions: {},
statusOptions: {}
};
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);
});
}
};

for(const name in suites) {
const options = suites[name];
describe(name, () => {
// these tests run for every suite
testIssueWithoutStatus(options);
testBitstringStatusList(options);
testTerseBitstringStatusList(options);

// to reduce runtime and because a different suite should not change
// the results, only suites marked "general" run these tests
if(options.tags?.includes('general')) {
testIssueWithOAuth2(options);
testIssueCrashRecovery(options);
testStatusScaling(options);
}

// tests that run for SD suites only
if(options.tags?.includes('sd')) {
testIssueSd(options);
}

// tests that run for XI suites only
if(options.tags?.includes('xi')) {
testIssueXi(options);
}
});
}
});
File renamed without changes.
2 changes: 1 addition & 1 deletion test/mocha/assertions/issueWithoutStatus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as assertions from './assertions.js';
import * as assertions from './index.js';
import * as helpers from '../helpers.js';
import {createRequire} from 'node:module';
import {klona} from 'klona';
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/assertions/testBitstringStatusList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as assertions from './assertions.js';
import * as assertions from './index.js';
import * as helpers from '../helpers.js';
import {createRequire} from 'node:module';
import {klona} from 'klona';
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/assertions/testIssueSd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as assertions from './assertions.js';
import * as assertions from './index.js';
import * as helpers from '../helpers.js';
import {createRequire} from 'node:module';
import {klona} from 'klona';
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/assertions/testIssueXi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as assertions from './assertions.js';
import * as assertions from './index.js';
import * as helpers from '../helpers.js';
import {createRequire} from 'node:module';
import {encode} from 'base64url-universal';
Expand Down
74 changes: 35 additions & 39 deletions test/mocha/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,9 @@ export async function provisionDependencies({
// key already set
continue;
}
let assertionMethodKey;
if(['P-256', 'P-384', 'Bls12381G2'].includes(algorithm)) {
assertionMethodKey = await _generateMultikey({
keystoreAgent,
type: `urn:webkms:multikey:${algorithm}`,
publicAliasTemplate
});
} else {
assertionMethodKey = await keystoreAgent.generateKey({
type: 'asymmetric',
publicAliasTemplate
});
}
suite.assertionMethodKey = assertionMethodKey;
suite.assertionMethodKey = await generateAsymmetricKey({
keystoreAgent, algorithm, publicAliasTemplate
});
}

if(zcaps) {
Expand Down Expand Up @@ -588,18 +577,9 @@ export async function provisionIssuerForStatus({
const didTemplate = did ?? 'did:key:{publicKeyMultibase}';
const publicAliasTemplate = didTemplate + '#{publicKeyMultibase}';
const algorithm = statusOptions.algorithm ?? suiteOptions.algorithm;
if(['P-256', 'P-384'].includes(algorithm)) {
assertionMethodKey = await _generateMultikey({
keystoreAgent,
type: `urn:webkms:multikey:${algorithm}`,
publicAliasTemplate
});
} else {
assertionMethodKey = await keystoreAgent.generateKey({
type: 'asymmetric',
publicAliasTemplate
});
}
const assertionMethodKey = await generateAsymmetricKey({
keystoreAgent, algorithm, publicAliasTemplate
});

// delegate assertion method zcap to service agent
zcaps.assertionMethod = await delegate({
Expand Down Expand Up @@ -706,22 +686,20 @@ export async function provisionStatus({
};
}

export async function _generateMultikey({
keystoreAgent, type, publicAliasTemplate
export async function generateAsymmetricKey({
keystoreAgent, algorithm, publicAliasTemplate
}) {
const {capabilityAgent, kmsClient} = keystoreAgent;
const invocationSigner = capabilityAgent.getSigner();
const {keyId, keyDescription} = await kmsClient.generateKey({
type,
suiteContextUrl: 'https://w3id.org/security/multikey/v1',
invocationSigner,
if(['P-256', 'P-384', 'Bls12381G2'].includes(algorithm)) {
return _generateMultikey({
keystoreAgent,
type: `urn:webkms:multikey:${algorithm}`,
publicAliasTemplate
});
}
return keystoreAgent.generateKey({
type: 'asymmetric',
publicAliasTemplate
});
const {id} = keyDescription;
({type} = keyDescription);
return new AsymmetricKey({
id, kmsId: keyId, type, invocationSigner, kmsClient, keyDescription
});
}

const serviceCoreConfigCollection =
Expand Down Expand Up @@ -769,3 +747,21 @@ export function parseEnvelope({verifiableCredential}) {
}
throw new Error(`Unknown envelope format "${format}".`);
}

async function _generateMultikey({
keystoreAgent, type, publicAliasTemplate
}) {
const {capabilityAgent, kmsClient} = keystoreAgent;
const invocationSigner = capabilityAgent.getSigner();
const {keyId, keyDescription} = await kmsClient.generateKey({
type,
suiteContextUrl: 'https://w3id.org/security/multikey/v1',
invocationSigner,
publicAliasTemplate
});
const {id} = keyDescription;
({type} = keyDescription);
return new AsymmetricKey({
id, kmsId: keyId, type, invocationSigner, kmsClient, keyDescription
});
}

0 comments on commit e944a75

Please sign in to comment.