From 97fe7110defab9e873f5d1158e76c05ade948e5f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 8 Mar 2024 16:21:26 +0900 Subject: [PATCH] Redis: Add password to URL environment This is follow-up of d37bae254a627c0aef2e760b697336080193681f and ensures the password value is included in the url, presented by the URL environment, so that the value can be looked up. --- pifpaf/drivers/redis.py | 7 +++++-- pifpaf/tests/test_drivers.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pifpaf/drivers/redis.py b/pifpaf/drivers/redis.py index fcaeef7..c57e431 100644 --- a/pifpaf/drivers/redis.py +++ b/pifpaf/drivers/redis.py @@ -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 - self.putenv("URL", self.url) + if self.password: + url = "redis://:%s@localhost:%d" % (self.password, self.port) + else: + url = "redis://localhost:%d" % self.port + self.putenv("URL", url) diff --git a/pifpaf/tests/test_drivers.py b/pifpaf/tests/test_drivers.py index 9b1440a..4452a75 100644 --- a/pifpaf/tests/test_drivers.py +++ b/pifpaf/tests/test_drivers.py @@ -301,7 +301,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"))