Skip to content

Commit

Permalink
Throw on other protocols provided than the redis protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Nov 23, 2015
1 parent bc85c4a commit 30d2184
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,9 @@ var createClient = function (port_arg, host_arg, options) {
if (parsed.auth) {
options.auth_pass = parsed.auth.split(':')[1];
}
if (parsed.protocol !== 'redis:') {
throw new Error('Connection string must use the "redis:" protocol');
}
options.host = parsed.hostname;
options.port = parsed.port;
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ describe("connection tests", function () {
}
});

it("throws on protocol other than redis in the redis url", function () {
client = {
end: function() {}
};
try {
redis.createClient(config.HOST[ip] + ':' + config.PORT);
throw new Error('failed');
} catch (err) {
assert.equal(err.message, 'Connection string must use the "redis:" protocol');
}
});

if (ip === 'IPv4') {
it('allows connecting with the redis url and the default port', function (done) {
client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]);
Expand Down

0 comments on commit 30d2184

Please sign in to comment.