test: update WPT for WebCryptoAPI to 4c2fd05ed5 · nodejs/node@cc19107 · GitHub
Skip to content

Commit cc19107

Browse files
nodejs-github-botaduh95
authored andcommitted
test: update WPT for WebCryptoAPI to 4c2fd05ed5
PR-URL: #65150 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 69e4fab commit cc19107

4 files changed

Lines changed: 98 additions & 70 deletions

File tree

test/fixtures/wpt/WebCryptoAPI/generateKey/failures.js

Lines changed: 71 additions & 69 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// META: title=WebCryptoAPI: generateKey() for Failures
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=failures.js
5+
run_bad_algorithm_test();

test/fixtures/wpt/WebCryptoAPI/generateKey/successes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ function run_test(algorithmNames, slowTest) {
110110
assert_unreached("exportKey threw an unexpected error: " + err.toString());
111111
})
112112
}, testTag + ": generateKey" + parameterString(algorithm, extractable, usages));
113+
114+
// Special case for ECDH and ECDSA: check that the generated key length is consistent.
115+
// Particularly for P-521, there is a high risk of the generated key being one byte short
116+
// if the implementation isn't careful.
117+
if (algorithm.namedCurve && extractable) {
118+
promise_test(async function(test) {
119+
// We run about 20 variants of this test, times 10 key generations below,
120+
// so this should have a decent chance of catching issues.
121+
await Promise.all(Array.from({ length: 10 }).map(async () => {
122+
const { privateKey, publicKey } = await subtle.generateKey(algorithm, extractable, usages);
123+
const [jwkPub, jwkPriv] = await Promise.all([
124+
subtle.exportKey('jwk', publicKey),
125+
subtle.exportKey('jwk', privateKey),
126+
]);
127+
const expectedLength = Math.ceil(Math.ceil(parseInt(algorithm.namedCurve.substring(2)) / 8) * 4/3);
128+
assert_equals(jwkPub.x.length, expectedLength, "Public key value x has correct length");
129+
assert_equals(jwkPub.y.length, expectedLength, "Public key value y has correct length");
130+
assert_equals(jwkPriv.d.length, expectedLength, "Private key value d has correct length");
131+
}));
132+
}, testTag + ": generateKey" + parameterString(algorithm, extractable, usages) + " produces consistent length key");
133+
}
113134
}
114135

115136
// Test all valid sets of parameters for successful

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)