Added non s3 scheme test. Removed .replace.

This commit is contained in:
RoyVivat 2026-03-23 15:50:59 -07:00
parent 7f5f3227d7
commit 1f1f623292
2 changed files with 11 additions and 1 deletions

View file

@ -7406,7 +7406,7 @@ def get_logging_id(start_time, response_obj):
# scheme and bucket, keeping only the object key to use as the log ID.
if "://" in raw_id:
after_scheme = raw_id.split("://", 1)[1] # "bucket/key" or "bucket"
safe_id = after_scheme.split("/", 1)[1].replace("/", "-") if "/" in after_scheme else ""
safe_id = after_scheme.split("/", 1)[1] if "/" in after_scheme else ""
else:
safe_id = raw_id
response_id = "time-" + start_time.strftime("%H-%M-%S-%f") + "_" + safe_id

View file

@ -705,6 +705,16 @@ def test_get_logging_id_none_id_does_not_raise():
assert result.startswith("time-17-40-11-901585_")
def test_get_logging_id_non_s3_uri_scheme_stripped():
"""Non-S3 URI schemes (e.g. ftp://) are also stripped — lock in that behaviour."""
start_time = datetime(2026, 3, 9, 17, 40, 11, 901585)
response_obj = {"id": "ftp://host/path/to/file"}
result = get_logging_id(start_time, response_obj)
assert "://" not in result
assert "host" not in result
assert result.startswith("time-17-40-11-901585_")
def test_get_logging_id_s3_uri_safe_for_url_path():
"""The sanitized log ID must be embeddable in an S3 object key URL without creating a malformed path."""
start_time = datetime(2026, 3, 9, 17, 40, 11, 901585)