Skip to content

Commit b0291fa

Browse files
committed
test: add new crypto tests
Add new tests according to the discussion in issue nodejs#25509.
1 parent d51b359 commit b0291fa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/simple/test-crypto.js

+35
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
var common = require('../common');
2626
var assert = require('assert');
2727
var util = require('util');
28+
var spawn = require('child_process').spawn;
2829

2930
try {
3031
var crypto = require('crypto');
@@ -855,6 +856,40 @@ var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
855856
var bad_dh = crypto.createDiffieHellman(p, 'hex');
856857
assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR);
857858

859+
function node_output(code, args, env, cb) {
860+
var out = '', err = '';
861+
var p = spawn(process.execPath, [ '-e', code ].concat(args), { env: env });
862+
p.stdout.on('data', function(data) { out += data; });
863+
p.stderr.on('data', function(data) { err += data; });
864+
p.on('close', function(code, signal) { cb(out, err, code); });
865+
}
866+
867+
function no_output(out, err, code) {
868+
assert.equal(out + err, '');
869+
assert.equal(code, 0);
870+
}
871+
872+
// test if fails on deprecated group
873+
node_output("require('crypto').getDiffieHellman('modp1')",
874+
[], {}, function(out, err, code) {
875+
assert.equal(out, '');
876+
assert.ok(err.indexOf('Small DH groups disabled') > -1);
877+
assert.equal(code, 1);
878+
});
879+
880+
// test if the environment variable makes it work
881+
node_output("require('crypto').getDiffieHellman('modp1')",
882+
[], { 'ENABLE_SMALL_DH_GROUPS': '' }, no_output);
883+
884+
// test if the cmdline switch makes it work
885+
node_output("require('crypto').getDiffieHellman('modp1')",
886+
[ '--enable-small-dh-groups' ], {}, no_output);
887+
888+
// test if does not fail on the next group
889+
node_output("require('crypto').getDiffieHellman('modp2')",
890+
[], {}, no_output);
891+
892+
858893
// Test RSA encryption/decryption
859894
(function() {
860895
var input = 'I AM THE WALRUS';

0 commit comments

Comments
 (0)