tls: return correct version from getCipher() · nodejs/node@0f745bf (original) (raw)
`@@ -30,28 +30,42 @@ const tls = require('tls');
`
30
30
`// Import fixtures directly from its module
`
31
31
`const fixtures = require('../common/fixtures');
`
32
32
``
33
``
`-
const cipher_list = ['AES128-SHA256', 'AES256-SHA256'];
`
34
``
`-
const cipher_version_pattern = /TLS|SSL/;
`
35
33
`const options = {
`
36
34
`key: fixtures.readKey('agent2-key.pem'),
`
37
35
`cert: fixtures.readKey('agent2-cert.pem'),
`
38
``
`-
ciphers: cipher_list.join(':'),
`
39
36
`honorCipherOrder: true
`
40
37
`};
`
41
38
``
42
``
`-
const server = tls.createServer(options, common.mustCall());
`
``
39
`+
let clients = 0;
`
``
40
`+
const server = tls.createServer(options, common.mustCall(() => {
`
``
41
`+
if (--clients === 0)
`
``
42
`+
server.close();
`
``
43
`+
}, 2));
`
43
44
``
44
45
`server.listen(0, '127.0.0.1', common.mustCall(function() {
`
45
``
`-
const client = tls.connect({
`
``
46
`+
clients++;
`
``
47
`+
tls.connect({
`
46
48
`host: '127.0.0.1',
`
47
49
`port: this.address().port,
`
48
``
`-
ciphers: cipher_list.join(':'),
`
``
50
`+
ciphers: 'AES128-SHA256',
`
49
51
`rejectUnauthorized: false
`
50
52
`}, common.mustCall(function() {
`
51
``
`-
const cipher = client.getCipher();
`
52
``
`-
assert.strictEqual(cipher.name, cipher_list[0]);
`
53
``
`-
assert(cipher_version_pattern.test(cipher.version));
`
54
``
`-
client.end();
`
55
``
`-
server.close();
`
``
53
`+
const cipher = this.getCipher();
`
``
54
`+
assert.strictEqual(cipher.name, 'AES128-SHA256');
`
``
55
`+
assert.strictEqual(cipher.version, 'TLSv1.2');
`
``
56
`+
this.end();
`
``
57
`+
}));
`
``
58
+
``
59
`+
clients++;
`
``
60
`+
tls.connect({
`
``
61
`+
host: '127.0.0.1',
`
``
62
`+
port: this.address().port,
`
``
63
`+
cipher: 'ECDHE-RSA-AES128-GCM-SHA256',
`
``
64
`+
rejectUnauthorized: false
`
``
65
`+
}, common.mustCall(function() {
`
``
66
`+
const cipher = this.getCipher();
`
``
67
`+
assert.strictEqual(cipher.name, 'ECDHE-RSA-AES128-GCM-SHA256');
`
``
68
`+
assert.strictEqual(cipher.version, 'TLSv1.2');
`
``
69
`+
this.end();
`
56
70
`}));
`
57
71
`}));
`