-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: fix error in deprecation message
The deprecation message for `crypto.Credentials` says to use `tls.createSecureContext` but the correct property to use is `tls.SecureContext()`. Fix the deprecation message and add a test that checks the mappings of deprecated properties and their warning messages. PR-URL: #6344 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
f6d7279
commit fdde369
Showing
2 changed files
with
32 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
return; | ||
} | ||
const crypto = require('crypto'); | ||
const tls = require('tls'); | ||
|
||
process.on('warning', common.mustCall((warning) => { | ||
assert.strictEqual(warning.name, 'DeprecationWarning'); | ||
assert.notStrictEqual(expected.indexOf(warning.message), -1, | ||
`unexpected error message: "${warning.message}"`); | ||
// Remove a warning message after it is seen so that we guarantee that we get | ||
// each message only once. | ||
expected.splice(expected.indexOf(warning.message), 1); | ||
}, 2)); | ||
|
||
var expected = [ | ||
'crypto.Credentials is deprecated. Use tls.SecureContext instead.', | ||
'crypto.createCredentials is deprecated. Use tls.createSecureContext instead.' | ||
]; | ||
|
||
// Accessing the deprecated function is enough to trigger the warning event. | ||
// It does not need to be called. So the assert serves the purpose of both | ||
// triggering the warning event and confirming that the deprected function is | ||
// mapped to the correct non-deprecated function. | ||
assert.strictEqual(crypto.Credentials, tls.SecureContext); | ||
assert.strictEqual(crypto.createCredentials, tls.createSecureContext); |