diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index eba836356c62..5d08af9a9320 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -25,6 +25,7 @@ var common = require('../common'); var assert = require('assert'); var util = require('util'); +var spawn = require('child_process').spawn; try { var crypto = require('crypto'); @@ -855,6 +856,40 @@ var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + var bad_dh = crypto.createDiffieHellman(p, 'hex'); assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +function node_output(code, args, env, cb) { + var out = '', err = ''; + var p = spawn(process.execPath, [ '-e', code ].concat(args), { env: env }); + p.stdout.on('data', function(data) { out += data; }); + p.stderr.on('data', function(data) { err += data; }); + p.on('close', function(code, signal) { cb(out, err, code); }); +} + +function no_output(out, err, code) { + assert.equal(out + err, ''); + assert.equal(code, 0); +} + +// test if fails on deprecated group +node_output("require('crypto').getDiffieHellman('modp1')", + [], {}, function(out, err, code) { + assert.equal(out, ''); + assert.ok(err.indexOf('Small DH groups disabled') > -1); + assert.equal(code, 1); + }); + +// test if the environment variable makes it work +node_output("require('crypto').getDiffieHellman('modp1')", + [], { 'ENABLE_SMALL_DH_GROUPS': '' }, no_output); + +// test if the cmdline switch makes it work +node_output("require('crypto').getDiffieHellman('modp1')", + [ '--enable-small-dh-groups' ], {}, no_output); + +// test if does not fail on the next group +node_output("require('crypto').getDiffieHellman('modp2')", + [], {}, no_output); + + // Test RSA encryption/decryption (function() { var input = 'I AM THE WALRUS';