def _run_failure_scenario(self, response, value_if_not_found, schema=None): if value_if_not_found is None: body = trhutil.get_json_body_from_response(response, schema=schema) self.assertIsNone(body) else: body = trhutil.get_json_body_from_response( response, value_if_not_found, schema) self.assertEqual(body, value_if_not_found)
def _test_response_ok_body(self, the_body, schema): response = mock.Mock() response.code = httplib.OK response.body = json.dumps(the_body) response.headers = { "Content-length": len(response.body), "Content-type": "application/json; charset=utf-8", } if schema is None: self.assertEqual( the_body, trhutil.get_json_body_from_response(response)) else: self.assertEqual( the_body, trhutil.get_json_body_from_response(response, schema=schema))
def _on_fetch_done(self, response): """Called when request to the key service returns.""" _logger.info( "Key Service (%s - %s) responded in %d ms", response.effective_url, response.request.method, int(response.request_time * 1000)) if response.error or response.code != httplib.OK: self._callback(False, self._mac_key_identifier) return body = trhutil.get_json_body_from_response( response, None, jsonschemas.get_creds_response) if body is None: self._callback(False, self._mac_key_identifier) return _logger.info( "For mac key identifier '%s' retrieved credentials '%s'", self._mac_key_identifier, body) self._callback( True, mac.MACKeyIdentifier(body["mac"]["mac_key_identifier"]), body["mac"]["mac_algorithm"], mac.MACKey(body["mac"]["mac_key"]), body["principal"])
def _http_client_fetch_callback(self, response): """Called when ```tornado.httpclient.AsyncHTTPClient``` completes.""" """:TRICKY: Need to be careful about changing this message format because the load testing infrastructure scrapes the logs for this message in this format.""" _logger.info( "Key Store (%s - %s) responded in %d ms", response.effective_url, response.request.method, int(response.request_time * 1000)) if response.error: _logger.error( "Key Store responded to %s on %s with error '%s'", response.request.method, response.effective_url, response.error) self._my_callback(False) return self._my_callback( True, response.code, trhutil.get_json_body_from_response(response))
def _on_fetch_done(self, response): """Called when request to the key service returns.""" _logger.info("Key Service (%s - %s) responded in %d ms", response.effective_url, response.request.method, int(response.request_time * 1000)) expected_response_codes = [ httplib.OK, httplib.NOT_FOUND, ] if response.error or response.code not in expected_response_codes: self._callback(False) return if response.code == httplib.NOT_FOUND: self._callback(True, None) return body = trhutil.get_json_body_from_response( response, None, jsonschemas.get_creds_response) if body is None: self._callback(False) return _logger.info( "Successfully retrieved basic auth credentials for api key '%s'", self._api_key) self._callback(True, body["principal"])