def setUp(self, extra_disc_server_config_knobs = None, extra_disc_server_mocks = None): extra_api_server_config_knobs = [ ('DEFAULTS', 'disc_server_dsa_api', '/api/dsa'), ('DEFAULTS', 'log_level', 'SYS_DEBUG'), ] super(DsTestCase, self).setUp(extra_config_knobs = extra_api_server_config_knobs) self._disc_server_ip = socket.gethostbyname(socket.gethostname()) self._disc_server_port = test_utils.get_free_port() http_server_port = test_utils.get_free_port() if extra_disc_server_config_knobs: self._disc_server_config_knobs.extend(extra_disc_server_config_knobs) if extra_disc_server_mocks: self.mocks.extend(extra_disc_server_mocks) test_common.setup_mocks(self.mocks) self._disc_server_greenlet = gevent.spawn(test_common.launch_disc_server, self.id(), self._disc_server_ip, self._disc_server_port, http_server_port, self._disc_server_config_knobs) test_utils.block_till_port_listened(self._disc_server_ip, self._disc_server_port) self._disc_server_session = requests.Session() adapter = requests.adapters.HTTPAdapter() self._disc_server_session.mount("http://", adapter) self._disc_server_session.mount("https://", adapter)
def setUp(self): self.maxDiff = None self._sandesh = Sandesh() http_port = test_utils.get_free_port() self._sandesh.init_generator( "conn_info_test", socket.gethostname(), "Test", "Test", None, "conn_info_test_ctxt", http_port )
def setUpClass(cls): global sandesh_test_started if (not sandesh_test_started): http_port = test_utils.get_free_port() sandesh_global.init_generator('sandesh_session_test', socket.gethostname(), 'Test', 'Test', None, 'sandesh_msg_test_ctxt', http_port) sandesh_test_started = True
def setUpClass(cls): global sandesh_test_started if not sandesh_test_started: http_port = test_utils.get_free_port() sandesh_global.init_generator( "sandesh_session_test", socket.gethostname(), "Test", "Test", None, "sandesh_msg_test_ctxt", http_port ) sandesh_test_started = True
def setUp(self): self._sandesh = Sandesh() http_port = test_utils.get_free_port() self._sandesh.init_generator('sandesh_trace_test', socket.gethostname(), 'Test', 'Test', None, 'trace_test_ctxt', http_port) self._sandesh.set_logging_params(level=SandeshLevel.SYS_DEBUG, enable_local_log=True, enable_trace_print=True) self._trace_read_list = []
def setUp(self): self.maxDiff = None self.sandesh = Sandesh() self.sandesh.init_generator('sandesh_uve_alarm_test', socket.gethostname(), 'Test', '0', None, '', test_utils.get_free_port(), connect_to_collector=False) # mock the sandesh client object self.sandesh._client = mock.MagicMock(spec=SandeshClient)
def setUp(self): self.http_port = test_utils.get_free_port() sandesh_global.init_generator('sandesh_http_test', socket.gethostname(), 'Test', 'Test', None, 'sandesh_http_test_ctxt', self.http_port, sandesh_req_uve_pkg_list = [], connect_to_collector=False) time.sleep(1) # Let http server up from sandesh_req_impl import SandeshHttpRequestImp self.sandesh_req_impl = SandeshHttpRequestImp(sandesh_global) self.assertTrue(sandesh_global.client() is None)
def setUpClass(cls): http_port = test_utils.get_free_port() sandesh_global.init_generator('sandesh_msg_test', socket.gethostname(), 'Test', 'Test', None, 'sandesh_msg_test_ctxt', http_port, connect_to_collector=False)
def setUp(self): self.http_port = test_utils.get_free_port() sandesh_global.init_generator('sandesh_http_test', socket.gethostname(), 'Test', 'Test', None, 'sandesh_http_test_ctxt', self.http_port, sandesh_req_uve_pkg_list=[], connect_to_collector=False) time.sleep(1) # Let http server up from sandesh_req_impl import SandeshHttpRequestImp self.sandesh_req_impl = SandeshHttpRequestImp(sandesh_global) self.assertTrue(sandesh_global.client() is None)
def setUp(self): self._sandesh = Sandesh() http_port = test_utils.get_free_port() self._sandesh.init_generator('sandesh_trace_test', socket.gethostname(), 'Test', 'Test', None, 'trace_test_ctxt', http_port) self._trace_read_list = []
def setup_package(): """Setup the environment for the tests. Check the test project twice, then start the server.""" pkg_root = os.path.abspath(os.environ['TEST_CODECHECKER_DIR']) env = os.environ.copy() env['PATH'] = os.path.join(pkg_root, 'bin') + ':' + env['PATH'] tmp_dir = os.path.abspath(os.environ['TEST_CODECHECKER_PACKAGE_DIR']) workspace = os.path.join(tmp_dir, 'workspace') if os.path.exists(workspace): print("Removing previous workspace") shutil.rmtree(workspace) os.makedirs(workspace) test_project_path = os.path.join( os.path.abspath(os.environ['TEST_TESTS_DIR']), 'test_projects', 'test_files') clang_version = os.environ.get('TEST_CLANG_VERSION', 'stable') use_postgresql = os.environ.get('TEST_USE_POSTGRESQL', '') == 'true' pg_db_config = {} if use_postgresql: pg_db_config['dbaddress'] = 'localhost' pg_db_config['dbname'] = 'testDb' pg_db_config['dbport'] = os.environ.get('TEST_DBPORT', get_free_port()) if os.environ.get('TEST_DBUSERNAME', False): pg_db_config['dbusername'] = os.environ['TEST_DBUSERNAME'] project_info = \ json.load(open(os.path.realpath(env['TEST_TEST_PROJECT_CONFIG']))) test_config = { 'CC_TEST_SERVER_PORT': get_free_port(), 'CC_TEST_SERVER_HOST': 'localhost', 'CC_TEST_VIEWER_PORT': get_free_port(), 'CC_TEST_VIEWER_HOST': 'localhost', 'CC_AUTH_SERVER_PORT': get_free_port(), 'CC_AUTH_SERVER_HOST': 'localhost', 'CC_AUTH_VIEWER_PORT': get_free_port(), 'CC_AUTH_VIEWER_HOST': 'localhost', } test_project_clean_cmd = project_info['clean_cmd'] test_project_build_cmd = project_info['build_cmd'] # setup env vars for test cases os.environ['CC_TEST_VIEWER_PORT'] = str(test_config['CC_TEST_VIEWER_PORT']) os.environ['CC_TEST_SERVER_PORT'] = str(test_config['CC_TEST_SERVER_PORT']) os.environ['CC_AUTH_SERVER_PORT'] = str(test_config['CC_AUTH_SERVER_PORT']) os.environ['CC_AUTH_VIEWER_PORT'] = str(test_config['CC_AUTH_VIEWER_PORT']) os.environ['CC_TEST_PROJECT_INFO'] = \ json.dumps(project_info['clang_' + clang_version]) # ------------------------------------------------------------------------- # generate suppress file suppress_file = os.path.join(tmp_dir, 'suppress_file') if os.path.isfile(suppress_file): os.remove(suppress_file) _generate_suppress_file(suppress_file) skip_list_file = os.path.join(test_project_path, 'skip_list') shared_test_params = { 'suppress_file': suppress_file, 'env': env, 'use_postgresql': use_postgresql, 'workspace': workspace, 'pg_db_config': pg_db_config } # First check. print("Running first analysis") ret = _clean_project(test_project_path, test_project_clean_cmd, env) if ret: sys.exit(ret) test_project_1_name = project_info['name'] + '_' + uuid.uuid4().hex ret = _run_check(shared_test_params, skip_list_file, test_project_build_cmd, test_project_1_name, test_project_path) _wait_for_postgres_shutdown(shared_test_params['workspace']) if ret: sys.exit(1) # Second check. print("Running second analysis") ret = _clean_project(test_project_path, test_project_clean_cmd, env) if ret: sys.exit(ret) test_project_2_name = project_info['name'] + '_' + uuid.uuid4().hex ret = _run_check(shared_test_params, skip_list_file, test_project_build_cmd, test_project_2_name, test_project_path) _wait_for_postgres_shutdown(shared_test_params['workspace']) if ret: sys.exit(1) # Start the CodeChecker server. print("Starting server to get results") _start_server(shared_test_params, test_config, False) # # Create a dummy authentication-enabled configuration and an auth-enabled server. # # Running the tests only work if the initial value (in package # session_config.json) is FALSE for authentication.enabled. os.remove( os.path.join(shared_test_params['workspace'], "session_config.json")) session_cfg_file = os.path.join(pkg_root, "config", "session_config.json") with open(session_cfg_file, 'r+') as scfg: __scfg_original = scfg.read() scfg.seek(0) scfg_dict = json.loads(__scfg_original) scfg_dict["authentication"]["enabled"] = True scfg_dict["authentication"]["method_dictionary"]["enabled"] = True scfg_dict["authentication"]["method_dictionary"]["auths"] = ["cc:test"] json.dump(scfg_dict, scfg, indent=2, sort_keys=True) scfg.truncate() print("Starting server to test authentication") _start_server(shared_test_params, test_config, True) # Need to save the original configuration back so multiple tests can work after each other os.remove( os.path.join(shared_test_params['workspace'], "session_config.json")) with open(session_cfg_file, 'w') as scfg: scfg.writelines(__scfg_original)
def setup_package(): """Setup the environment for the tests. Check the test project twice, then start the server.""" pkg_root = os.path.abspath(os.environ['TEST_CODECHECKER_DIR']) env = os.environ.copy() env['PATH'] = os.path.join(pkg_root, 'bin') + ':' + env['PATH'] tmp_dir = os.path.abspath(os.environ['TEST_CODECHECKER_PACKAGE_DIR']) workspace = os.path.join(tmp_dir, 'workspace') if os.path.exists(workspace): print("Removing previous workspace") shutil.rmtree(workspace) os.makedirs(workspace) test_project_path = os.path.join( os.path.abspath(os.environ['TEST_TESTS_DIR']), 'test_projects', 'test_files') clang_version = os.environ.get('TEST_CLANG_VERSION', 'stable') use_postgresql = os.environ.get('TEST_USE_POSTGRESQL', '') == 'true' pg_db_config = {} if use_postgresql: pg_db_config['dbaddress'] = 'localhost' pg_db_config['dbname'] = 'testDb' pg_db_config['dbport'] = os.environ.get('TEST_DBPORT', get_free_port()) if os.environ.get('TEST_DBUSERNAME', False): pg_db_config['dbusername'] = os.environ['TEST_DBUSERNAME'] project_info = \ json.load(open(os.path.realpath(env['TEST_TEST_PROJECT_CONFIG']))) test_config = { 'CC_TEST_SERVER_PORT': get_free_port(), 'CC_TEST_SERVER_HOST': 'localhost', 'CC_TEST_VIEWER_PORT': get_free_port(), 'CC_TEST_VIEWER_HOST': 'localhost' } test_project_clean_cmd = project_info['clean_cmd'] test_project_build_cmd = project_info['build_cmd'] # setup env vars for test cases os.environ['CC_TEST_VIEWER_PORT'] = str(test_config['CC_TEST_VIEWER_PORT']) os.environ['CC_TEST_SERVER_PORT'] = str(test_config['CC_TEST_SERVER_PORT']) os.environ['CC_TEST_PROJECT_INFO'] = \ json.dumps(project_info['clang_' + clang_version]) # ------------------------------------------------------------------------- # generate suppress file suppress_file = os.path.join(tmp_dir, 'suppress_file') if os.path.isfile(suppress_file): os.remove(suppress_file) _generate_suppress_file(suppress_file) skip_list_file = os.path.join(test_project_path, 'skip_list') shared_test_params = { 'suppress_file': suppress_file, 'env': env, 'use_postgresql': use_postgresql, 'workspace': workspace, 'pg_db_config': pg_db_config } # first check print("Running first analysis") _clean_project(test_project_path, test_project_clean_cmd, env) test_project_1_name = project_info['name'] + '_' + uuid.uuid4().hex _run_check(shared_test_params, skip_list_file, test_project_build_cmd, test_project_1_name, test_project_path) _wait_for_postgres_shutdown(shared_test_params['workspace']) # second check print("Running second analysis") _clean_project(test_project_path, test_project_clean_cmd, env) test_project_2_name = project_info['name'] + '_' + uuid.uuid4().hex _run_check(shared_test_params, skip_list_file, test_project_build_cmd, test_project_2_name, test_project_path) _wait_for_postgres_shutdown(shared_test_params['workspace']) # start the CodeChecker server print("Starting server to get results") _start_server(shared_test_params, test_config)
import requests from mock import patch, MagicMock, call, Mock from oauthlib.oauth2 import TokenExpiredError from dispatcher import Dispatcher, OAuth2Session, CONSENT_MANAGER_OAUTH_CLIENT_ID, CONSENT_MANAGER_OAUTH_CLIENT_SECRET, \ HGW_FRONTEND_OAUTH_CLIENT_SECRET, HGW_FRONTEND_OAUTH_CLIENT_ID from test_data import SOURCES, UNKNOWN_OAUTH_CLIENT, ACTIVE_CHANNEL_ID, DESTINATION, PROCESS_ID, PENDING_CHANNEL_ID, \ CHANNEL_WITH_NO_PROCESS_ID, PERSON_ID from test_utils import get_free_port, start_mock_server, MockBackendRequestHandler, MockConsentManagerRequestHandler, \ MockFrontendRequestHandler logger = logging.getLogger('dispatcher') for h in logger.handlers: h.setLevel(logging.CRITICAL) os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' HGW_BACKEND_PORT = get_free_port() HGW_BACKEND_URI = 'http://localhost:{}'.format(HGW_BACKEND_PORT) HGW_FRONTEND_PORT = get_free_port() HGW_FRONTEND_URI = 'http://localhost:{}'.format(HGW_FRONTEND_PORT) CONSENT_MANAGER_PORT = get_free_port() CONSENT_MANAGER_URI = 'http://localhost:{}'.format(CONSENT_MANAGER_PORT) class MockMessage(object): def __init__(self, key, topic, value, offset): self.key = key self.topic = topic self.value = value self.offset = offset
def setUp(self): self.maxDiff = None self._sandesh = Sandesh() http_port = test_utils.get_free_port() self._sandesh.init_generator('conn_info_test', socket.gethostname(), 'Test', 'Test', None, 'conn_info_test_ctxt', http_port)