Skip to content

Commit 4e5c2f8

Browse files
authored
Merge pull request #1241 from lsst-sqre/tickets/DM-48870
DM-48870: Fix escaping of Redis passwords
2 parents 63bffd0 + 7dfe8b6 commit 4e5c2f8

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Gafaelfawr does not support direct upgrades from versions older than 10.0.0. Whe
1010

1111
<!-- scriv-insert-here -->
1212

13+
<a id='changelog-12.5.2'></a>
14+
## 12.5.2 (2025-02-10)
15+
16+
### Bug fixes
17+
18+
- Fix escaping of the Redis password to use the correct library function.
19+
1320
<a id='changelog-12.5.1'></a>
1421
## 12.5.1 (2025-02-10)
1522

src/gafaelfawr/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ipaddress import IPv4Network, IPv6Network
2626
from pathlib import Path
2727
from typing import Annotated, Any, Self
28-
from urllib.parse import urlencode
28+
from urllib.parse import quote
2929

3030
import yaml
3131
from pydantic import (
@@ -1096,7 +1096,7 @@ def redis_rate_limit_url(self) -> str:
10961096
netloc = f"{host}:{port}" if port else host
10971097
path = self.redis_ephemeral_url.path
10981098
if self.redis_password:
1099-
password = urlencode(self.redis_password.get_secret_value())
1099+
password = quote(self.redis_password.get_secret_value(), safe="")
11001100
return f"async+redis://:{password}@{netloc}{path}"
11011101
else:
11021102
return f"async+redis://{netloc}{path}"

tests/config_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ def test_config_cilogon_test(monkeypatch: pytest.MonkeyPatch) -> None:
136136
}
137137
)
138138
assert str(config.oidc.redirect_url) == "https://example.com/login"
139+
140+
141+
def test_redis_rate_limit_url(monkeypatch: pytest.MonkeyPatch) -> None:
142+
ephemeral = "redis://gafaelfawr-redis-ephemeral.gafaelfawr:6370/1"
143+
persistent = "redis://gafaelfawr-redis.gafaelfawr:6370/0"
144+
monkeypatch.delenv("REDIS_6379_TCP_PORT")
145+
monkeypatch.delenv("REDIS_HOST")
146+
monkeypatch.setenv("GAFAELFAWR_REDIS_EPHEMERAL_URL", ephemeral)
147+
monkeypatch.setenv("GAFAELFAWR_REDIS_PERSISTENT_URL", persistent)
148+
monkeypatch.setenv("GAFAELFAWR_REDIS_PASSWORD", "f:b/b@c")
149+
config = parse_config(config_path("github"))
150+
assert str(config.redis_ephemeral_url) == ephemeral
151+
assert str(config.redis_persistent_url) == persistent
152+
assert config.redis_rate_limit_url == (
153+
"async+redis://:f%3Ab%2Fb%[email protected]"
154+
":6370/1"
155+
)

0 commit comments

Comments
 (0)