Skip to content

Commit

Permalink
test: add new crypto tests
Browse files Browse the repository at this point in the history
Add new tests according to the discussion in issue nodejs#25509.
  • Loading branch information
thinred committed Jun 18, 2015
1 parent d51b359 commit b0291fa
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/simple/test-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit b0291fa

Please sign in to comment.