def test_parse_error(self): ops = {} ops['http_proxy'] = {} ops['https_proxy'] = {} ops['http_proxy']['url'] = "domain.com:3128" ops['https_proxy']['url'] = "domain.com:3128" with self.assertRaises(ActionError) as context: create_proxies(ops) self.assertEqual("Parse proxy url error", str(context.exception))
def test_empty_http(self): ops = {} ops['https_proxy'] = {} ops['https_proxy']['url'] = "http://domain.com:3128" dump = create_proxies(ops) expected = { 'http': 'http://domain.com:3128', 'https': 'http://domain.com:3128' } self.assertEquals(expected, dump)
def test_empty_username(self): ops = {} ops['http_proxy'] = {} ops['https_proxy'] = {} ops['http_proxy']['url'] = "http://domain.com:3128" ops['http_proxy']['username'] = "" ops['http_proxy']['password'] = "" ops['https_proxy']['url'] = "http://domain.com:3128" ops['https_proxy']['username'] = "" ops['https_proxy']['password'] = "" ops['bypass_list'] = "*.cisco.com" dump = create_proxies(ops) expected = { 'http': 'http://domain.com:3128', 'https': 'http://domain.com:3128', 'no_proxy': "*.cisco.com" } self.assertEquals(expected, dump)
def handle(self, data, context): # pylint: disable=broad-except try: # if isinstance(data, six.string_types): input_object = json.loads(data) # else: # input_object = data input_type = input_object['type'] self.logger.info("Got event type %s", input_type) lh_options = {} proxy_options = {} ignore_proxy = False if 'lh_options' in input_object: lh_options = input_object['lh_options'] self.logger.info("Got lh_options %s", lh_options) if lh_options and 'proxy_options' in lh_options: proxy_options = lh_options['proxy_options'] event = input_object['config'] self.logger.info("Got event config %s", dump_excluding_secrets(event, lh_options)) handler = resolve_event(input_type, self.options) if not handler: raise ValueError("Unresolved event type: " + input_type) handler.add_lh_options(lh_options) if 'ignore_proxy' in event: ignore_proxy = event['ignore_proxy'] if proxy_options and not ignore_proxy: proxies = create_proxies(proxy_options) if proxies: handler.add_proxies(proxies) result = handler.invoke(event, context) return action_success(result) except ActionError as e: self.logger.error("Raised action error code=%s, message=%s", e.code, e) return action_error(str(e), e.code) except Exception: formatted_lines = traceback.format_exc().splitlines() e = "Error processing request: " + str(formatted_lines[-1]) self.logger.exception("Exception during processing request") return action_error(str(e), None)
def handle(self, data, context): """Handle the incoming request to this controller. """ # pylint: disable=broad-except try: if isinstance(data, six.string_types): input_object = json.loads(data) else: input_object = data input_type = input_object['type'] self.logger.info("Got event type %s", input_type) lh_options = {} proxy_options = {} no_proxy = False if 'lh_options' in input_object: lh_options = input_object['lh_options'] if lh_options and 'proxy_options' in lh_options: proxy_options = lh_options['proxy_options'] event = input_object['config'] self.logger.info("Got event config %s", dump_excluding_secrets(event, lh_options)) handler = resolve_event(input_type, self.options) if not handler: raise ValueError("Unresolved event type: " + input_type) handler.add_lh_options(lh_options) if 'no_proxy' in event: no_proxy = event['no_proxy'] if proxy_options and not no_proxy: proxies = create_proxies(proxy_options) if proxies: handler.add_proxies(proxies) result = handler.invoke(event, context) return self.__action_success(result) except ActionError as e: self.logger.error("Raised action error code=%s, message=%s", e.code, e) return self.__action_error(str(e), e.code) except Exception as e: self.logger.exception("Exception during processing request") return self.__action_error(str(e), None)
def test_empty_proxies(self): proxy_options = {} dump = create_proxies(proxy_options) expected = {} self.assertEquals(expected, dump)