test: update WPT for WebCryptoAPI to edd42c005c · nodejs/node@36542b5 · GitHub
Skip to content

Commit 36542b5

Browse files
nodejs-github-bottargos
authored andcommitted
test: update WPT for WebCryptoAPI to edd42c005c
PR-URL: #57365 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 2b2267f commit 36542b5

6 files changed

Lines changed: 95 additions & 45 deletions

File tree

lib/internal/crypto/cfrg.js

Lines changed: 8 additions & 0 deletions

lib/internal/crypto/webcrypto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ async function exportKeyJWK(key) {
467467
// Fall through
468468
case 'Ed448':
469469
jwk.crv ||= key.algorithm.name;
470+
jwk.alg = key.algorithm.name;
470471
return jwk;
471472
case 'AES-CTR':
472473
// Fall through

test/fixtures/wpt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Last update:
3333
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3434
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3535
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
36-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/3e3374efde/WebCryptoAPI
36+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/edd42c005c/WebCryptoAPI
3737
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3838
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
3939
- webstorage: https://github.com/web-platform-tests/wpt/tree/1291340aaa/webstorage

test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function runTests(algorithmName) {
1111
['spki', 'jwk', 'raw'].forEach(function(format) {
1212
if (format === "jwk") { // Not all fields used for public keys
1313
testFormat(format, algorithm, jwkData, algorithmName, usages, extractable);
14-
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
14+
// Test for https://github.com/w3c/webcrypto/pull/401
1515
if (extractable) {
1616
testJwkAlgBehaviours(algorithm, jwkData.jwk, algorithmName, usages);
1717
}
@@ -27,7 +27,7 @@ function runTests(algorithmName) {
2727
['pkcs8', 'jwk'].forEach(function(format) {
2828
testFormat(format, algorithm, data, algorithmName, usages, extractable);
2929

30-
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
30+
// Test for https://github.com/w3c/webcrypto/pull/401
3131
if (format === "jwk" && extractable) {
3232
testJwkAlgBehaviours(algorithm, data.jwk, algorithmName, usages);
3333
}
@@ -67,27 +67,34 @@ function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
6767
});
6868
}
6969

70-
// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
71-
// https://github.com/WICG/webcrypto-secure-curves/pull/24
70+
// Test importKey/exportKey "alg" behaviours (https://github.com/w3c/webcrypto/pull/401)
71+
// - alg is ignored for ECDH import
72+
// - TODO: alg is checked to be the algorithm.name or EdDSA for Ed25519 and Ed448 import
73+
// - alg is missing for ECDH export
74+
// - alg is the algorithm name for Ed25519 and Ed448 export
7275
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
7376
[algorithm, algorithm.name].forEach((alg) => {
74-
promise_test(function(test) {
75-
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, alg, true, usages).
76-
then(function(key) {
77-
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
78-
79-
return subtle.exportKey('jwk', key).
80-
then(function(result) {
81-
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
82-
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
83-
assert_true(equalJwk(keyData, result), "Round trip works");
84-
}, function(err) {
77+
(crv.startsWith('Ed') ? [algorithm.name, 'EdDSA'] : ['this is ignored']).forEach((jwkAlg) => {
78+
promise_test(function(test) {
79+
return subtle.importKey('jwk', { ...keyData, alg: jwkAlg }, alg, true, usages).
80+
then(function(key) {
81+
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
82+
83+
return subtle.exportKey('jwk', key).
84+
then(function(result) {
85+
let expectedKeys = crv.startsWith('Ed') ? 6 : 5
86+
if (keyData.d) expectedKeys++
87+
assert_equals(Object.keys(result).length, expectedKeys, "Correct number of JWK members");
88+
assert_equals(result.alg, crv.startsWith('Ed') ? algorithm.name : undefined, 'Expected JWK "alg" member');
89+
assert_true(equalJwk(keyData, result), "Round trip works");
90+
}, function(err) {
91+
assert_unreached("Threw an unexpected error: " + err.toString());
92+
});
93+
}, function(err) {
8594
assert_unreached("Threw an unexpected error: " + err.toString());
86-
});
87-
}, function(err) {
88-
assert_unreached("Threw an unexpected error: " + err.toString());
89-
});
90-
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, alg, true, usages));
95+
});
96+
}, 'Good parameters with JWK alg' + (crv.startsWith('Ed') ? ` ${jwkAlg}: ` : ': ') + crv.toString() + " " + parameterString('jwk', keyData, alg, true, usages, jwkAlg));
97+
});
9198
});
9299
}
93100

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"path": "wasm/webapi"
9393
},
9494
"WebCryptoAPI": {
95-
"commit": "3e3374efde7ce73d551ea908d52d0afab046971a",
95+
"commit": "edd42c005cf8192fbae41ec061c14342e7bcac15",
9696
"path": "WebCryptoAPI"
9797
},
9898
"webidl/ecmascript-binding/es-exceptions": {

test/parallel/test-webcrypto-export-import-cfrg.js

Lines changed: 57 additions & 23 deletions

0 commit comments

Comments
 (0)