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.
636
Be aware that we do not setup a real proxy here. Instead, we
637
check that the *connection* goes through the proxy by serving
638
different content (the faked proxy server append '-proxied'
642
# FIXME: We don't have an https server available, so we don't
643
# test https connections.
646
TestCaseWithTwoWebservers.setUp(self)
647
self.build_tree_contents([('foo', 'contents of foo\n'),
648
('foo-proxied', 'proxied contents of foo\n')])
649
# Let's setup some attributes for tests
650
self.server = self.get_readonly_server()
651
self.no_proxy_host = 'localhost:%d' % self.server.port
652
# The secondary server is the proxy
653
self.proxy = self.get_secondary_server()
654
self.proxy_url = self.proxy.get_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 _set_and_capture_env_var(self, name, new_value):
664
"""Set an environment variable, and reset it when finished."""
665
self._old_env[name] = osutils.set_or_unset_env(name, new_value)
667
def _install_env(self, env):
668
for name, value in env.iteritems():
669
self._set_and_capture_env_var(name, value)
671
def _restore_env(self):
672
for name, value in self._old_env.iteritems():
673
osutils.set_or_unset_env(name, value)
675
def proxied_in_env(self, env):
676
self._install_env(env)
677
url = self.server.get_url()
678
t = self._transport(url)
680
self.assertEqual(t.get('foo').read(), 'proxied contents of foo\n')
684
def not_proxied_in_env(self, env):
685
self._install_env(env)
686
url = self.server.get_url()
687
t = self._transport(url)
689
self.assertEqual(t.get('foo').read(), 'contents of foo\n')
693
def test_http_proxy(self):
694
self.proxied_in_env({'http_proxy': self.proxy_url})
696
def test_HTTP_PROXY(self):
697
self.proxied_in_env({'HTTP_PROXY': self.proxy_url})
699
def test_all_proxy(self):
700
self.proxied_in_env({'all_proxy': self.proxy_url})
702
def test_ALL_PROXY(self):
703
self.proxied_in_env({'ALL_PROXY': self.proxy_url})
705
def test_http_proxy_with_no_proxy(self):
706
self.not_proxied_in_env({'http_proxy': self.proxy_url,
707
'no_proxy': self.no_proxy_host})
709
def test_HTTP_PROXY_with_NO_PROXY(self):
710
self.not_proxied_in_env({'HTTP_PROXY': self.proxy_url,
711
'NO_PROXY': self.no_proxy_host})
713
def test_all_proxy_with_no_proxy(self):
714
self.not_proxied_in_env({'all_proxy': self.proxy_url,
715
'no_proxy': self.no_proxy_host})
717
def test_ALL_PROXY_with_NO_PROXY(self):
718
self.not_proxied_in_env({'ALL_PROXY': self.proxy_url,
719
'NO_PROXY': self.no_proxy_host})
722
class TestProxyHttpServer_urllib(TestProxyHttpServer,
723
TestCaseWithTwoWebservers):
724
"""Tests proxy server for urllib implementation"""
726
_transport = HttpTransport_urllib
729
class TestProxyHttpServer_pycurl(TestWithTransport_pycurl,
731
TestCaseWithTwoWebservers):
732
"""Tests proxy server for pycurl implementation"""
735
TestProxyHttpServer.setUp(self)
736
# Oh my ! pycurl does not check for the port as part of
737
# no_proxy :-( So we just test the host part
738
self.no_proxy_host = 'localhost'
740
def test_HTTP_PROXY(self):
741
# pycurl do not check HTTP_PROXY for security reasons
742
# (for use in a CGI context that we do not care
743
# about. Should we ?)
746
def test_HTTP_PROXY_with_NO_PROXY(self):