Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: simplify test-tls-ecdh-multiple #46963

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions test/parallel/test-tls-ecdh-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!common.opensslCli)

const assert = require('assert');
const tls = require('tls');
const spawn = require('child_process').spawn;
const { execFile } = require('child_process');
const fixtures = require('../common/fixtures');

function loadPEM(n) {
Expand All @@ -29,49 +29,33 @@ const options = {

const reply = 'I AM THE WALRUS'; // Something recognizable

const server = tls.createServer(options, function(conn) {
const server = tls.createServer(options, (conn) => {
conn.end(reply);
});

let gotReply = false;

server.listen(0, function() {
}).listen(0, common.mustCall(() => {
const args = ['s_client',
'-cipher', `${options.ciphers}`,
'-connect', `127.0.0.1:${this.address().port}`];

const client = spawn(common.opensslCli, args);

client.stdout.on('data', function(data) {
const message = data.toString();
if (message.includes(reply))
gotReply = true;
});
'-connect', `127.0.0.1:${server.address().port}`];

client.on('exit', function(code) {
assert.strictEqual(code, 0);
execFile(common.opensslCli, args, common.mustSucceed((stdout) => {
assert(stdout.includes(reply));
server.close();
});

client.on('error', assert.ifError);
});
}));
}));

process.on('exit', function() {
assert.ok(gotReply);

// Some of unsupported curves
{
// Some unsupported curves.
const unsupportedCurves = [
'wap-wsg-idm-ecid-wtls1',
'c2pnb163v1',
'prime192v3',
];

// Brainpool is not supported in FIPS mode
// Brainpool is not supported in FIPS mode.
if (common.hasFipsCrypto)
unsupportedCurves.push('brainpoolP256r1');

unsupportedCurves.forEach((ecdhCurve) => {
assert.throws(() => tls.createServer({ ecdhCurve }),
/Error: Failed to set ECDH curve/);
});
});
}