Skip to content

Commit

Permalink
Sanitize provided ARL templates
Browse files Browse the repository at this point in the history
ARL templates are extracted from environment variable which can in
practice easily include some trailing whitespace characters. Unstripped
ARLs with trailing whitechars are not accepted by the FastPurge API
resulting in 4xx errors.
  • Loading branch information
rbikar committed Oct 26, 2023
1 parent 02a744f commit 5d46b63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/test_cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def test_publisher_with_cache_purge(pulp, requests_mock):
"clean": True,
},
"cdn_root": "https://cdn.example.com",
"arl_templates": ["/arl/1/test/{ttl}/{path}", "/arl/2/test/{ttl}/{path}"],
"arl_templates": [
"/arl/1/test/{ttl}/{path}",
"/arl/2/test/{ttl}/{path}",
# extra case with whitespace chars
" /arl/3/test/{ttl}/{path} /extra// \n\n \t ",
],
"max_retry_sleep": 0.001,
}
setup_fastpurge_mock(requests_mock)
Expand Down Expand Up @@ -137,6 +142,7 @@ def test_publisher_with_cache_purge(pulp, requests_mock):
"https://cdn.example.com/content/unit/1/client/repomd.xml",
"/arl/1/test/33s/content/unit/1/client/repomd.xml",
"/arl/2/test/33s/content/unit/1/client/repomd.xml",
"/arl/3/test/33s/content/unit/1/client/repomd.xml /extra//",
]


Expand Down
2 changes: 1 addition & 1 deletion ubipop/_cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def __init__(self, url, arl_templates=None, max_retry_sleep=_MAX_SLEEP, **kwargs
used within this class (e.g. "verify", "cert").
"""
self._url = url
self._arl_templates = arl_templates
self._arl_templates = [item.strip() for item in arl_templates if item]
self._tls = threading.local()

retry_args = {
Expand Down

0 comments on commit 5d46b63

Please sign in to comment.