Files
node/test/parallel/test-https-client-override-global-agent.js
Daniel Bevenius 9abb646732 test: move require('https') to after crypto check
Currently, test-https-client-override-global-agent.js fails with the
following error when configured --without-ssl:

Error [ERR_NO_CRYPTO]:
Node.js is not compiled with OpenSSL crypto support
  at Object.assertCrypto (internal/util.js:101:11)
  ...
  at Object.<anonymous>
  (/node/test/parallel/test-https-client-override-global-agent.js:5:15)

This commit moves the require statement to after the crypto check.

PR-URL: https://github.com/nodejs/node/pull/25388
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-11 05:31:30 +01:00

38 lines
971 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const https = require('https');
// Disable strict server certificate validation by the client
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
};
const server = https.Server(options, common.mustCall((req, res) => {
res.writeHead(200);
res.end('Hello, World!');
}));
server.listen(0, common.mustCall(() => {
const agent = new https.Agent();
const name = agent.getName({ port: server.address().port });
https.globalAgent = agent;
makeRequest();
assert(agent.sockets.hasOwnProperty(name)); // agent has indeed been used
}));
function makeRequest() {
const req = https.get({
port: server.address().port
});
req.on('close', () =>
server.close());
}