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"