1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Throw on other protocols provided than the redis protocol

This commit is contained in:
Ruben Bridgewater
2015-11-22 17:02:44 +01:00
parent bc85c4a01d
commit 30d2184dbb
2 changed files with 15 additions and 0 deletions

View File

@@ -1270,6 +1270,9 @@ var createClient = function (port_arg, host_arg, options) {
if (parsed.auth) { if (parsed.auth) {
options.auth_pass = parsed.auth.split(':')[1]; 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.host = parsed.hostname;
options.port = parsed.port; options.port = parsed.port;
} else { } else {

View File

@@ -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') { if (ip === 'IPv4') {
it('allows connecting with the redis url and the default port', function (done) { it('allows connecting with the redis url and the default port', function (done) {
client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]); client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]);