diff --git a/test/mocha/20-issue.js b/test/mocha/20-issue.js index 6994c359..461a85e0 100644 --- a/test/mocha/20-issue.js +++ b/test/mocha/20-issue.js @@ -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: {}, @@ -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: {}, @@ -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: { @@ -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); + } + }); + } }); diff --git a/test/mocha/assertions/assertions.js b/test/mocha/assertions/index.js similarity index 100% rename from test/mocha/assertions/assertions.js rename to test/mocha/assertions/index.js diff --git a/test/mocha/assertions/issueWithoutStatus.js b/test/mocha/assertions/issueWithoutStatus.js index 94384c2a..48d118d9 100644 --- a/test/mocha/assertions/issueWithoutStatus.js +++ b/test/mocha/assertions/issueWithoutStatus.js @@ -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'; diff --git a/test/mocha/assertions/testBitstringStatusList.js b/test/mocha/assertions/testBitstringStatusList.js index cf5480b7..3b46a392 100644 --- a/test/mocha/assertions/testBitstringStatusList.js +++ b/test/mocha/assertions/testBitstringStatusList.js @@ -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'; diff --git a/test/mocha/assertions/testIssueSd.js b/test/mocha/assertions/testIssueSd.js index 6791d134..d8ac68c8 100644 --- a/test/mocha/assertions/testIssueSd.js +++ b/test/mocha/assertions/testIssueSd.js @@ -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'; diff --git a/test/mocha/assertions/testIssueXi.js b/test/mocha/assertions/testIssueXi.js index b0c1b9d3..7c796ec0 100644 --- a/test/mocha/assertions/testIssueXi.js +++ b/test/mocha/assertions/testIssueXi.js @@ -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'; diff --git a/test/mocha/helpers.js b/test/mocha/helpers.js index 789b7326..1577812f 100644 --- a/test/mocha/helpers.js +++ b/test/mocha/helpers.js @@ -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) { @@ -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({ @@ -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 = @@ -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 + }); +}