GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto,test: improve hmac coverage with webcrypto tests · nodejs/node@23d6541

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-webcrypto-export-import.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-export-import.js
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,53 @@ const { subtle, getRandomValues } = require('crypto').webcrypto;
2626
code: 'ERR_INVALID_ARG_TYPE'
2727
});
2828
});
29+
assert.rejects(
30+
subtle.importKey('raw', keyData, {
31+
name: 'HMAC'
32+
}, false, ['sign', 'verify']), {
33+
code: 'ERR_MISSING_OPTION'
34+
}).then(common.mustCall());
35+
assert.rejects(
36+
subtle.importKey('raw', keyData, {
37+
name: 'HMAC',
38+
hash: 'SHA-256'
39+
}, false, ['deriveBits']), {
40+
name: 'SyntaxError',
41+
message: 'Unsupported key usage for an HMAC key'
42+
}).then(common.mustCall());
43+
assert.rejects(
44+
subtle.importKey('node.keyObject', '', {
45+
name: 'HMAC',
46+
hash: 'SHA-256'
47+
}, false, ['sign', 'verify']), {
48+
code: 'ERR_INVALID_ARG_TYPE'
49+
}).then(common.mustCall());
50+
assert.rejects(
51+
subtle.importKey('raw', keyData, {
52+
name: 'HMAC',
53+
hash: 'SHA-256',
54+
length: 0
55+
}, false, ['sign', 'verify']), {
56+
name: 'DataError',
57+
message: 'Zero-length key is not supported'
58+
}).then(common.mustCall());
59+
assert.rejects(
60+
subtle.importKey('raw', keyData, {
61+
name: 'HMAC',
62+
hash: 'SHA-256',
63+
length: 1
64+
}, false, ['sign', 'verify']), {
65+
name: 'DataError',
66+
message: 'Invalid key length'
67+
}).then(common.mustCall());
68+
assert.rejects(
69+
subtle.importKey('jwk', null, {
70+
name: 'HMAC',
71+
hash: 'SHA-256',
72+
}, false, ['sign', 'verify']), {
73+
name: 'DataError',
74+
message: 'Invalid JWK keyData'
75+
}).then(common.mustCall());
2976
}
3077

3178
// Import/Export HMAC Secret Key

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.