Skip to content

Commit

Permalink
crypto,test: improve hmac coverage with webcrypto tests
Browse files Browse the repository at this point in the history
PR-URL: #37571
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
obi-el authored and danielleadams committed Mar 16, 2021
1 parent 366772b commit 23d6541
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/parallel/test-webcrypto-export-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ const { subtle, getRandomValues } = require('crypto').webcrypto;
code: 'ERR_INVALID_ARG_TYPE'
});
});
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC'
}, false, ['sign', 'verify']), {
code: 'ERR_MISSING_OPTION'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256'
}, false, ['deriveBits']), {
name: 'SyntaxError',
message: 'Unsupported key usage for an HMAC key'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('node.keyObject', '', {
name: 'HMAC',
hash: 'SHA-256'
}, false, ['sign', 'verify']), {
code: 'ERR_INVALID_ARG_TYPE'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256',
length: 0
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Zero-length key is not supported'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('raw', keyData, {
name: 'HMAC',
hash: 'SHA-256',
length: 1
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Invalid key length'
}).then(common.mustCall());
assert.rejects(
subtle.importKey('jwk', null, {
name: 'HMAC',
hash: 'SHA-256',
}, false, ['sign', 'verify']), {
name: 'DataError',
message: 'Invalid JWK keyData'
}).then(common.mustCall());
}

// Import/Export HMAC Secret Key
Expand Down

0 comments on commit 23d6541

Please sign in to comment.