Skip to content

Commit

Permalink
feat: Automatically set tls.servername option with rediss:// URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Aug 20, 2019
1 parent 0d190ec commit d6fc213
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions test/unit/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d6fc213

Please sign in to comment.