summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2019-01-27 12:24:03 -0800
committerAndy McCurdy <andy@andymccurdy.com>2019-01-27 12:24:03 -0800
commit5a2e26d2b0b554bfcd6875a968bcd8090b7f9b03 (patch)
tree7ab6f053294cda0c1c01b2c58b980f2513c239a8
parent04ddd34ec55a659b5bb8c1ac8c47899781b90a6d (diff)
downloadredis-py-5a2e26d2b0b554bfcd6875a968bcd8090b7f9b03.tar.gz
Connection URLs must have a valid scheme.
Fixes #969 Fixes #961
-rw-r--r--CHANGES2
-rwxr-xr-xredis/connection.py8
-rw-r--r--tests/test_connection_pool.py4
3 files changed, 12 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 9b0f51c..783f869 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,6 @@
* 3.1.0 (in development)
+ * Connection URLs must have one of the following schemes:
+ redis://, rediss://, unix://. Thanks @jdupl123. #961/#969
* Fixed an issue with retry_on_timeout logic that caused some TimeoutErrors
to be retried. Thanks Aaron Yang. #1022/#1023
* Added support for SNI for SSL. Thanks @oridistor and Roey Prat. #1087
diff --git a/redis/connection.py b/redis/connection.py
index cf5ed0e..0d1c394 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -885,7 +885,7 @@ class ConnectionPool(object):
path = url.path
hostname = url.hostname
- # We only support redis:// and unix:// schemes.
+ # We only support redis://, rediss:// and unix:// schemes.
if url.scheme == 'unix':
url_options.update({
'password': password,
@@ -893,7 +893,7 @@ class ConnectionPool(object):
'connection_class': UnixDomainSocketConnection,
})
- else:
+ elif url.scheme in ('redis', 'rediss'):
url_options.update({
'host': hostname,
'port': int(url.port or 6379),
@@ -910,6 +910,10 @@ class ConnectionPool(object):
if url.scheme == 'rediss':
url_options['connection_class'] = SSLConnection
+ else:
+ valid_schemes = ', '.join(('redis://', 'rediss://', 'unix://'))
+ raise ValueError('Redis URL must specify one of the following'
+ 'schemes (%s)' % valid_schemes)
# last shot at the db value
url_options['db'] = int(url_options.get('db', db or 0))
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py
index b0dec67..ca56a76 100644
--- a/tests/test_connection_pool.py
+++ b/tests/test_connection_pool.py
@@ -308,6 +308,10 @@ class TestConnectionPoolURLParsing(object):
'password': None,
}
+ def test_invalid_scheme_raises_error(self):
+ with pytest.raises(ValueError):
+ redis.ConnectionPool.from_url('localhost')
+
class TestConnectionPoolUnixSocketURLParsing(object):
def test_defaults(self):