summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2019-06-03 13:35:48 -0700
committerAndy McCurdy <andy@andymccurdy.com>2019-06-03 13:50:47 -0700
commitf3e428d43b400b993955f9b4213a0794a43e8d96 (patch)
tree08804c2b74e2baf68c4d3e00e7db3fe1863cad88
parent64cf721a63ca7a9a94c0d92d8206f8f1f6900afc (diff)
downloadredis-py-f3e428d43b400b993955f9b4213a0794a43e8d96.tar.gz
All authentication-related errors now raise AuthenticationError
AuthenticationError is now a subclass of ConnectionError, which means the connection will be shut down and cleaned up. Fixes #923
-rwxr-xr-xredis/connection.py5
-rw-r--r--redis/exceptions.py6
-rw-r--r--tests/test_connection_pool.py14
3 files changed, 21 insertions, 4 deletions
diff --git a/redis/connection.py b/redis/connection.py
index a6572cb..88286c8 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -102,12 +102,15 @@ class Encoder(object):
class BaseParser(object):
EXCEPTION_CLASSES = {
'ERR': {
- 'max number of clients reached': ConnectionError
+ 'max number of clients reached': ConnectionError,
+ 'Client sent AUTH, but no password is set': AuthenticationError,
+ 'invalid password': AuthenticationError,
},
'EXECABORT': ExecAbortError,
'LOADING': BusyLoadingError,
'NOSCRIPT': NoScriptError,
'READONLY': ReadOnlyError,
+ 'NOAUTH': AuthenticationError,
}
def parse_error(self, response):
diff --git a/redis/exceptions.py b/redis/exceptions.py
index 35bfbe5..e7f2cbb 100644
--- a/redis/exceptions.py
+++ b/redis/exceptions.py
@@ -5,15 +5,15 @@ class RedisError(Exception):
pass
-class AuthenticationError(RedisError):
+class ConnectionError(RedisError):
pass
-class ConnectionError(RedisError):
+class TimeoutError(RedisError):
pass
-class TimeoutError(RedisError):
+class AuthenticationError(ConnectionError):
pass
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py
index 1f5797b..f258411 100644
--- a/tests/test_connection_pool.py
+++ b/tests/test_connection_pool.py
@@ -507,3 +507,17 @@ class TestConnection(object):
'UnixDomainSocketConnection',
'path=/path/to/socket,db=0',
)
+
+ def test_connect_no_auth_supplied_when_required(self, r):
+ """
+ AuthenticationError should be raised when the server requires a
+ password but one isn't supplied.
+ """
+ with pytest.raises(redis.AuthenticationError):
+ r.execute_command('DEBUG', 'ERROR',
+ 'ERR Client sent AUTH, but no password is set')
+
+ def test_connect_invalid_password_supplied(self, r):
+ "AuthenticationError should be raised when sending the wrong password"
+ with pytest.raises(redis.AuthenticationError):
+ r.execute_command('DEBUG', 'ERROR', 'ERR invalid password')