nodejs/test/parallel/test-tls-no-sslv3.js
James M Snell 761de815c5
test: move crypto related common utilities in common/crypto
Since `common/crypto` already exists, it makes sense to keep
crypto-related utilities there. The only exception being
common.hasCrypto which is needed up front to determine
if tests should be skipped.

Eliminate the redundant check in hasFipsCrypto and just
use crypto.getFips() directly where needed.

PR-URL: https://github.com/nodejs/node/pull/56714
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-01-25 00:58:32 +00:00

52 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const { opensslCli } = require('../common/crypto');
if (opensslCli === false) {
common.skip('node compiled without OpenSSL CLI.');
}
const assert = require('assert');
const tls = require('tls');
const spawn = require('child_process').spawn;
const fixtures = require('../common/fixtures');
const cert = fixtures.readKey('rsa_cert.crt');
const key = fixtures.readKey('rsa_private.pem');
const server = tls.createServer({ cert, key }, common.mustNotCall());
const errors = [];
let stderr = '';
server.listen(0, '127.0.0.1', function() {
const address = `${this.address().address}:${this.address().port}`;
const args = ['s_client',
'-ssl3',
'-connect', address];
const client = spawn(opensslCli, args, { stdio: 'pipe' });
client.stdout.pipe(process.stdout);
client.stderr.pipe(process.stderr);
client.stderr.setEncoding('utf8');
client.stderr.on('data', (data) => stderr += data);
client.once('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, 1);
server.close();
}));
});
server.on('tlsClientError', (err) => errors.push(err));
process.on('exit', function() {
if (/[Uu]nknown option:? -ssl3/.test(stderr)) {
common.printSkipMessage('`openssl s_client -ssl3` not supported.');
} else {
assert.strictEqual(errors.length, 1);
assert(/:version too low/.test(errors[0].message));
}
});