Skip to content

Commit

Permalink
fix: Don’t clobber passed-in tls options with rediss:/ URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Aug 20, 2019
1 parent c1f0d03 commit 0d190ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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") {
Expand Down
3 changes: 0 additions & 3 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/unit/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d190ec

Please sign in to comment.