mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
test: update WPT for WebCryptoAPI to a6a0a0292a
PR-URL: https://github.com/nodejs/node/pull/66142 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
658951021a
commit
63d32369b1
5 files changed
+95
-10
No files matched your search
@@ -51,7 +51,6 @@
|
||||
emptyExpected: digestedData[alg].empty,
|
||||
label: upCase + " with " + size + " source data",
|
||||
mutations: true,
|
||||
transferBeforeCall: true,
|
||||
});
|
||||
vectors.push({
|
||||
algorithm: {name: downCase},
|
||||
|
||||
+3
-8
@@ -58,15 +58,10 @@ function runDigestTests(subtle, sourceData, getVectors) {
|
||||
|
||||
promise_test(function () {
|
||||
var buffer = new Uint8Array(sourceData[size]);
|
||||
var algorithm = vector.transferBeforeCall
|
||||
? vector.algorithm
|
||||
: withNameGetter(vector.algorithm, function () {
|
||||
buffer.buffer.transfer();
|
||||
return algorithmName(vector.algorithm);
|
||||
});
|
||||
if (vector.transferBeforeCall) {
|
||||
var algorithm = withNameGetter(vector.algorithm, function () {
|
||||
buffer.buffer.transfer();
|
||||
}
|
||||
return algorithmName(vector.algorithm);
|
||||
});
|
||||
return subtle.digest(algorithm, buffer).then(function (result) {
|
||||
assert_true(
|
||||
equalBuffers(result, vector.emptyExpected),
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// META: title=WebCryptoAPI: exportKey() and wrapKey() check export support first
|
||||
|
||||
// HKDF and PBKDF2 are not registered for the export key operation, and their
|
||||
// keys can only be imported as non-extractable. Both error conditions are
|
||||
// therefore always true at once, which makes the order observable.
|
||||
//
|
||||
// exportKey: step 6 (NotSupportedError) precedes step 7 (InvalidAccessError).
|
||||
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-exportKey
|
||||
//
|
||||
// wrapKey: step 11 (NotSupportedError) precedes step 12 (InvalidAccessError).
|
||||
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-wrapKey
|
||||
|
||||
function importDeriveKey(name) {
|
||||
return crypto.subtle.importKey('raw', new Uint8Array([]), name, false,
|
||||
['deriveBits']);
|
||||
}
|
||||
|
||||
function importAesKey(name, usages) {
|
||||
return crypto.subtle.importKey('raw', new Uint8Array(16), name, false,
|
||||
usages);
|
||||
}
|
||||
|
||||
for (const name of ['HKDF', 'PBKDF2']) {
|
||||
promise_test(async (t) => {
|
||||
const key = await importDeriveKey(name);
|
||||
return promise_rejects_dom(t, 'NotSupportedError',
|
||||
crypto.subtle.exportKey('raw', key));
|
||||
}, `exportKey() with a ${name} key throws NotSupportedError`);
|
||||
|
||||
promise_test(async (t) => {
|
||||
const key = await importDeriveKey(name);
|
||||
const wrappingKey = await importAesKey('AES-KW', ['wrapKey']);
|
||||
return promise_rejects_dom(
|
||||
t, 'NotSupportedError',
|
||||
crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW'));
|
||||
}, `wrapKey() with a ${name} key throws NotSupportedError`);
|
||||
}
|
||||
|
||||
// An algorithm that does support the export key operation must still report
|
||||
// the extractable check.
|
||||
promise_test(async (t) => {
|
||||
const key = await importAesKey('AES-CBC', ['encrypt']);
|
||||
return promise_rejects_dom(t, 'InvalidAccessError',
|
||||
crypto.subtle.exportKey('raw', key));
|
||||
}, 'exportKey() with a non-extractable AES-CBC key throws InvalidAccessError');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const key = await importAesKey('AES-CBC', ['encrypt']);
|
||||
const wrappingKey = await importAesKey('AES-KW', ['wrapKey']);
|
||||
return promise_rejects_dom(
|
||||
t, 'InvalidAccessError',
|
||||
crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW'));
|
||||
}, 'wrapKey() with a non-extractable AES-CBC key throws InvalidAccessError');
|
||||
@@ -0,0 +1,38 @@
|
||||
// META: title=WebCryptoAPI: BufferSource arguments and members reject shared buffers
|
||||
|
||||
// None of the BufferSource arguments of SubtleCrypto, or of the dictionaries it
|
||||
// takes, are [AllowShared], so a SharedArrayBuffer, or a view onto one, has to
|
||||
// throw a TypeError.
|
||||
//
|
||||
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`.
|
||||
const sharedBuffer = new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 }).buffer;
|
||||
|
||||
function generateAesGcmKey() {
|
||||
return crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, false, ["encrypt"]);
|
||||
}
|
||||
|
||||
for (const [kind, buffer] of [["SharedArrayBuffer", sharedBuffer],
|
||||
["Uint8Array(SharedArrayBuffer)", new Uint8Array(sharedBuffer)]]) {
|
||||
promise_test(t => {
|
||||
return promise_rejects_js(t, TypeError, crypto.subtle.digest("SHA-256", buffer));
|
||||
}, `digest() data is a ${kind}`);
|
||||
|
||||
promise_test(async t => {
|
||||
const key = await generateAesGcmKey();
|
||||
await promise_rejects_js(t, TypeError,
|
||||
crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, buffer));
|
||||
}, `encrypt() data is a ${kind}`);
|
||||
|
||||
promise_test(async t => {
|
||||
const key = await generateAesGcmKey();
|
||||
await promise_rejects_js(t, TypeError,
|
||||
crypto.subtle.encrypt({ name: "AES-GCM", iv: buffer }, key, new Uint8Array(1)));
|
||||
}, `encrypt() AesGcmParams.iv is a ${kind}`);
|
||||
|
||||
promise_test(async t => {
|
||||
const key = await generateAesGcmKey();
|
||||
await promise_rejects_js(t, TypeError,
|
||||
crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12), additionalData: buffer },
|
||||
key, new Uint8Array(1)));
|
||||
}, `encrypt() AesGcmParams.additionalData is a ${kind}`);
|
||||
}
|
||||
Vendored
+1
-1
@@ -100,7 +100,7 @@
|
||||
"path": "web-locks"
|
||||
},
|
||||
"WebCryptoAPI": {
|
||||
"commit": "55ce71bb9deaf4b8a30fe80f95558a10699fb433",
|
||||
"commit": "a6a0a0292a4706866328488ffaaace00400edcc6",
|
||||
"path": "WebCryptoAPI"
|
||||
},
|
||||
"webidl": {
|
||||
|
||||
Reference in new issue
Block a user