GeezerVison is showing github.com — test: update WPT for WebCryptoAPI to a6a0a0292a · nodejs/node@3472aab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/digest/digest.https.any.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 51 | 51 | emptyExpected: digestedData[alg].empty, | 52 | 52 | label: upCase + " with " + size + " source data", | 53 | 53 | mutations: true, | 54 | | - transferBeforeCall: true, | 55 | 54 | }); | 56 | 55 | vectors.push({ | 57 | 56 | algorithm: {name: downCase}, | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/digest/digest.js +3-8Lines changed: 3 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,15 +58,10 @@ function runDigestTests(subtle, sourceData, getVectors) { | 58 | 58 |
| 59 | 59 | promise_test(function () { | 60 | 60 | var buffer = new Uint8Array(sourceData[size]); | 61 | | - var algorithm = vector.transferBeforeCall | 62 | | - ? vector.algorithm | 63 | | - : withNameGetter(vector.algorithm, function () { | 64 | | - buffer.buffer.transfer(); | 65 | | - return algorithmName(vector.algorithm); | 66 | | - }); | 67 | | - if (vector.transferBeforeCall) { | | 61 | + var algorithm = withNameGetter(vector.algorithm, function () { | 68 | 62 | buffer.buffer.transfer(); | 69 | | - } | | 63 | + return algorithmName(vector.algorithm); | | 64 | + }); | 70 | 65 | return subtle.digest(algorithm, buffer).then(function (result) { | 71 | 66 | assert_true( | 72 | 67 | equalBuffers(result, vector.emptyExpected), | |
Collapse file Copy file name to clipboard +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: title=WebCryptoAPI: exportKey() and wrapKey() check export support first | | 2 | + | | 3 | +// HKDF and PBKDF2 are not registered for the export key operation, and their | | 4 | +// keys can only be imported as non-extractable. Both error conditions are | | 5 | +// therefore always true at once, which makes the order observable. | | 6 | +// | | 7 | +// exportKey: step 6 (NotSupportedError) precedes step 7 (InvalidAccessError). | | 8 | +// https://w3c.github.io/webcrypto/#SubtleCrypto-method-exportKey | | 9 | +// | | 10 | +// wrapKey: step 11 (NotSupportedError) precedes step 12 (InvalidAccessError). | | 11 | +// https://w3c.github.io/webcrypto/#SubtleCrypto-method-wrapKey | | 12 | + | | 13 | +function importDeriveKey(name) { | | 14 | + return crypto.subtle.importKey('raw', new Uint8Array([]), name, false, | | 15 | + ['deriveBits']); | | 16 | +} | | 17 | + | | 18 | +function importAesKey(name, usages) { | | 19 | + return crypto.subtle.importKey('raw', new Uint8Array(16), name, false, | | 20 | + usages); | | 21 | +} | | 22 | + | | 23 | +for (const name of ['HKDF', 'PBKDF2']) { | | 24 | + promise_test(async (t) => { | | 25 | + const key = await importDeriveKey(name); | | 26 | + return promise_rejects_dom(t, 'NotSupportedError', | | 27 | + crypto.subtle.exportKey('raw', key)); | | 28 | + }, `exportKey() with a ${name} key throws NotSupportedError`); | | 29 | + | | 30 | + promise_test(async (t) => { | | 31 | + const key = await importDeriveKey(name); | | 32 | + const wrappingKey = await importAesKey('AES-KW', ['wrapKey']); | | 33 | + return promise_rejects_dom( | | 34 | + t, 'NotSupportedError', | | 35 | + crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW')); | | 36 | + }, `wrapKey() with a ${name} key throws NotSupportedError`); | | 37 | +} | | 38 | + | | 39 | +// An algorithm that does support the export key operation must still report | | 40 | +// the extractable check. | | 41 | +promise_test(async (t) => { | | 42 | + const key = await importAesKey('AES-CBC', ['encrypt']); | | 43 | + return promise_rejects_dom(t, 'InvalidAccessError', | | 44 | + crypto.subtle.exportKey('raw', key)); | | 45 | +}, 'exportKey() with a non-extractable AES-CBC key throws InvalidAccessError'); | | 46 | + | | 47 | +promise_test(async (t) => { | | 48 | + const key = await importAesKey('AES-CBC', ['encrypt']); | | 49 | + const wrappingKey = await importAesKey('AES-KW', ['wrapKey']); | | 50 | + return promise_rejects_dom( | | 51 | + t, 'InvalidAccessError', | | 52 | + crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW')); | | 53 | +}, 'wrapKey() with a non-extractable AES-CBC key throws InvalidAccessError'); |
Collapse file Copy file name to clipboard +38Lines changed: 38 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: title=WebCryptoAPI: BufferSource arguments and members reject shared buffers | | 2 | + | | 3 | +// None of the BufferSource arguments of SubtleCrypto, or of the dictionaries it | | 4 | +// takes, are [AllowShared], so a SharedArrayBuffer, or a view onto one, has to | | 5 | +// throw a TypeError. | | 6 | +// | | 7 | +// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`. | | 8 | +const sharedBuffer = new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 }).buffer; | | 9 | + | | 10 | +function generateAesGcmKey() { | | 11 | + return crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, false, ["encrypt"]); | | 12 | +} | | 13 | + | | 14 | +for (const [kind, buffer] of [["SharedArrayBuffer", sharedBuffer], | | 15 | + ["Uint8Array(SharedArrayBuffer)", new Uint8Array(sharedBuffer)]]) { | | 16 | + promise_test(t => { | | 17 | + return promise_rejects_js(t, TypeError, crypto.subtle.digest("SHA-256", buffer)); | | 18 | + }, `digest() data is a ${kind}`); | | 19 | + | | 20 | + promise_test(async t => { | | 21 | + const key = await generateAesGcmKey(); | | 22 | + await promise_rejects_js(t, TypeError, | | 23 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, buffer)); | | 24 | + }, `encrypt() data is a ${kind}`); | | 25 | + | | 26 | + promise_test(async t => { | | 27 | + const key = await generateAesGcmKey(); | | 28 | + await promise_rejects_js(t, TypeError, | | 29 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: buffer }, key, new Uint8Array(1))); | | 30 | + }, `encrypt() AesGcmParams.iv is a ${kind}`); | | 31 | + | | 32 | + promise_test(async t => { | | 33 | + const key = await generateAesGcmKey(); | | 34 | + await promise_rejects_js(t, TypeError, | | 35 | + crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12), additionalData: buffer }, | | 36 | + key, new Uint8Array(1))); | | 37 | + }, `encrypt() AesGcmParams.additionalData is a ${kind}`); | | 38 | +} |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/versions.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 96 | 96 | "path": "web-locks" | 97 | 97 | }, | 98 | 98 | "WebCryptoAPI": { | 99 | | - "commit": "55ce71bb9deaf4b8a30fe80f95558a10699fb433", | | 99 | + "commit": "a6a0a0292a4706866328488ffaaace00400edcc6", | 100 | 100 | "path": "WebCryptoAPI" | 101 | 101 | }, | 102 | 102 | "webidl": { | |
|