Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2420](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2420))
- `opentelemetry-instrumentation-asyncio` Check for __name__ attribute in the coroutine
([#2521](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2521))
- `opentelemetry-util-http` Preserve brackets around literal IPv6 hosts ([#2552](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2552))

## Version 1.24.0/0.45b0 (2024-03-28)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ def remove_url_credentials(url: str) -> str:
parsed = urlparse(url)
if all([parsed.scheme, parsed.netloc]): # checks for valid url
parsed_url = urlparse(url)
netloc = (
(":".join(((parsed_url.hostname or ""), str(parsed_url.port))))
if parsed_url.port
else (parsed_url.hostname or "")
)
_, _, netloc = parsed.netloc.rpartition("@")
return urlunparse(
(
parsed_url.scheme,
Expand Down
27 changes: 27 additions & 0 deletions util/opentelemetry-util-http/tests/test_remove_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from opentelemetry.util.http import remove_url_credentials


class TestRemoveUrlCredentials(unittest.TestCase):
def test_remove_no_credentials(self):
url = "http://opentelemetry.io:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, url)

def test_remove_credentials(self):
url = "http://someuser:somepass@opentelemetry.io:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(
cleaned_url, "http://opentelemetry.io:8080/test/path?query=value"
)

def test_remove_credentials_ipv4_literal(self):
url = "http://someuser:somepass@127.0.0.1:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, "http://127.0.0.1:8080/test/path?query=value")

def test_remove_credentials_ipv6_literal(self):
url = "http://someuser:somepass@[::1]:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, "http://[::1]:8080/test/path?query=value")