Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fdde369

Browse filesBrowse files
TrottFishrock123
authored andcommitted
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>
1 parent f6d7279 commit fdde369
Copy full SHA for fdde369

File tree

Expand file treeCollapse file tree

2 files changed

+32
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-1
lines changed
Open diff view settings
Collapse file

‎lib/crypto.js‎

Copy file name to clipboardExpand all lines: lib/crypto.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,4 @@ exports.__defineGetter__('createCredentials',
671671
exports.__defineGetter__('Credentials', internalUtil.deprecate(function() {
672672
return require('tls').SecureContext;
673673
}, 'crypto.Credentials is deprecated. ' +
674-
'Use tls.createSecureContext instead.'));
674+
'Use tls.SecureContext instead.'));
Collapse file
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
return;
8+
}
9+
const crypto = require('crypto');
10+
const tls = require('tls');
11+
12+
process.on('warning', common.mustCall((warning) => {
13+
assert.strictEqual(warning.name, 'DeprecationWarning');
14+
assert.notStrictEqual(expected.indexOf(warning.message), -1,
15+
`unexpected error message: "${warning.message}"`);
16+
// Remove a warning message after it is seen so that we guarantee that we get
17+
// each message only once.
18+
expected.splice(expected.indexOf(warning.message), 1);
19+
}, 2));
20+
21+
var expected = [
22+
'crypto.Credentials is deprecated. Use tls.SecureContext instead.',
23+
'crypto.createCredentials is deprecated. Use tls.createSecureContext instead.'
24+
];
25+
26+
// Accessing the deprecated function is enough to trigger the warning event.
27+
// It does not need to be called. So the assert serves the purpose of both
28+
// triggering the warning event and confirming that the deprected function is
29+
// mapped to the correct non-deprecated function.
30+
assert.strictEqual(crypto.Credentials, tls.SecureContext);
31+
assert.strictEqual(crypto.createCredentials, tls.createSecureContext);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.