Preserve brackets around literal IPv6 hosts (#2552)
This commit is contained in:
		
							parent
							
								
									e6409568c1
								
							
						
					
					
						commit
						65b4f850a0
					
				|  | @ -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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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") | ||||
		Loading…
	
		Reference in New Issue