summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-01-31 01:26:41 -0500
committerBrian White <mscdex@mscdex.net>2016-02-03 21:34:06 -0500
commit2c357a7e3baa06b6cb1e18f627db1e69b93d1120 (patch)
tree589a3fa4d6ba2851a384233925f4747e74574868 /test
parent4501a28ad98ad897bbfc371026f9c663c1953716 (diff)
downloadnode-new-2c357a7e3baa06b6cb1e18f627db1e69b93d1120.tar.gz
tls: add getProtocol() to TLS sockets
This commit adds a new method for TLS sockets that returns the negotiated protocol version. PR-URL: https://github.com/nodejs/node/pull/4995 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-tls-getprotocol.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/parallel/test-tls-getprotocol.js b/test/parallel/test-tls-getprotocol.js
new file mode 100644
index 0000000000..67592143ee
--- /dev/null
+++ b/test/parallel/test-tls-getprotocol.js
@@ -0,0 +1,43 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+
+if (!common.hasCrypto) {
+ console.log('1..0 # Skipped: missing crypto');
+ return;
+}
+
+const tls = require('tls');
+const fs = require('fs');
+
+const clientConfigs = [
+ { secureProtocol: 'TLSv1_method', version: 'TLSv1' },
+ { secureProtocol: 'TLSv1_1_method', version: 'TLSv1.1' },
+ { secureProtocol: 'TLSv1_2_method', version: 'TLSv1.2' }
+];
+
+const serverConfig = {
+ key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
+ cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem')
+};
+
+const server = tls.createServer(serverConfig, common.mustCall(function() {
+
+}, clientConfigs.length)).listen(common.PORT, common.localhostIPv4, function() {
+ let connected = 0;
+ clientConfigs.forEach(function(v) {
+ tls.connect({
+ host: common.localhostIPv4,
+ port: common.PORT,
+ rejectUnauthorized: false,
+ secureProtocol: v.secureProtocol
+ }, common.mustCall(function() {
+ assert.strictEqual(this.getProtocol(), v.version);
+ this.on('end', common.mustCall(function() {
+ assert.strictEqual(this.getProtocol(), null);
+ })).end();
+ if (++connected === clientConfigs.length)
+ server.close();
+ }));
+ });
+});