Skip to content

Commit

Permalink
Redis: Add password to URL environment (#172)
Browse files Browse the repository at this point in the history
This is follow-up of d37bae2 and
ensures the password value is included in the url, presented by
the URL environment, so that the value can be looked up.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
kajinamit and mergify[bot] authored Aug 12, 2024
1 parent 9f08009 commit 43959ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pifpaf/drivers/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@ def _setUp(self):
str(self.sentinel_port))

self.putenv("REDIS_PORT", str(self.port))
self.url = "redis://localhost:%d" % self.port
if self.password:
self.url = "redis://:%s@localhost:%d" % (self.password, self.port)
else:
self.url = "redis://localhost:%d" % self.port
self.putenv("URL", self.url)
4 changes: 2 additions & 2 deletions pifpaf/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_redis(self):
def test_redis_with_password(self):
port = 6384
f = self.useFixture(redis.RedisDriver(port=port, password='secrete'))
self.assertEqual("redis://localhost:%d" % port,
self.assertEqual("redis://:secrete@localhost:%d" % port,
os.getenv("PIFPAF_URL"))
self.assertEqual(str(port), os.getenv("PIFPAF_REDIS_PORT"))
self._run("redis-cli -p %d -a secrete llen pifpaf" % f.port)
Expand All @@ -302,7 +302,7 @@ def test_redis_sentinel_with_password(self):
port = 6385
f = self.useFixture(redis.RedisDriver(sentinel=True, port=port,
password='secrete'))
self.assertEqual("redis://localhost:%d" % port,
self.assertEqual("redis://:secrete@localhost:%d" % port,
os.getenv("PIFPAF_URL"))
self.assertEqual(str(port), os.getenv("PIFPAF_REDIS_PORT"))
self.assertEqual("6380", os.getenv("PIFPAF_REDIS_SENTINEL_PORT"))
Expand Down

0 comments on commit 43959ac

Please sign in to comment.