Skip to content

Commit acd5776

Browse files
committed
Change common tests to verifier tests.
1 parent 87bc3d2 commit acd5776

File tree

1 file changed

+53
-49
lines changed

1 file changed

+53
-49
lines changed

tests/suites/algorithms.js

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,79 +7,79 @@ import {
77
generators,
88
issueCloned
99
} from 'data-integrity-test-suite-assertion';
10-
import {createInitialVc, endpointCheck} from '../helpers.js';
1110
import {getMultiKey} from '../vc-generator/key-gen.js';
1211
import {getSuites} from './helpers.js';
13-
import {localVerifier} from '../vc-verifier/index.js';
1412

1513
export function commonAlgorithms({
1614
credential,
17-
issuers,
15+
verifiers,
1816
mandatoryPointers,
19-
keyType,
20-
cryptosuite,
17+
selectivePointers,
18+
keyTypes,
2119
suiteName,
22-
vcVersion
20+
vcVersion,
21+
setup = _commonSetup
2322
}) {
24-
const verifier = localVerifier({cryptosuite});
25-
for(const [name, {endpoints}] of issuers) {
26-
const [issuer] = endpoints;
27-
// does the endpoint support this test?
28-
if(!endpointCheck({endpoint: issuer, keyType, vcVersion})) {
29-
continue;
30-
}
31-
describe(`${name}: ${keyType}`, function() {
32-
let securedCredential = null;
33-
before(async function() {
34-
securedCredential = await createInitialVc({
35-
issuer,
36-
vcVersion,
37-
vc: credential,
38-
mandatoryPointers
23+
const title = `${suiteName} - Algorithms Common - VC ${vcVersion}`;
24+
return describe(title, function() {
25+
const credentials = new Map(keyTypes.map(keyType => [keyType, null]));
26+
before(async function() {
27+
for(const keyType of keyTypes) {
28+
credentials.set(keyType, await setup({
29+
credential,
30+
verifiers,
31+
mandatoryPointers,
32+
selectivePointers,
33+
keyType,
34+
suiteName,
35+
vcVersion
36+
}));
37+
}
38+
});
39+
for(const [name, {endpoints}] of verifiers) {
40+
const [verifier] = endpoints;
41+
describe(`${name}`, function() {
42+
beforeEach(function() {
43+
this.currentTest.cell = {
44+
rowId: this.currentTest.title,
45+
columnId: this.currentTest.parent.title
46+
};
3947
});
40-
});
41-
beforeEach(function() {
42-
this.currentTest.cell = {
43-
rowId: this.currentTest.title,
44-
columnId: this.currentTest.parent.title
45-
};
46-
});
47-
it('When generating ECDSA signatures, the signature value MUST be ' +
48-
'expressed according to section 7 of [RFC4754] (sometimes referred ' +
49-
'to as the IEEE P1363 format) and encoded according to the specific ' +
50-
'cryptosuite proof generation algorithm.', async function() {
51-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=When%20generating%20ECDSA%20signatures%2C%20the%20signature%20value%20MUST%20be%20expressed%20according%20to%20section%207%20of%20%5BRFC4754%5D%20(sometimes%20referred%20to%20as%20the%20IEEE%20P1363%20format)%20and%20encoded%20according%20to%20the%20specific%20cryptosuite%20proof%20generation%20algorithm';
52-
await assertions.verificationSuccess({
53-
credential: securedCredential,
54-
verifier,
55-
reason: `Should verify VC signed with ${suiteName} ${keyType}`
48+
it('When generating ECDSA signatures, the signature value MUST be ' +
49+
'expressed according to section 7 of [RFC4754] (sometimes referred ' +
50+
'to as the IEEE P1363 format) and encoded according to the ' +
51+
'specific cryptosuite proof generation algorithm.', async function() {
52+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=When%20generating%20ECDSA%20signatures%2C%20the%20signature%20value%20MUST%20be%20expressed%20according%20to%20section%207%20of%20%5BRFC4754%5D%20(sometimes%20referred%20to%20as%20the%20IEEE%20P1363%20format)%20and%20encoded%20according%20to%20the%20specific%20cryptosuite%20proof%20generation%20algorithm';
53+
for(const [keyType, fixtures] of credentials) {
54+
await assertions.verificationSuccess({
55+
credential: fixtures.get('invalidHash'),
56+
verifier,
57+
reason: `Should not verify VC signed w/ ${keyType} & invalidHash.`
58+
});
59+
}
5660
});
57-
});
58-
if(keyType === 'P-256') {
5961
it('For P-256 keys, the default hashing function, SHA-2 with 256 bits' +
6062
'of output, MUST be used.', async function() {
6163
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D256%20keys%2C%20the%20default%20hashing%20function%2C%20SHA%2D2%20with%20256%20bits%20of%20output%2C%20MUST%20be%20used.';
6264
await assertions.verificationSuccess({
63-
credential: securedCredential,
65+
credential: credentials.get('P-256').get('invalidHash'),
6466
verifier,
65-
reason: `Should verify VC signed with ${suiteName} ${keyType}`
67+
reason: `Should not verify VC with invalid hash.`
6668
});
6769
});
68-
}
69-
if(keyType === 'P-384') {
7070
it('For P-384 keys, SHA-2 with 384-bits of output MUST be used, ' +
7171
'specified via the RDFC-1.0 implementation-specific parameter.',
7272
async function() {
7373
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D384%20keys%2C%20SHA%2D2%20with%20384%2Dbits%20of%20output%20MUST%20be%20used%2C%20specified%20via%20the%20RDFC%2D1.0%20implementation%2Dspecific%20parameter.';
74-
await assertions.verificationSuccess({
75-
credential: securedCredential,
74+
await assertions.verificationFail({
75+
credential: credentials.get('P-384').get('invalidHash'),
7676
verifier,
77-
reason: `Should verify VC signed with ${suiteName} ${keyType}`
77+
reason: `Should not verify VC with invalid hash.`
7878
});
7979
});
80-
}
81-
});
82-
}
80+
});
81+
}
82+
});
8383
}
8484

8585
export function ecdsaRdfc2019Algorithms({
@@ -290,3 +290,7 @@ function unsafeProxy(suite) {
290290
}
291291
});
292292
}
293+
294+
function _commonSetup({}) {
295+
296+
}

0 commit comments

Comments
 (0)