MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-webcrypto-export-import.js:16–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15{
16 async function test() {
17 const keyData = globalThis.crypto.getRandomValues(new Uint8Array(32));
18 await Promise.all([1, null, undefined, {}, []].map((format) =>
19 assert.rejects(
20 subtle.importKey(format, keyData, {}, false, ['wrapKey']), {
21 code: 'ERR_INVALID_ARG_VALUE'
22 })
23 ));
24 await assert.rejects(
25 subtle.importKey('not valid', keyData, {}, false, ['wrapKey']), {
26 code: 'ERR_INVALID_ARG_VALUE'
27 });
28 await assert.rejects(
29 subtle.importKey('KeyObject', keyData, {}, false, ['wrapKey']), {
30 message: /'KeyObject' is not a valid enum value of type KeyFormat/,
31 code: 'ERR_INVALID_ARG_VALUE'
32 });
33 await assert.rejects(
34 subtle.importKey('raw', 1, {}, false, ['deriveBits']), {
35 code: 'ERR_INVALID_ARG_TYPE'
36 });
37 await assert.rejects(
38 subtle.importKey('raw', keyData, {
39 name: 'HMAC'
40 }, false, ['sign', 'verify']), {
41 code: 'ERR_MISSING_OPTION'
42 });
43 await assert.rejects(
44 subtle.importKey('raw', keyData, {
45 name: 'HMAC',
46 hash: 'SHA-256',
47 length: 384,
48 }, false, ['sign', 'verify']), {
49 name: 'DataError',
50 message: 'Invalid key length'
51 });
52 await assert.rejects(
53 subtle.importKey('raw', keyData, {
54 name: 'HMAC',
55 hash: 'SHA-256'
56 }, false, ['deriveBits']), {
57 name: 'SyntaxError',
58 message: 'Unsupported key usage for HMAC key'
59 });
60 await assert.rejects(
61 subtle.importKey('raw', keyData, {
62 name: 'HMAC',
63 hash: 'SHA-256',
64 length: 0
65 }, false, ['sign', 'verify']), {
66 name: 'DataError',
67 message: 'HmacImportParams.length cannot be 0'
68 });
69 await assert.rejects(
70 subtle.importKey('raw', keyData, {
71 name: 'HMAC',
72 hash: 'SHA-256',
73 length: 1

Callers 1

Calls 6

allMethod · 0.80
toCryptoKeyMethod · 0.80
mapMethod · 0.65
assertFunction · 0.50
toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…