diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-12-16 04:36:20 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-12-16 04:36:20 (GMT) |
commit | a7f9933efacc017f9772ae12830e75ce88c3b7ec (patch) | |
tree | a77891b72afd37d205de512bee500167e56ba38d /Lib/test/test_urllibnet.py | |
parent | e319ab01cee6aa4675cac418d5f5900e5537f66e (diff) | |
download | cpython-a7f9933efacc017f9772ae12830e75ce88c3b7ec.zip cpython-a7f9933efacc017f9772ae12830e75ce88c3b7ec.tar.gz cpython-a7f9933efacc017f9772ae12830e75ce88c3b7ec.tar.bz2 |
Issue #23788: Merge redundant test_bad_address() into test_urllibnet
In Python 2, these were duplicated; one for urllib.urlopen() and one for
urllib2.urlopen(). The test_urllibnet version has a better precondition to
avoid false failures with bad DNS, and the test_urllib2_localnet version had
a more up-to-date comment and domain name.
Diffstat (limited to 'Lib/test/test_urllibnet.py')
-rw-r--r-- | Lib/test/test_urllibnet.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 42ebb6e..b9b9262 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -113,7 +113,25 @@ class urlopenNetworkTests(unittest.TestCase): def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. - bogus_domain = "sadflkjsasf.i.nvali.d" + + # Given that both VeriSign and various ISPs have in + # the past or are presently hijacking various invalid + # domain name requests in an attempt to boost traffic + # to their own sites, finding a domain name to use + # for this test is difficult. RFC2606 leads one to + # believe that '.invalid' should work, but experience + # seemed to indicate otherwise. Single character + # TLDs are likely to remain invalid, so this seems to + # be the best choice. The trailing '.' prevents a + # related problem: The normal DNS resolver appends + # the domain names from the search path if there is + # no '.' the end and, and if one of those domains + # implements a '*' rule a result is returned. + # However, none of this will prevent the test from + # failing if the ISP hijacks all invalid domain + # requests. The real solution would be to be able to + # parameterize the framework with a mock resolver. + bogus_domain = "sadflkjsasf.i.nvali.d." try: socket.gethostbyname(bogus_domain) except OSError: @@ -128,11 +146,7 @@ class urlopenNetworkTests(unittest.TestCase): 'can be caused by a broken DNS server ' '(e.g. returns 404 or hijacks page)') with self.assertRaises(OSError, msg=failure_explanation): - # SF patch 809915: In Sep 2003, VeriSign started highjacking - # invalid .com and .net addresses to boost traffic to their own - # site. This test started failing then. One hopes the .invalid - # domain will be spared to serve its defined purpose. - urllib.request.urlopen("http://sadflkjsasf.i.nvali.d/") + urllib.request.urlopen("http://{}/".format(bogus_domain)) class urlretrieveNetworkTests(unittest.TestCase): |