• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7if (common.hasFipsCrypto)
8  common.skip('crypto.createCipher() is not supported in FIPS mode');
9
10const crypto = require('crypto');
11const key = '0123456789';
12
13{
14  common.expectWarning({
15    DeprecationWarning: [
16      ['crypto.createCipher is deprecated.', 'DEP0106'],
17    ],
18    Warning: [
19      ['Use Cipheriv for counter mode of aes-256-gcm'],
20    ]
21  });
22
23  // Emits regular warning expected by expectWarning()
24  crypto.createCipher('aes-256-gcm', key);
25}
26
27const realEmitWarning = process.emitWarning;
28
29{
30  // It's a good idea to make this overridable from userland.
31  process.emitWarning = () => { throw new Error('foo'); };
32  assert.throws(() => {
33    crypto.createCipher('aes-256-gcm', key);
34  }, /^Error: foo$/);
35}
36
37{
38  Object.defineProperty(process, 'emitWarning', {
39    get() { throw new Error('bar'); },
40    configurable: true
41  });
42  assert.throws(() => {
43    crypto.createCipher('aes-256-gcm', key);
44  }, /^Error: bar$/);
45}
46
47// Reset back to default after the test.
48Object.defineProperty(process, 'emitWarning', {
49  value: realEmitWarning,
50  configurable: true,
51  writable: true
52});
53