Ejemplo n.º 1
0
    def test__get_proxy_config_with_ssl(self):

        stream = Stream('127.0.0.1', port=8080)

        # we actually still have an http connection here, but we're faking https
        # to test the expected proxy behaviour
        stream._ssl_enabled = True

        # https_proxy is not set
        # --> proxy_server and proxy_port should not be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # set proxy env. variable
        os.environ['https_proxy'] = 'https://test:123'

        # https_proxy is set
        # --> proxy_server and proxy_port should be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)
Ejemplo n.º 2
0
    def test__get_proxy_config_with_ssl(self):

        stream = Stream('127.0.0.1', port=8080)

        # we actually still have an http connection here, but we're faking https
        # to test the expected proxy behaviour
        stream._ssl_enabled = True

        # https_proxy is not set
        # --> proxy_server and proxy_port should not be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # set proxy env. variable
        os.environ['https_proxy'] = 'https://test:123'

        # https_proxy is set
        # --> proxy_server and proxy_port should be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)
Ejemplo n.º 3
0
    def test__get_proxy_config(self):

        stream = Stream('127.0.0.1', port=8080)

        # http_proxy is not set
        # --> proxy_server and proxy_port should not be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # set proxy env. variable
        os.environ['http_proxy'] = 'http://test:123'

        # http_proxy is set
        # --> proxy_server and proxy_port should be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)

        # no_proxy is set but url is not in no_proxy
        # --> proxy_server and proxy_port should be set
        os.environ['no_proxy'] = 'some_url, other_url'
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)

        # http_proxy and no_proxy are set and url is in no_proxy
        # --> proxy_server and proxy_port should not be set
        os.environ['no_proxy'] = 'some_url, {}, other_url'.format(
            stream._server
        )
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # unset env variables
        os.environ.pop('http_proxy')
        os.environ.pop('no_proxy')
Ejemplo n.º 4
0
    def test__get_proxy_config(self):

        stream = Stream('127.0.0.1', port=8080)

        # http_proxy is not set
        # --> proxy_server and proxy_port should not be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # set proxy env. variable
        os.environ['http_proxy'] = 'http://test:123'

        # http_proxy is set
        # --> proxy_server and proxy_port should be set
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)

        # no_proxy is set but url is not in no_proxy
        # --> proxy_server and proxy_port should be set
        os.environ['no_proxy'] = 'some_url, other_url'
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertEqual(proxy_server, 'test')
        self.assertEqual(proxy_port, 123)

        # http_proxy and no_proxy are set and url is in no_proxy
        # --> proxy_server and proxy_port should not be set
        os.environ['no_proxy'] = 'some_url, {}, other_url'.format(
            stream._server)
        proxy_server, proxy_port = stream._get_proxy_config()
        self.assertIsNone(proxy_server)
        self.assertIsNone(proxy_port)

        # unset env variables
        os.environ.pop('http_proxy')
        os.environ.pop('no_proxy')