def test__get_ssl_context(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 # if ssl verification is enabled (default), context=None expected context = stream._get_ssl_context() self.assertIsNone(context) # if ssl verification is disabled, SSLContext expected stream._ssl_verification_enabled = False context = stream._get_ssl_context() self.assertIsInstance(context, ssl.SSLContext)
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)