From 75d16125e120e9ace37c9e59d6575a7b58949504 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 27 Aug 2020 21:18:49 -0700 Subject: [PATCH] test: make test-tls-reuse-host-from-socket pass without internet Start up a TLS server on localhost rather than using example.org. PR-URL: https://github.com/nodejs/node/pull/34953 Reviewed-By: Anna Henningsen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- .../test-tls-reuse-host-from-socket.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) rename test/{internet => parallel}/test-tls-reuse-host-from-socket.js (73%) diff --git a/test/internet/test-tls-reuse-host-from-socket.js b/test/parallel/test-tls-reuse-host-from-socket.js similarity index 73% rename from test/internet/test-tls-reuse-host-from-socket.js rename to test/parallel/test-tls-reuse-host-from-socket.js index f7093856c6ab95..1a7705d911b69e 100644 --- a/test/internet/test-tls-reuse-host-from-socket.js +++ b/test/parallel/test-tls-reuse-host-from-socket.js @@ -25,13 +25,19 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); -const tls = require('tls'); - const net = require('net'); +const tls = require('tls'); +const fixtures = require('../common/fixtures'); -const socket = net.connect(443, 'www.example.org', common.mustCall(() => { - const secureSocket = tls.connect({ socket }, common.mustCall(() => { - secureSocket.destroy(); - console.log('ok'); +const server = tls.createServer({ + key: fixtures.readKey('agent1-key.pem'), + cert: fixtures.readKey('agent1-cert.pem') +}).listen(0, common.mustCall(() => { + const socket = net.connect(server.address().port, common.mustCall(() => { + const opts = { socket, rejectUnauthorized: false }; + const secureSocket = tls.connect(opts, common.mustCall(() => { + secureSocket.destroy(); + server.close(); + })); })); }));