621
623
"""Tests range requests refusing server for pycurl implementation"""
626
class TestProxyHttpServer(object):
627
"""Tests proxy server.
629
This MUST be used by daughter classes that also inherit from
630
TestCaseWithTwoWebservers.
632
We can't inherit directly from TestCaseWithTwoWebservers or
633
the test framework will try to create an instance which
634
cannot run, its implementation being incomplete.
638
TestCaseWithTwoWebservers.setUp(self)
639
self.build_tree_contents([('foo', 'contents of foo\n'),
640
('foo-proxied', 'proxied contents of foo\n')])
641
# Create the server now. Otherwise, it will created when
642
# test methods are invoked. At that point the test
643
# methods may have set env vars and the HttpServer
644
# creation will erase them.
645
server = self.get_readonly_server()
646
# The secondary server is the proxy
648
# NOTE: We do not setup a real proxy, instead we check
649
# that the connection goes thru the proxy by serving
651
proxy = self.get_secondary_server()
652
proxy_url = proxy.get_url()
653
# All tests will rely on the secondary server being set
655
os.environ['http_proxy'] = proxy_url
657
def create_transport_secondary_server(self):
658
"""Creates an http server that will serve files with
659
'-proxied' appended to their names.
661
return HttpServer(FakeProxyRequestHandler)
663
def test_http_proxy(self):
664
server = self.get_readonly_server()
665
url = server.get_url()
666
t = self._transport(url)
667
self.assertEqual(t.get('foo').read(),
668
'proxied contents of foo\n')
670
def test_http_no_proxy(self):
671
server = self.get_readonly_server()
672
url = server.get_url()
673
os.environ['no_proxy'] = 'localhost:%d' % server.port
674
t = self._transport(url)
676
self.assertEqual(t.get('foo').read(),
679
del os.environ['no_proxy']
682
class TestProxyHttpServer_urllib(TestProxyHttpServer,
683
TestCaseWithTwoWebservers):
684
"""Tests proxy server for urllib implementation"""
686
_transport = HttpTransport_urllib
689
class TestProxyHttpServer_pycurl(TestWithTransport_pycurl,
691
TestCaseWithTwoWebservers):
692
"""Tests proxy server for pycurl implementation"""
694
def test_http_no_proxy(self):
695
server = self.get_readonly_server()
696
url = server.get_url()
697
# Oh my ! pycurl do not check the port part :-( So we
698
# just test the host part
699
os.environ['no_proxy'] = 'localhost'
700
t = self._transport(url)
702
self.assertEqual(t.get('foo').read(),
705
del os.environ['no_proxy']