Skip to content

Commit

Permalink
Refs #1027: covering @paradiseng's contrib with fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farirat committed Feb 23, 2022
1 parent d4ec696 commit 4672cc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion jasmin/redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def clientConnectionFailed(self, connector, reason):

def __init__(self, uuid, dbid, poolsize, isLazy=True,
handler=redis.ConnectionHandler, config=None):
redis.RedisFactory.__init__(self, uuid, dbid, poolsize, isLazy, handler, password=config.password)
if isinstance(config, RedisForJasminConfig) and config.password is not None:
redis.RedisFactory.__init__(self, uuid, dbid, poolsize, isLazy, handler, password=config.password)
else:
redis.RedisFactory.__init__(self, uuid, dbid, poolsize, isLazy, handler)

# Set up a dedicated logger
self.log = logging.getLogger(LOG_CATEGORY)
Expand Down
26 changes: 17 additions & 9 deletions tests/redis/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,34 @@ def waitFor(seconds):
class AuthenticationTestCase(TestCase):
@defer.inlineCallbacks
def setUp(self):
# Connect to redis server
# Connect to redis server without authentication
self.RedisForJasminConfigInstance = RedisForJasminConfig()
self.redisClient = yield ConnectionWithConfiguration(self.RedisForJasminConfigInstance)
yield self.redisClient._connected

# Set password for default user
self.RedisForJasminConfigInstance.password = 'guest'
yield self.redisClient.execute_command(
'CONFIG', 'SET', 'requirepass', self.RedisForJasminConfigInstance.password)

# Disconnect and reconnect using password
yield self.redisClient.disconnect()
self.redisClient = yield ConnectionWithConfiguration(self.RedisForJasminConfigInstance)
yield self.redisClient._connected

@defer.inlineCallbacks
def tearDown(self):
# Before disconnecting: set the password for default user to '' (default behaviour)
yield self.redisClient.execute_command(
'CONFIG', 'SET', 'requirepass', '')

yield self.redisClient.disconnect()

@defer.inlineCallbacks
def test_auth(self):
try:
# Authenticate and select db
yield self.redisClient.auth(self.RedisForJasminConfigInstance.password)
yield self.redisClient.select(self.RedisForJasminConfigInstance.dbid)
except Exception as e:
self.assertEqual(type(e), redis.ResponseError)
self.assertEqual(str(e), 'ERR AUTH <password> called without any password configured for the default user. '
'Are you sure your configuration is correct?')
# Authenticate and select db
yield self.redisClient.auth(self.RedisForJasminConfigInstance.password)
yield self.redisClient.select(self.RedisForJasminConfigInstance.dbid)


class RedisTestCase(TestCase):
Expand Down

0 comments on commit 4672cc0

Please sign in to comment.