2016-01-31 01:26:41 -05:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2017-07-01 02:29:09 +03:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip('missing crypto');
|
2016-01-31 01:26:41 -05:00
|
|
|
|
2017-11-06 15:03:43 +00:00
|
|
|
// This test ensures that `getProtocol` returns the right protocol
|
|
|
|
// from a TLS connection
|
|
|
|
|
2017-07-01 02:29:09 +03:00
|
|
|
const assert = require('assert');
|
2016-01-31 01:26:41 -05:00
|
|
|
const tls = require('tls');
|
2017-11-06 15:03:43 +00:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-01-31 01:26:41 -05:00
|
|
|
|
|
|
|
const clientConfigs = [
|
|
|
|
{ secureProtocol: 'TLSv1_method', version: 'TLSv1' },
|
|
|
|
{ secureProtocol: 'TLSv1_1_method', version: 'TLSv1.1' },
|
|
|
|
{ secureProtocol: 'TLSv1_2_method', version: 'TLSv1.2' }
|
|
|
|
];
|
|
|
|
|
|
|
|
const serverConfig = {
|
2018-10-22 11:40:28 +02:00
|
|
|
secureProtocol: 'TLS_method',
|
2019-05-29 17:03:05 -07:00
|
|
|
key: fixtures.readKey('agent2-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent2-cert.pem')
|
2016-01-31 01:26:41 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const server = tls.createServer(serverConfig, common.mustCall(function() {
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
}, clientConfigs.length)).listen(0, common.localhostIPv4, function() {
|
2016-01-31 01:26:41 -05:00
|
|
|
let connected = 0;
|
|
|
|
clientConfigs.forEach(function(v) {
|
|
|
|
tls.connect({
|
|
|
|
host: common.localhostIPv4,
|
2016-05-29 03:06:56 -04:00
|
|
|
port: server.address().port,
|
2016-01-31 01:26:41 -05:00
|
|
|
rejectUnauthorized: false,
|
|
|
|
secureProtocol: v.secureProtocol
|
|
|
|
}, common.mustCall(function() {
|
|
|
|
assert.strictEqual(this.getProtocol(), v.version);
|
2020-02-15 01:56:01 +01:00
|
|
|
this.on('end', common.mustCall());
|
|
|
|
this.on('close', common.mustCall(function() {
|
2016-01-31 01:26:41 -05:00
|
|
|
assert.strictEqual(this.getProtocol(), null);
|
|
|
|
})).end();
|
|
|
|
if (++connected === clientConfigs.length)
|
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|