(self)
| 109 | |
| 110 | @support.requires_resource('walltime') |
| 111 | def test_bad_address(self): |
| 112 | # Make sure proper exception is raised when connecting to a bogus |
| 113 | # address. |
| 114 | |
| 115 | # Given that both VeriSign and various ISPs have in |
| 116 | # the past or are presently hijacking various invalid |
| 117 | # domain name requests in an attempt to boost traffic |
| 118 | # to their own sites, finding a domain name to use |
| 119 | # for this test is difficult. RFC2606 leads one to |
| 120 | # believe that '.invalid' should work, but experience |
| 121 | # seemed to indicate otherwise. Single character |
| 122 | # TLDs are likely to remain invalid, so this seems to |
| 123 | # be the best choice. The trailing '.' prevents a |
| 124 | # related problem: The normal DNS resolver appends |
| 125 | # the domain names from the search path if there is |
| 126 | # no '.' the end and, and if one of those domains |
| 127 | # implements a '*' rule a result is returned. |
| 128 | # However, none of this will prevent the test from |
| 129 | # failing if the ISP hijacks all invalid domain |
| 130 | # requests. The real solution would be to be able to |
| 131 | # parameterize the framework with a mock resolver. |
| 132 | bogus_domain = "sadflkjsasf.i.nvali.d." |
| 133 | try: |
| 134 | socket.gethostbyname(bogus_domain) |
| 135 | except OSError: |
| 136 | # socket.gaierror is too narrow, since getaddrinfo() may also |
| 137 | # fail with EAI_SYSTEM and ETIMEDOUT (seen on Ubuntu 13.04), |
| 138 | # i.e. Python's TimeoutError. |
| 139 | pass |
| 140 | else: |
| 141 | # This happens with some overzealous DNS providers such as OpenDNS |
| 142 | self.skipTest("%r should not resolve for test to work" % bogus_domain) |
| 143 | failure_explanation = ('opening an invalid URL did not raise OSError; ' |
| 144 | 'can be caused by a broken DNS server ' |
| 145 | '(e.g. returns 404 or hijacks page)') |
| 146 | with self.assertRaises(OSError, msg=failure_explanation): |
| 147 | urllib.request.urlopen("http://{}/".format(bogus_domain)) |
| 148 | |
| 149 | |
| 150 | class urlretrieveNetworkTests(unittest.TestCase): |
nothing calls this directly
no test coverage detected