-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: do not add undefined hash in webcrypto normalizeAlgorithm
PR-URL: #42559 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
- Loading branch information
Showing
3 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
|
||
const { | ||
normalizeAlgorithm, | ||
} = require('internal/crypto/util'); | ||
|
||
{ | ||
// Check that normalizeAlgorithm does not add an undefined hash property. | ||
assert.strictEqual('hash' in normalizeAlgorithm({ name: 'ECDH' }), false); | ||
assert.strictEqual('hash' in normalizeAlgorithm('ECDH'), false); | ||
} | ||
|
||
{ | ||
// Check that normalizeAlgorithm does not mutate object inputs. | ||
const algorithm = { name: 'ECDH', hash: 'SHA-256' }; | ||
assert.strictEqual(normalizeAlgorithm(algorithm) !== algorithm, true); | ||
assert.deepStrictEqual(algorithm, { name: 'ECDH', hash: 'SHA-256' }); | ||
} |