From c7923684e87183045a70be3619925030c5082113 Mon Sep 17 00:00:00 2001 From: su-fang Date: Mon, 6 Feb 2023 15:39:01 +0800 Subject: [PATCH] =?UTF-8?q?Apply=20patchs:=20remove-broken-test.patch=20?= =?UTF-8?q?=20Description:=20Remove=20broken=20test=20=20This=20test=20loo?= =?UTF-8?q?ks=20like=20broken,=20and=20if=20it=20doesn't=20really=20raise?= =?UTF-8?q?=20something,=20it=20=20still=20LGTM...=20:)=20=20Author:=20Tho?= =?UTF-8?q?mas=20Goirand=20=20remove-network-access-test.?= =?UTF-8?q?patch=20=20Remove=20network=20access=20test=20=20This=20test=20?= =?UTF-8?q?is=20doing=20network=20access,=20which=20isn't=20acceptable=20d?= =?UTF-8?q?uring=20build.=20=20Author:=20Thomas=20Goirand=20=20match-uri-without-hostname-case.patch=20=20Match=20URI=20?= =?UTF-8?q?without=20letter=20case=20in=20hostname.=20=20The=20URI=20match?= =?UTF-8?q?ing=20should=20ignore=20the=20hostname=20letter=20case,=20so=20?= =?UTF-8?q?that=20=20intermediate=20=E2=80=9Cnormalising=E2=80=9D=20of=20t?= =?UTF-8?q?he=20hostname=20does=20not=20affect=20whether=20=20the=20URI=20?= =?UTF-8?q?matches.=20=20Author:=20Ben=20Finney=20=20?= =?UTF-8?q?=20Co-Author:=20Thomas=20Goirand=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 6 ++++++ httpretty/core.py | 14 +++++++------ tests/unit/test_core.py | 27 ------------------------- tests/unit/test_httpretty.py | 38 +++++++++++++++++++----------------- 4 files changed, 34 insertions(+), 51 deletions(-) diff --git a/debian/changelog b/debian/changelog index c98b23c..30daca1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-httpretty (1.1.4-ok2) yangtze; urgency=medium + + * Apply patchs. + + -- sufang Mon, 06 Feb 2023 15:38:14 +0800 + python-httpretty (1.1.4-ok1) yangtze; urgency=medium * Build for openkylin. diff --git a/httpretty/core.py b/httpretty/core.py index 19715e0..63b2e76 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -1425,6 +1425,7 @@ class httpretty(HttpBaseClass): :param hostname: a string :returns: an :py:class:`~httpretty.core.URLMatcher` or ``None`` """ + hostname_lower = hostname.lower() items = sorted( cls._entries.items(), key=lambda matcher_entries: matcher_entries[0].priority, @@ -1432,8 +1433,8 @@ class httpretty(HttpBaseClass): ) for matcher, value in items: if matcher.info is None: - pattern_with_port = "https://{0}:".format(hostname) - pattern_without_port = "https://{0}/".format(hostname) + pattern_with_port = "https://{0}:".format(hostname_lower) + pattern_without_port = "https://{0}/".format(hostname_lower) hostname_pattern = ( hostname_re .match(matcher.regex.pattern) @@ -1443,7 +1444,7 @@ class httpretty(HttpBaseClass): if re.match(hostname_pattern, pattern): return matcher - elif matcher.info.hostname == hostname: + elif (matcher.info.hostname.lower() == hostname_lower): return matcher return None @@ -1454,6 +1455,7 @@ class httpretty(HttpBaseClass): :param port: an integer :returns: an :py:class:`~httpretty.core.URLMatcher` or ``None`` """ + hostname_lower = hostname.lower() items = sorted( cls._entries.items(), key=lambda matcher_entries: matcher_entries[0].priority, @@ -1466,8 +1468,8 @@ class httpretty(HttpBaseClass): else: scheme = 'http://' - pattern_without_port = "{0}{1}/".format(scheme, hostname) - pattern_with_port = "{0}{1}:{2}/".format(scheme, hostname, port) + pattern_without_port = "{0}{1}/".format(scheme, hostname_lower) + pattern_with_port = "{0}{1}:{2}/".format(scheme, hostname_lower, port) hostname_pattern = ( hostname_re .match(matcher.regex.pattern) @@ -1477,7 +1479,7 @@ class httpretty(HttpBaseClass): if re.match(hostname_pattern, pattern): return matcher - elif matcher.info.hostname == hostname \ + elif matcher.info.hostname.lower() == hostname_lower \ and matcher.info.port == port: return matcher diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index 80c4a86..8cc7a4b 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -188,33 +188,6 @@ def test_fake_ssl_socket_proxies_its_ow_socket(): socket.send.assert_called_once_with("FOO") -@freeze_time("2013-10-04 04:20:00") -def test_fakesock_socket_getpeercert(): - ("fakesock.socket#getpeercert should return a hardcoded fake certificate") - # Given a fake socket instance - socket = fakesock.socket() - - # And that it's bound to some host - socket._host = 'somewhere.com' - - # When I retrieve the peer certificate - certificate = socket.getpeercert() - - # Then it should return a hardcoded value - certificate.should.equal({ - u'notAfter': 'Sep 29 04:20:00 GMT', - u'subject': ( - ((u'organizationName', u'*.somewhere.com'),), - ((u'organizationalUnitName', u'Domain Control Validated'),), - ((u'commonName', u'*.somewhere.com'),)), - u'subjectAltName': ( - (u'DNS', u'*.somewhere.com'), - (u'DNS', u'somewhere.com'), - (u'DNS', u'*') - ) - }) - - def test_fakesock_socket_ssl(): ("fakesock.socket#ssl should take a socket instance and return itself") # Given a fake socket instance diff --git a/tests/unit/test_httpretty.py b/tests/unit/test_httpretty.py index 017b290..48d368b 100644 --- a/tests/unit/test_httpretty.py +++ b/tests/unit/test_httpretty.py @@ -45,24 +45,6 @@ Content-Type: %(content_type)s """ -def test_httpretty_should_raise_proper_exception_on_inconsistent_length(): - ("HTTPretty should raise proper exception on inconsistent Content-Length / " - "registered response body") - - HTTPretty.register_uri.when.called_with( - HTTPretty.GET, - "http://github.com/gabrielfalcao", - body="that's me!", - adding_headers={ - 'Content-Length': '999' - } - ).should.have.raised( - HTTPrettyError, - 'HTTPretty got inconsistent parameters. The header Content-Length you registered expects size "999" ' - 'but the body you registered for that has actually length "10".' - ) - - def test_does_not_have_last_request_by_default(): 'HTTPretty.last_request is a dummy object by default' HTTPretty.reset() @@ -405,6 +387,26 @@ def test_socktype_good_python_version(): HTTPretty.disable() +def test_match_http_address_should_ignore_hostname_case(): + "HTTPretty.match_http_address should ignore case of hostname." + + for (register_hostname, match_hostname) in [ + ('foo.example.com', 'foo.example.com'), + ('FOO.example.COM', 'foo.example.com'), + ('foo.EXAMPLE.com', 'foo.example.com'), + ('fOo.eXaMpLe.com', 'foo.example.com'), + ('foo.example.com', 'FOO.example.COM'), + ('foo.example.com', 'foo.EXAMPLE.com'), + ('foo.example.com', 'fOo.eXaMpLe.com'), + ]: + HTTPretty.register_uri( + HTTPretty.GET, + "http://{hostname}/".format(hostname=register_hostname), + body="yay", + ) + assert HTTPretty.match_http_address(match_hostname, 80) + + def test_httpretty_should_allow_registering_regex_hostnames(): "HTTPretty should allow registering regexes with requests"