From 7cd6e0b8829d20dba26697b29a2fdfd3a6e7ab12 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: May 05 2018 09:28:55 +0000 Subject: Do not lowercase hostnames with custom-protocol (rhbz 1574684) upstream: https://github.com/urllib3/urllib3/issues/1267 --- diff --git a/0001-only-normalize-http-s-urls.patch b/0001-only-normalize-http-s-urls.patch new file mode 100644 index 0000000..7fae8c5 --- /dev/null +++ b/0001-only-normalize-http-s-urls.patch @@ -0,0 +1,62 @@ +From b67976b2a85b0d5f5c3dc53ec4ad41f22e2992f6 Mon Sep 17 00:00:00 2001 +From: Nate Prewitt +Date: Sun, 12 Feb 2017 14:01:00 -0700 +Subject: [PATCH] only normalize http(s) urls + +--- + test/test_util.py | 8 +++++++- + urllib3/util/url.py | 6 +++++- + 2 files changed, 12 insertions(+), 2 deletions(-) + +diff --git a/test/test_util.py b/test/test_util.py +index 543924d..a909acf 100644 +--- a/test/test_util.py ++++ b/test/test_util.py +@@ -109,7 +109,10 @@ class TestUtil(unittest.TestCase): + self.assertRaises(LocationParseError, get_host, location) + + def test_host_normalization(self): +- """Asserts the scheme and host is normalized to lower-case.""" ++ """ ++ Asserts the scheme and hosts with a normalizable scheme are ++ converted to lower-case. ++ """ + url_host_map = { + # Hosts + 'HTTP://GOOGLE.COM/mail/': ('http', 'google.com', None), +@@ -121,6 +124,8 @@ class TestUtil(unittest.TestCase): + 'HTTP://[2a00:1450:4001:c01::67]:80/test': ('http', '[2a00:1450:4001:c01::67]', 80), + 'HTTP://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000/index.html': ('http', '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', 8000), + 'HTTPS://[1080:0:0:0:8:800:200c:417A]/index.html': ('https', '[1080:0:0:0:8:800:200c:417a]', None), ++ 'http+UNIX://%2fvar%2frun%2fSOCKET/path': ( ++ 'http+unix', '%2fvar%2frun%2fSOCKET', None), + } + for url, expected_host in url_host_map.items(): + returned_host = get_host(url) +diff --git a/urllib3/util/url.py b/urllib3/util/url.py +index 61a326e..6b6f996 100644 +--- a/urllib3/util/url.py ++++ b/urllib3/util/url.py +@@ -6,6 +6,10 @@ from ..exceptions import LocationParseError + + url_attrs = ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment'] + ++# We only want to normalize urls with an HTTP(S) scheme. ++# urllib3 infers URLs without a scheme (None) to be http. ++NORMALIZABLE_SCHEMES = ('http', 'https', None) ++ + + class Url(namedtuple('Url', url_attrs)): + """ +@@ -21,7 +25,7 @@ class Url(namedtuple('Url', url_attrs)): + path = '/' + path + if scheme: + scheme = scheme.lower() +- if host: ++ if host and scheme in NORMALIZABLE_SCHEMES: + host = host.lower() + return super(Url, cls).__new__(cls, scheme, auth, host, port, path, + query, fragment) +-- +2.17.0 + diff --git a/0002-Do-not-lowercase-hostnames-with-custom-protocol.patch b/0002-Do-not-lowercase-hostnames-with-custom-protocol.patch new file mode 100644 index 0000000..d18f7c2 --- /dev/null +++ b/0002-Do-not-lowercase-hostnames-with-custom-protocol.patch @@ -0,0 +1,120 @@ +From d267a4d236f7676ffc2def28fdaa16538f7da6c6 Mon Sep 17 00:00:00 2001 +From: Lukas Slebodnik +Date: Sat, 5 May 2018 10:37:32 +0200 +Subject: [PATCH 2/2] Do not lowercase hostnames with custom-protocol(#1267) + +Unix sockets are are case sensitive the same as other files +on standard unix file systems. +--- + test/test_connectionpool.py | 40 +++++++++++++++++++++++++++++++++++++ + urllib3/connectionpool.py | 10 ++++++---- + 2 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/test/test_connectionpool.py b/test/test_connectionpool.py +index c49e416e8e8cfeb5e35d7ed6246560d186b08159..cf8dcbf32983007cde5fbeec536b5476631588e6 100644 +--- a/test/test_connectionpool.py ++++ b/test/test_connectionpool.py +@@ -32,6 +32,19 @@ from ssl import SSLError as BaseSSLError + from dummyserver.server import DEFAULT_CA + + ++class HTTPUnixConnection(HTTPConnection): ++ def __init__(self, host, timeout=60, **kwargs): ++ super(HTTPUnixConnection, self).__init__('localhost') ++ self.unix_socket = host ++ self.timeout = timeout ++ self.sock = None ++ ++ ++class HTTPUnixConnectionPool(HTTPConnectionPool): ++ scheme = 'http+unix' ++ ConnectionCls = HTTPUnixConnection ++ ++ + class TestConnectionPool(unittest.TestCase): + """ + Tests in this suite should exercise the ConnectionPool functionality +@@ -140,6 +153,33 @@ class TestConnectionPool(unittest.TestCase): + c = HTTPSConnectionPool(b) + self.assertFalse(c.is_same_host(a), "%s =? %s" % (b, a)) + ++ def test_same_host_custom_protocol(self): ++ same_host_custom_protocol = [ ++ ('%2Fvar%2Frun%2Fdocker.sock', ++ 'http+unix://%2Fvar%2Frun%2Fdocker.sock'), ++ ('%2Fvar%2Frun%2Fdocker.sock', ++ 'http+unix://%2Fvar%2Frun%2Fdocker.sock/'), ++ ('%2Fvar%2Frun%2Fdocker.sock', ++ 'http+unix://%2Fvar%2Frun%2Fdocker.sock/abracadabra'), ++ ('%2Ftmp%2FTEST.sock', 'http+unix://%2Ftmp%2FTEST.sock'), ++ ('%2Ftmp%2FTEST.sock', 'http+unix://%2Ftmp%2FTEST.sock/'), ++ ('%2Ftmp%2FTEST.sock', 'http+unix://%2Ftmp%2FTEST.sock/abracadab'), ++ ] ++ for a, b in same_host_custom_protocol: ++ with HTTPUnixConnectionPool(a) as c: ++ assert c.is_same_host(b) ++ ++ def test_not_same_host_custom_protocol(self): ++ not_same_host_custom_protocol = [ ++ ('%2Ftmp%2Ftest.sock', 'http+unix://%2Ftmp%2FTEST.sock'), ++ ('%2Ftmp%2Ftest.sock', 'http+unix://%2Ftmp%2FTEST.sock/'), ++ ('%2Ftmp%2Ftest.sock', 'http+unix://%2Ftmp%2FTEST.sock/abracadab'), ++ ('%2Fvar%2Frun%2Fdocker.sock', 'http+unix://%2Ftmp%2FTEST.sock'), ++ ] ++ for a, b in not_same_host_custom_protocol: ++ with HTTPUnixConnectionPool(a) as c: ++ assert not c.is_same_host(b) ++ + def test_max_connections(self): + pool = HTTPConnectionPool(host='localhost', maxsize=1, block=True) + +diff --git a/urllib3/connectionpool.py b/urllib3/connectionpool.py +index b4f1166a694c3055339bd7e9049252a45a84d630..8c49c170c1dede4edc30e57f23d6983db8643530 100644 +--- a/urllib3/connectionpool.py ++++ b/urllib3/connectionpool.py +@@ -40,7 +40,7 @@ from .util.request import set_file_position + from .util.response import assert_header_parsing + from .util.retry import Retry + from .util.timeout import Timeout +-from .util.url import get_host, Url ++from .util.url import get_host, Url, NORMALIZABLE_SCHEMES + + + if six.PY2: +@@ -68,7 +68,7 @@ class ConnectionPool(object): + if not host: + raise LocationValueError("No host specified.") + +- self.host = _ipv6_host(host).lower() ++ self.host = _ipv6_host(host, self.scheme) + self.port = port + + def __str__(self): +@@ -433,7 +433,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): + # TODO: Add optional support for socket.gethostbyname checking. + scheme, host, port = get_host(url) + +- host = _ipv6_host(host).lower() ++ host = _ipv6_host(host, self.scheme) + + # Use explicit default port for comparison when none is given + if self.port and not port: +@@ -880,7 +880,7 @@ def connection_from_url(url, **kw): + return HTTPConnectionPool(host, port=port, **kw) + + +-def _ipv6_host(host): ++def _ipv6_host(host, scheme): + """ + Process IPv6 address literals + """ +@@ -896,4 +896,6 @@ def _ipv6_host(host): + # percent sign might be URIencoded, convert it back into ASCII + if host.startswith('[') and host.endswith(']'): + host = host.replace('%25', '%').strip('[]') ++ if scheme in NORMALIZABLE_SCHEMES: ++ host = host.lower() + return host +-- +2.17.0 + diff --git a/0003-Move-RECENT_DATE-to-2017-06-30.patch b/0003-Move-RECENT_DATE-to-2017-06-30.patch new file mode 100644 index 0000000..8536ada --- /dev/null +++ b/0003-Move-RECENT_DATE-to-2017-06-30.patch @@ -0,0 +1,38 @@ +From 4bff1e93d2dd4663d422d7e290473d9189cec5db Mon Sep 17 00:00:00 2001 +From: Dominique Leuenberger +Date: Sun, 31 Dec 2017 15:11:16 +0100 +Subject: [PATCH] Move RECENT_DATE to 2017-06-30 + +The test suite expects the current date to be no more than two years in the future +of RECENT_DATE, which just serves as a reference point. + +Also clarify the comment about how to update RECENT_DATE + +Fixes #1303 +--- + urllib3/connection.py | 9 +++++---- + 2 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/urllib3/connection.py b/urllib3/connection.py +index 06bcbde1af7af11257357d9f786fb4b0976063fd..a03b573f01d82973f8d64a0bac4819eec63c24c6 100644 +--- a/urllib3/connection.py ++++ b/urllib3/connection.py +@@ -56,10 +56,11 @@ port_by_scheme = { + 'https': 443, + } + +-# When updating RECENT_DATE, move it to +-# within two years of the current date, and no +-# earlier than 6 months ago. +-RECENT_DATE = datetime.date(2016, 1, 1) ++# When updating RECENT_DATE, move it to within two years of the current date, ++# and not less than 6 months ago. ++# Example: if Today is 2018-01-01, then RECENT_DATE should be any date on or ++# after 2016-01-01 (today - 2 years) AND before 2017-07-01 (today - 6 months) ++RECENT_DATE = datetime.date(2017, 6, 30) + + + class DummyConnection(object): +-- +2.17.0 + diff --git a/python-urllib3.spec b/python-urllib3.spec index 3f51dce..f9547fc 100644 --- a/python-urllib3.spec +++ b/python-urllib3.spec @@ -2,7 +2,7 @@ Name: python-%{srcname} Version: 1.20 -Release: 2%{?dist} +Release: 3%{?dist} Summary: Python HTTP library with thread-safe connection pooling and file post License: MIT @@ -10,6 +10,12 @@ URL: https://github.com/shazow/urllib3 Source0: %{url}/archive/%{version}/%{srcname}-%{version}.tar.gz # Used with Python 3.5+ Source1: ssl_match_hostname_py3.py +# https://github.com/urllib3/urllib3/commit/b67976b2a85b0d5f5c3dc53ec4ad41f22e2992f6 +Patch0001: 0001-only-normalize-http-s-urls.patch +# https://github.com/urllib3/urllib3/commit/9f09cb4b9d69bd8944c881f61b8fe933ad425b5b +Patch0002: 0002-Do-not-lowercase-hostnames-with-custom-protocol.patch +# https://github.com/urllib3/urllib3/commit/4bff1e93d2dd4663d422d7e290473d9189cec5db +Patch0003: 0003-Move-RECENT_DATE-to-2017-06-30.patch BuildArch: noarch %description @@ -73,6 +79,10 @@ Python3 HTTP module with connection pooling and file POST abilities. %prep %setup -q -n %{srcname}-%{version} +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 + # Drop the dummyserver tests in koji. They fail there in real builds, but not # in scratch builds (weird). rm -rf test/with_dummyserver/ @@ -135,6 +145,10 @@ nosetests-%{python3_version} %changelog +* Thu May 03 2018 Lukas Slebodnik - 1.20-3 +- Do not lowercase hostnames with custom-protocol (rhbz 1574684) +- upstream: https://github.com/urllib3/urllib3/issues/1267 + * Fri Dec 01 2017 Jeremy Cline - 1.20-2 - Symlink the Python 3 bytecode for six (rbhz 1519147)