diff --git a/index.js b/index.js index 9ee001e610..777383173e 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,14 @@ function RedisClient (options, stream) { EventEmitter.call(this); var cnx_options = {}; var self = this; + /* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */ + for (var tls_option in options.tls) { // jshint ignore: line + cnx_options[tls_option] = options.tls[tls_option]; + // Copy the tls options into the general options to make sure the address is set right + if (tls_option === 'port' || tls_option === 'host' || tls_option === 'path' || tls_option === 'family') { + options[tls_option] = options.tls[tls_option]; + } + } if (stream) { // The stream from the outside is used so no connection from this side is triggered but from the server this client should talk to // Reconnect etc won't work with this. This requires monkey patching to work, so it is not officially supported @@ -64,10 +72,6 @@ function RedisClient (options, stream) { cnx_options.family = (!options.family && net.isIP(cnx_options.host)) || (options.family === 'IPv6' ? 6 : 4); this.address = cnx_options.host + ':' + cnx_options.port; } - /* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */ - for (var tls_option in options.tls) { // jshint ignore: line - cnx_options[tls_option] = options.tls[tls_option]; - } // Warn on misusing deprecated functions if (typeof options.retry_strategy === 'function') { if ('max_attempts' in options) { diff --git a/test/tls.spec.js b/test/tls.spec.js index 40a424c27c..d977ee7d9a 100644 --- a/test/tls.spec.js +++ b/test/tls.spec.js @@ -60,6 +60,7 @@ describe('TLS connection tests', function () { tls: tls_options }); var time = 0; + assert.strictEqual(client.address, '127.0.0.1:' + tls_port); client.once('ready', function () { helper.killConnection(client); @@ -87,18 +88,20 @@ describe('TLS connection tests', function () { describe('when not connected', function () { - it('connect with host and port provided in the options object', function (done) { + it('connect with host and port provided in the tls object', function (done) { if (skip) this.skip(); + var tls = utils.clone(tls_options); + tls.port = tls_port; + tls.host = 'localhost'; client = redis.createClient({ - host: 'localhost', connect_timeout: 1000, - port: tls_port, - tls: tls_options + tls: tls }); // verify connection is using TCP, not UNIX socket assert.strictEqual(client.connection_options.host, 'localhost'); assert.strictEqual(client.connection_options.port, tls_port); + assert.strictEqual(client.address, 'localhost:' + tls_port); assert(client.stream.encrypted); client.set('foo', 'bar'); @@ -115,6 +118,7 @@ describe('TLS connection tests', function () { port: tls_port, tls: faulty_cert }); + assert.strictEqual(client.address, 'localhost:' + tls_port); client.on('error', function (err) { assert(/DEPTH_ZERO_SELF_SIGNED_CERT/.test(err.code || err.message), err); client.end(true);