Skip to content

Commit fdde369

Browse 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 <[email protected]>
1 parent f6d7279 commit fdde369

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/crypto.js

+1-1
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.'));
+31
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)