Skip to content

Commit

Permalink
test,crypto: update WebCryptoAPI WPT
Browse files Browse the repository at this point in the history
PR-URL: nodejs#50039
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
  • Loading branch information
panva authored and alexfernandez committed Nov 1, 2023
1 parent 80478a6 commit 2b2cea1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Last update:
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/f4e7e32fd0/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/d4e14d714c/WebCryptoAPI
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
}

testFormat(format, algorithm, data, vector.name, usages, extractable);

// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
if (format === "jwk" && extractable) {
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
}
});

});
Expand All @@ -92,6 +97,11 @@
var data = keyData[vector.name];

testFormat(format, algorithm, data, vector.name, usages, extractable);

// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
if (format === "jwk" && extractable) {
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
}
});
});
});
Expand Down Expand Up @@ -126,6 +136,28 @@
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages));
}

// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
// https://github.com/WICG/webcrypto-secure-curves/pull/24
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
promise_test(function(test) {
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages).
then(function(key) {
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");

return subtle.exportKey('jwk', key).
then(function(result) {
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
assert_true(equalJwk(keyData, result), "Round trip works");
}, function(err) {
assert_unreached("Threw an unexpected error: " + err.toString());
});
}, function(err) {
assert_unreached("Threw an unexpected error: " + err.toString());
});
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages));
}



// Helper methods follow:
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function run_test() {
promise_test(function(test) {
return subtle.sign(algorithm, vector.privateKey, vector.data)
.then(function(signature) {
assert_true(equalBuffers(signature, vector.signature), "Signing did not give the expected output");
// Can we verify the signature?
return subtle.verify(algorithm, vector.publicKey, signature, vector.data)
.then(function(is_verified) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function run_test() {
promise_test(function(test) {
return subtle.sign({name: "HMAC", hash: vector.hash}, vector.key, vector.plaintext)
.then(function(signature) {
assert_true(equalBuffers(signature, vector.signature), "Signing did not give the expected output");
// Can we get the verify the new signature?
return subtle.verify({name: "HMAC", hash: vector.hash}, vector.key, signature, vector.plaintext)
.then(function(is_verified) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"path": "wasm/webapi"
},
"WebCryptoAPI": {
"commit": "f4e7e32fd0d4937f5b024602c6bf665ebeb1fa17",
"commit": "d4e14d714c5242e174ba9aec43caf5eb514d0f09",
"path": "WebCryptoAPI"
},
"webidl/ecmascript-binding/es-exceptions": {
Expand Down

0 comments on commit 2b2cea1

Please sign in to comment.