|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + console.log('1..0 # Skipped: missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | + |
| 10 | +const tls = require('tls'); |
| 11 | +const fs = require('fs'); |
| 12 | + |
| 13 | +const clientConfigs = [ |
| 14 | + { secureProtocol: 'TLSv1_method', version: 'TLSv1' }, |
| 15 | + { secureProtocol: 'TLSv1_1_method', version: 'TLSv1.1' }, |
| 16 | + { secureProtocol: 'TLSv1_2_method', version: 'TLSv1.2' } |
| 17 | +]; |
| 18 | + |
| 19 | +const serverConfig = { |
| 20 | + key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), |
| 21 | + cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') |
| 22 | +}; |
| 23 | + |
| 24 | +const server = tls.createServer(serverConfig, common.mustCall(function() { |
| 25 | + |
| 26 | +}, clientConfigs.length)).listen(common.PORT, common.localhostIPv4, function() { |
| 27 | + let connected = 0; |
| 28 | + clientConfigs.forEach(function(v) { |
| 29 | + tls.connect({ |
| 30 | + host: common.localhostIPv4, |
| 31 | + port: common.PORT, |
| 32 | + rejectUnauthorized: false, |
| 33 | + secureProtocol: v.secureProtocol |
| 34 | + }, common.mustCall(function() { |
| 35 | + assert.strictEqual(this.getProtocol(), v.version); |
| 36 | + this.on('end', common.mustCall(function() { |
| 37 | + assert.strictEqual(this.getProtocol(), null); |
| 38 | + })).end(); |
| 39 | + if (++connected === clientConfigs.length) |
| 40 | + server.close(); |
| 41 | + })); |
| 42 | + }); |
| 43 | +}); |
0 commit comments