[merge] fix bug 59835
John Arbash Meinel
john at arbash-meinel.com
Tue Sep 12 16:16:40 BST 2006
Vincent Ladeuil wrote:
>>>>>> "Robert" == Robert Collins <robertc at robertcollins.net> writes:
>
> <snip/>
>
> >> I would be fine just bringing this in as is, because it at least lets us
> >> start getting real errors, rather than bogus AttributeError.
>
> Robert> +0.9 as is, +1 with a test to break the old code.
>
> With test, please review. It does the job, but any comment will
> be appreciated, I'm not sure I used the test framework as it was
> intended to be used.
>
> Vincent
>
>
>
...
> === modified file bzrlib/tests/test_http.py
> --- bzrlib/tests/test_http.py
> +++ bzrlib/tests/test_http.py
> @@ -135,6 +135,12 @@
> TestCaseWithWebserver.setUp(self)
> self._prep_tree()
>
> + def test_bogus_host(self):
> + from urllib2 import URLError
> + t = self._transport('http://1.2.3.4.5.6.7.8/')
> + self.assertRaises(URLError,
> + t.has,
> + 'foo/bar')
>
>
> class TestHttpConnections_pycurl(TestCaseWithWebserver, TestHttpMixins):
Unfortunately, because of wildcard dns resolvers, you cannot guarantee
that 1.2.3.4.5.6.7.8 is an invalid address. In general, our tests have
started creating a new socket on the local machine, and then not
responding to it, to guarantee that there is no actual host there. But
that has the problem that I believe this test is looking for a bad host,
not a failed connect.
I actually disabled my wildcard dns search, because I kept getting typos
resolving back to my website, which was more annoying than a 404.
Anyway, I just checked, and
t = bzrlib.transport.get_transport('http+urllib://localhost:9999/')
t.has('id')
Does indeed fail because of no 'code' attribute.
So the correct way to do it is:
import socket
...
s = socket.socket()
s.bind(('localhost', 0))
bogus_url = 'http://%s:%s/' % s.getsockname()
By 'bind()' you reserve a real port number, but by not doing
listen/accept, you prevent anyone from actually connecting to that address.
So I think the correct fix would be:
import urllib2
s = socket.socket()
s.bind(('localhost', 0))
t = self._transport('http://%s:%s/' % s.getsockname())
self.assertRaises(urlib2.URLError, t.has, 'foo/bar')
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060912/e99c7e0e/attachment.pgp
More information about the bazaar
mailing list