From fdde36909c601dfaf8c3c1e13772d8ee436c4edf Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 21 Apr 2016 22:29:14 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/6344 Reviewed-By: James M Snell --- lib/crypto.js | 2 +- test/parallel/test-crypto-deprecated.js | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-crypto-deprecated.js diff --git a/lib/crypto.js b/lib/crypto.js index 534ff03917354b..688ac34e4ad767 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -671,4 +671,4 @@ exports.__defineGetter__('createCredentials', exports.__defineGetter__('Credentials', internalUtil.deprecate(function() { return require('tls').SecureContext; }, 'crypto.Credentials is deprecated. ' + - 'Use tls.createSecureContext instead.')); + 'Use tls.SecureContext instead.')); diff --git a/test/parallel/test-crypto-deprecated.js b/test/parallel/test-crypto-deprecated.js new file mode 100644 index 00000000000000..a45c4111c6fa46 --- /dev/null +++ b/test/parallel/test-crypto-deprecated.js @@ -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);