2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2014-09-05 16:56:55 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
|
|
|
console.log('1..0 # Skipped: missing crypto');
|
|
|
|
process.exit();
|
|
|
|
}
|
2014-09-05 16:56:55 +02:00
|
|
|
var https = require('https');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2014-09-05 16:56:55 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
key: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-key.pem')),
|
|
|
|
cert: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-cert.pem'))
|
|
|
|
};
|
|
|
|
|
|
|
|
var reqCount = 0;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
var server = https.createServer(options, function(req, res) {
|
2014-09-05 16:56:55 +02:00
|
|
|
++reqCount;
|
|
|
|
res.writeHead(200);
|
|
|
|
res.end();
|
|
|
|
req.resume();
|
2015-05-19 13:00:06 +02:00
|
|
|
}).listen(common.PORT, function() {
|
2014-09-05 16:56:55 +02:00
|
|
|
authorized();
|
|
|
|
});
|
|
|
|
|
|
|
|
function authorized() {
|
|
|
|
var req = https.request({
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: true,
|
|
|
|
ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))]
|
2015-05-19 13:00:06 +02:00
|
|
|
}, function(res) {
|
2014-09-05 16:56:55 +02:00
|
|
|
assert(false);
|
|
|
|
});
|
2015-05-19 13:00:06 +02:00
|
|
|
req.on('error', function(err) {
|
2014-09-05 16:56:55 +02:00
|
|
|
override();
|
|
|
|
});
|
|
|
|
req.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
function override() {
|
|
|
|
var options = {
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: true,
|
|
|
|
ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))],
|
2015-05-19 13:00:06 +02:00
|
|
|
checkServerIdentity: function(host, cert) {
|
2014-09-05 16:56:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
options.agent = new https.Agent(options);
|
2015-05-19 13:00:06 +02:00
|
|
|
var req = https.request(options, function(res) {
|
2014-09-05 16:56:55 +02:00
|
|
|
assert(req.socket.authorized);
|
|
|
|
server.close();
|
|
|
|
});
|
2015-05-19 13:00:06 +02:00
|
|
|
req.on('error', function(err) {
|
2014-09-05 16:56:55 +02:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
req.end();
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('exit', function() {
|
2014-09-05 16:56:55 +02:00
|
|
|
assert.equal(reqCount, 1);
|
|
|
|
});
|