mirror of
https://github.com/nodejs/node.git
synced 2025-05-20 08:12:55 +00:00

The current API is somewhat confusing at times and simpler usage is possible. This overloads the arguments further to accept objects with deprecation codes as property keys. It also adds documentation for the different possible styles. Besides that it is now going to validate for the code being present in case of deprecations but not for other cases. The former validation was not consistent as it only validated some cases and accepted undefined instead of `common.noWarnCode`. This check is removed due to the lack of consistency. `common.noWarnCode` is completely removed due to just being sugar for `undefined`. This also verifies that the warning order is identical to the order in which they are triggered. PR-URL: https://github.com/nodejs/node/pull/25251 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
if (common.hasFipsCrypto)
|
|
common.skip('crypto.createCipher() is not supported in FIPS mode');
|
|
|
|
const crypto = require('crypto');
|
|
const key = '0123456789';
|
|
|
|
{
|
|
common.expectWarning({
|
|
DeprecationWarning: [
|
|
['crypto.createCipher is deprecated.', 'DEP0106']
|
|
],
|
|
Warning: [
|
|
['Use Cipheriv for counter mode of aes-256-gcm']
|
|
]
|
|
});
|
|
|
|
// Emits regular warning expected by expectWarning()
|
|
crypto.createCipher('aes-256-gcm', key);
|
|
}
|
|
|
|
const realEmitWarning = process.emitWarning;
|
|
|
|
{
|
|
// It's a good idea to make this overridable from userland.
|
|
process.emitWarning = () => { throw new Error('foo'); };
|
|
assert.throws(() => {
|
|
crypto.createCipher('aes-256-gcm', key);
|
|
}, /^Error: foo$/);
|
|
}
|
|
|
|
{
|
|
Object.defineProperty(process, 'emitWarning', {
|
|
get() { throw new Error('bar'); },
|
|
configurable: true
|
|
});
|
|
assert.throws(() => {
|
|
crypto.createCipher('aes-256-gcm', key);
|
|
}, /^Error: bar$/);
|
|
}
|
|
|
|
// Reset back to default after the test.
|
|
Object.defineProperty(process, 'emitWarning', {
|
|
value: realEmitWarning,
|
|
configurable: true,
|
|
writable: true
|
|
});
|