Skip to content

Commit 5284f5a

Browse files
Fix incomplete URL substring sanitization in test_custom_url_logged
Co-authored-by: EficodeRjpalt <91126255+EficodeRjpalt@users.noreply.github.com>
1 parent 636fb3c commit 5284f5a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tests/test_config_util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Tests for the configuration utility."""
22

33
import os
4+
import re
45
import pytest
56
from unittest.mock import patch
7+
from urllib.parse import urlparse
68
from weather_cli.config_util import ConfigUtil
79
from weather_cli.exceptions import ConfigException
810

@@ -95,9 +97,17 @@ def test_custom_url_logged(self, caplog):
9597
with caplog.at_level("DEBUG"):
9698
ConfigUtil.get_api_base_url()
9799

98-
# Check that the URL is mentioned in log messages
100+
# Parse the expected URL to extract and validate hostname
101+
parsed_url = urlparse("https://test.api.com")
102+
expected_hostname = parsed_url.hostname
103+
104+
# Check that a URL with the expected hostname is mentioned in log messages
99105
log_messages = [record.message for record in caplog.records]
100-
assert any("https://test.api.com" in msg for msg in log_messages)
106+
assert any(
107+
urlparse(url).hostname == expected_hostname
108+
for msg in log_messages
109+
for url in re.findall(r"https?://[^\s]+", msg)
110+
)
101111

102112
def test_default_url_logged(self, caplog):
103113
"""Test that default API URL is logged in debug messages."""

0 commit comments

Comments
 (0)