node/test/parallel/test-https-client-checkServerIdentity.js
Emily Marigold Klassen 48a55d1364
test: use common.fixtures in checkServerIdentity
PR-URL: https://github.com/nodejs/node/pull/15951
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-11-28 13:09:58 +09:00

53 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const https = require('https');
const options = {
key: fixtures.readKey('agent3-key.pem'),
cert: fixtures.readKey('agent3-cert.pem')
};
const server = https.createServer(options, common.mustCall(function(req, res) {
res.writeHead(200);
res.end();
req.resume();
})).listen(0, function() {
authorized();
});
function authorized() {
const req = https.request({
port: server.address().port,
rejectUnauthorized: true,
ca: [fixtures.readKey('ca2-cert.pem')]
}, common.mustNotCall());
req.on('error', function(err) {
override();
});
req.end();
}
function override() {
const options = {
port: server.address().port,
rejectUnauthorized: true,
ca: [fixtures.readKey('ca2-cert.pem')],
checkServerIdentity: function(host, cert) {
return false;
}
};
options.agent = new https.Agent(options);
const req = https.request(options, function(res) {
assert(req.socket.authorized);
server.close();
});
req.on('error', function(err) {
throw err;
});
req.end();
}