|
7 | 7 | import email.message |
8 | 8 | import io |
9 | 9 | import unittest |
10 | | -import unittest.mock |
11 | 10 | from test import support |
12 | 11 | from test.support import os_helper |
13 | 12 | from test.support import socket_helper |
@@ -401,17 +400,11 @@ def test_url_host_with_newline_header_injection_rejected(self): |
401 | 400 | host = "localhost\r\nX-injected: header\r\n" |
402 | 401 | schemeless_url = "//" + host + ":8080/test/?test=a" |
403 | 402 | try: |
404 | | - # Once \r\n are stripped from the URL, the ':' in |
405 | | - # "X-injected:" is mistaken for the port separator, and |
406 | | - # urlsplit()/urlparse() now reject the resulting |
407 | | - # non-numeric "port" at parse time, before a Request is |
408 | | - # even built -- rejecting the injection earlier than |
409 | | - # http.client's own InvalidURL check ever gets a chance to. |
| 403 | + InvalidURL = http.client.InvalidURL |
410 | 404 | with self.assertRaisesRegex( |
411 | | - ValueError, "Port could not be cast to integer value"): |
| 405 | + InvalidURL, r"contain control.*\\r"): |
412 | 406 | urllib.request.urlopen(f"http:{schemeless_url}") |
413 | | - with self.assertRaisesRegex( |
414 | | - ValueError, "Port could not be cast to integer value"): |
| 407 | + with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"): |
415 | 408 | urllib.request.urlopen(f"https:{schemeless_url}") |
416 | 409 | finally: |
417 | 410 | self.unfakehttp() |
@@ -1679,17 +1672,6 @@ def test_url2pathname_resolve_host(self): |
1679 | 1672 | self.assertEqual(fn(f'//{socket.gethostname()}/foo/bar'), f'{sep}foo{sep}bar') |
1680 | 1673 | self.assertEqual(fn(f'//{socket.gethostname()}/foo/bar', resolve_host=True), f'{sep}foo{sep}bar') |
1681 | 1674 |
|
1682 | | - def test_url2pathname_win_netloc_not_validated_as_port(self): |
1683 | | - # The Windows branch of url2pathname() stuffs things like drive |
1684 | | - # letters into the netloc (e.g. '//C:\\' -> authority 'C:\\'), |
1685 | | - # which is not a real host[:port] pair. url2pathname() must not |
1686 | | - # reject it as an invalid port; run the Windows branch directly |
1687 | | - # so this is exercised on every platform, not just win32. |
1688 | | - with unittest.mock.patch('os.name', 'nt'): |
1689 | | - fn = urllib.request.url2pathname |
1690 | | - self.assertEqual(fn('//C:\\'), 'C:\\') |
1691 | | - self.assertEqual(fn('//C:80/'), 'C:80\\') |
1692 | | - |
1693 | 1675 | @unittest.skipUnless(sys.platform == 'win32', |
1694 | 1676 | 'test specific to Windows pathnames.') |
1695 | 1677 | def test_url2pathname_win(self): |
|
0 commit comments