0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/parallel/test-tls-getcipher.js
Ethan Arrowood be1f52b498 test: updated tls-getcipher test
Changed var to ES6 syntax const/let.
Added common.mustCall function wrapper to all functions
called exactly once.
Changed assert.equal to assert.strictEqual.

PR-URL: https://github.com/nodejs/node/pull/9923
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-05 08:34:41 -08:00

38 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
const assert = require('assert');
const tls = require('tls');
const fs = require('fs');
const cipher_list = ['AES128-SHA256', 'AES256-SHA256'];
const cipher_version_pattern = /TLS|SSL/;
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
ciphers: cipher_list.join(':'),
honorCipherOrder: true
};
const server = tls.createServer(options,
common.mustCall(function(cleartextStream) {}));
server.listen(0, '127.0.0.1', common.mustCall(function() {
const client = tls.connect({
host: '127.0.0.1',
port: this.address().port,
ciphers: cipher_list.join(':'),
rejectUnauthorized: false
}, common.mustCall(function() {
const cipher = client.getCipher();
assert.strictEqual(cipher.name, cipher_list[0]);
assert(cipher_version_pattern.test(cipher.version));
client.end();
server.close();
}));
}));