From 0d190ecf3e1ff6d1b9708ff10180618a513ca4f2 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Tue, 20 Aug 2019 18:09:56 +0100 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20Don=E2=80=99t=20clobber=20passed-in?= =?UTF-8?q?=20tls=20options=20with=20rediss:/=20URLs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/redis/index.ts | 7 +++++++ lib/utils/index.ts | 3 --- test/unit/redis.ts | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/redis/index.ts b/lib/redis/index.ts index 9524eee7..7c9e64a8 100644 --- a/lib/redis/index.ts +++ b/lib/redis/index.ts @@ -192,6 +192,7 @@ Redis.prototype.resetOfflineQueue = function() { Redis.prototype.parseOptions = function() { this.options = {}; + let isTls = false; for (var i = 0; i < arguments.length; ++i) { var arg = arguments[i]; if (arg === null || typeof arg === "undefined") { @@ -201,12 +202,18 @@ Redis.prototype.parseOptions = function() { defaults(this.options, arg); } else if (typeof arg === "string") { defaults(this.options, parseURL(arg)); + if (arg.startsWith('rediss://')) { + isTls = true + } } else if (typeof arg === "number") { this.options.port = arg; } else { throw new Error("Invalid argument " + arg); } } + if (isTls) { + defaults(this.options, {tls: true}) + } defaults(this.options, Redis.defaultOptions); if (typeof this.options.port === "string") { diff --git a/lib/utils/index.ts b/lib/utils/index.ts index a97bd288..fb37c791 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -274,9 +274,6 @@ export function parseURL(url) { if (parsed.port) { result.port = parsed.port; } - if (parsed.protocol === "rediss:") { - result.tls = true; - } defaults(result, parsed.query); return result; diff --git a/test/unit/redis.ts b/test/unit/redis.ts index 48fe36de..655fa5d3 100644 --- a/test/unit/redis.ts +++ b/test/unit/redis.ts @@ -80,6 +80,12 @@ describe("Redis", function() { host: "192.168.1.1" }); expect(option).to.have.property("port", 6380); + + option = getOption("rediss://host") + expect(option).to.have.property("tls", true) + + option = getOption("rediss://example.test", { tls: { hostname: "example.test" } }); + expect(option.tls).to.deep.equal({hostname: "example.test"}) } catch (err) { stub.restore(); throw err; From d6fc2139ceea668eff23f70784cffba2933326b4 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Tue, 20 Aug 2019 18:18:40 +0100 Subject: [PATCH 2/3] feat: Automatically set tls.servername option with rediss:// URLs --- lib/redis/index.ts | 6 +++--- test/unit/redis.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/redis/index.ts b/lib/redis/index.ts index 7c9e64a8..92505b01 100644 --- a/lib/redis/index.ts +++ b/lib/redis/index.ts @@ -202,8 +202,8 @@ Redis.prototype.parseOptions = function() { defaults(this.options, arg); } else if (typeof arg === "string") { defaults(this.options, parseURL(arg)); - if (arg.startsWith('rediss://')) { - isTls = true + if (arg.startsWith("rediss://")) { + isTls = true; } } else if (typeof arg === "number") { this.options.port = arg; @@ -212,7 +212,7 @@ Redis.prototype.parseOptions = function() { } } if (isTls) { - defaults(this.options, {tls: true}) + defaults(this.options, { tls: { servername: this.options.host } }); } defaults(this.options, Redis.defaultOptions); diff --git a/test/unit/redis.ts b/test/unit/redis.ts index 655fa5d3..a6dada93 100644 --- a/test/unit/redis.ts +++ b/test/unit/redis.ts @@ -81,11 +81,13 @@ describe("Redis", function() { }); expect(option).to.have.property("port", 6380); - option = getOption("rediss://host") - expect(option).to.have.property("tls", true) + option = getOption("rediss://host.test"); + expect(option.tls).to.deep.equal({ servername: "host.test" }); - option = getOption("rediss://example.test", { tls: { hostname: "example.test" } }); - expect(option.tls).to.deep.equal({hostname: "example.test"}) + option = getOption("rediss://example.test", { + tls: { rejectUnauthorized: false } + }); + expect(option.tls).to.deep.equal({ rejectUnauthorized: false }); } catch (err) { stub.restore(); throw err; From e20df82e4733860bd1344a90f2459a8ef51d7587 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Sun, 25 Aug 2019 08:14:33 -0400 Subject: [PATCH 3/3] Fix test --- test/unit/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/utils.ts b/test/unit/utils.ts index 7993b12d..52d2aae8 100644 --- a/test/unit/utils.ts +++ b/test/unit/utils.ts @@ -195,7 +195,6 @@ describe("utils", function() { expect( utils.parseURL("rediss://user:pass@127.0.0.1:6380/4?key=value") ).to.eql({ - tls: true, host: "127.0.0.1", port: "6380", db: "4",