11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciif (!common.hasCrypto) 61cb0ef41Sopenharmony_ci common.skip('missing crypto'); 71cb0ef41Sopenharmony_ciif (common.hasFipsCrypto) 81cb0ef41Sopenharmony_ci common.skip('crypto.createCipher() is not supported in FIPS mode'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst crypto = require('crypto'); 111cb0ef41Sopenharmony_ciconst key = '0123456789'; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci{ 141cb0ef41Sopenharmony_ci common.expectWarning({ 151cb0ef41Sopenharmony_ci DeprecationWarning: [ 161cb0ef41Sopenharmony_ci ['crypto.createCipher is deprecated.', 'DEP0106'], 171cb0ef41Sopenharmony_ci ], 181cb0ef41Sopenharmony_ci Warning: [ 191cb0ef41Sopenharmony_ci ['Use Cipheriv for counter mode of aes-256-gcm'], 201cb0ef41Sopenharmony_ci ] 211cb0ef41Sopenharmony_ci }); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci // Emits regular warning expected by expectWarning() 241cb0ef41Sopenharmony_ci crypto.createCipher('aes-256-gcm', key); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst realEmitWarning = process.emitWarning; 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci{ 301cb0ef41Sopenharmony_ci // It's a good idea to make this overridable from userland. 311cb0ef41Sopenharmony_ci process.emitWarning = () => { throw new Error('foo'); }; 321cb0ef41Sopenharmony_ci assert.throws(() => { 331cb0ef41Sopenharmony_ci crypto.createCipher('aes-256-gcm', key); 341cb0ef41Sopenharmony_ci }, /^Error: foo$/); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci Object.defineProperty(process, 'emitWarning', { 391cb0ef41Sopenharmony_ci get() { throw new Error('bar'); }, 401cb0ef41Sopenharmony_ci configurable: true 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci assert.throws(() => { 431cb0ef41Sopenharmony_ci crypto.createCipher('aes-256-gcm', key); 441cb0ef41Sopenharmony_ci }, /^Error: bar$/); 451cb0ef41Sopenharmony_ci} 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci// Reset back to default after the test. 481cb0ef41Sopenharmony_ciObject.defineProperty(process, 'emitWarning', { 491cb0ef41Sopenharmony_ci value: realEmitWarning, 501cb0ef41Sopenharmony_ci configurable: true, 511cb0ef41Sopenharmony_ci writable: true 521cb0ef41Sopenharmony_ci}); 53