def setUp(self): # Get the test workspace used to cppcheck tests. self._test_workspace = os.environ["TEST_WORKSPACE"] test_class = self.__class__.__name__ print("Running " + test_class + " tests in " + self._test_workspace) self._test_cfg = env.import_test_cfg(self._test_workspace) self._codechecker_cfg = self._test_cfg["codechecker_cfg"] self._test_directory = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) self._temp_workspace = os.path.join(self._codechecker_cfg["workspace"], "test_proj") self._divide_zero_workspace = os.path.join(self._temp_workspace, "divide_zero") self._double_suppress_workspace = os.path.join(self._temp_workspace, "double_suppress") self.product_name = self._codechecker_cfg['viewer_product'] # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self._test_workspace) self.assertIsNotNone(self._cc_client) self._pr_client = env.setup_product_client(self._test_workspace, product=self.product_name) self.assertIsNotNone(self._pr_client)
def test_get_product_data(self): """ Test getting product configuration from server. """ # First, test calling the API through a product endpoint and not the # global endpoint. Also retrieve product ID this way. pr_client = env.setup_product_client(self.test_workspace, product=self.product_name) self.assertIsNotNone(pr_client, "Couldn't set up client") # This returns a USERSPACE product data. pr_data = pr_client.getCurrentProduct() self.assertIsNotNone(pr_data, "Couldn't retrieve product data properly") self.assertEqual(pr_data.endpoint, self.product_name, "The product's endpoint is improper.") self.assertTrue(pr_data.id > 0, "Product didn't have valid ID") # The connected attribute of a product will be always True if # database status is OK. connected = pr_data.databaseStatus == DBStatus.OK self.assertEqual(pr_data.connected, connected) # Now get the SERVERSPACE (configuration) for the product. # TODO: These things usually should only work for superusers! pr_conf = self._pr_client.getProductConfiguration(pr_data.id) self.assertIsNotNone(pr_conf, "Product configuration must come.") self.assertEqual( pr_conf.endpoint, self.product_name, "Product endpoint reproted by server must be the " "used endpoint... something doesn't make sense here!") self.assertIsNotNone( pr_conf.connection, "Product configuration must " "send a database connection.") self.assertIsNone( pr_conf.connection.password_b64, "!SECURITY LEAK! Server should NEVER send the " "product's database password out!") self.assertIn( self.product_name, pr_conf.connection.database, "The product's database (name|file) should contain " "the product's endpoint -- in the test context.") name = base64.b64decode(pr_conf.displayedName_b64) \ if pr_conf.displayedName_b64 else '' self.assertEqual( name, # libtest/codechecker.py uses the workspace's name. os.path.basename(self.test_workspace), "The displayed name must == the default value, as " "we didn't specify a custom displayed name.")
def setUp(self): """ """ # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self.test_workspace) self.product_name = self.test_cfg['codechecker_cfg']['viewer_product'] # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self.test_workspace, session_token='_PROHIBIT') # Create a SUPERUSER login. root_token = self._auth_client.performLogin("Username:Password", "root:root") # Setup a product client to test product API calls. self._pr_client = env.setup_product_client(self.test_workspace) self.assertIsNotNone(self._pr_client) # Setup a product client to test product API calls which requires root. self._root_client = env.setup_product_client(self.test_workspace, session_token=root_token) self.assertIsNotNone(self._pr_client) # Get the run names which belong to this test. run_names = env.get_run_names(self.test_workspace) runs = self._cc_client.getRunData(None, None, 0, None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, "There should be only one run for this test.") self._runid = test_runs[0].runId
def setUp(self): """ """ # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self.test_workspace) self.product_name = self.test_cfg['codechecker_cfg']['viewer_product'] # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self.test_workspace, session_token='_PROHIBIT') # Create a SUPERUSER login. root_token = self._auth_client.performLogin("Username:Password", "root:root") # Setup a product client to test product API calls. self._pr_client = env.setup_product_client(self.test_workspace) self.assertIsNotNone(self._pr_client) # Setup a product client to test product API calls which requires root. self._root_client = env.setup_product_client(self.test_workspace, session_token=root_token) self.assertIsNotNone(self._pr_client) # Get the run names which belong to this test. run_names = env.get_run_names(self.test_workspace) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, "There should be only one run for this test.") self._runid = test_runs[0].runId
def test_group_auth(self): """ Test for case insensitive group comparison at authorization. """ auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # Create a SUPERUSER login. self.sessionToken = auth_client.performLogin("Username:Password", "root:root") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "root") product_name = self._test_cfg['codechecker_cfg']['viewer_product'] pr_client = env.setup_product_client(self._test_workspace, product=product_name) product_id = pr_client.getCurrentProduct().id extra_params = {'productID': product_id} ret = authd_auth_client.addPermission(Permission.PRODUCT_ADMIN, "ADMIN_group", True, json.dumps(extra_params)) self.assertTrue(ret) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Perform login with a user who is in ADMIN_GROUP and check that # he has permission to perform operations. self.sessionToken = \ auth_client.performLogin("Username:Password", "admin_group_user:admin123") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken) self.assertIsNotNone(client.allowsStoringAnalysisStatistics(), "Privileged server didn't respond properly.") result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.")
def test_editing_endpoint(self): """ Test if the product can successfully change its endpoint and keep the data. """ pr_client = env.setup_product_client( self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_endpoint = config.endpoint new_endpoint = "edited_endpoint" # Save a new endpoint. config.endpoint = new_endpoint self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") # Check if the configuration now uses the new values. config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.endpoint, new_endpoint, "Server didn't save new endpoint.") # The old product is gone. Thus, connection should NOT happen. res = self._cc_client.getRunData(None) self.assertIsNone(res) # The new product should connect and have the data. codechecker_cfg = self.test_cfg['codechecker_cfg'] token = self._auth_client.performLogin("Username:Password", "cc:test") new_client = env.get_viewer_client( host=codechecker_cfg['viewer_host'], port=codechecker_cfg['viewer_port'], product=new_endpoint, # Use the new product URL. endpoint='/CodeCheckerService', session_token=token) self.assertEqual(len(new_client.getRunData(None)), 1, "The new product did not serve the stored data.") # Set back to the old endpoint. config.endpoint = old_endpoint self.assertTrue(self._root_client.editProduct(product_id, config), "Product configuration restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.endpoint, old_endpoint, "Server didn't save back to old endpoint.") # The old product should have its data available again. runs = self._cc_client.getRunData(None) self.assertEqual( len(runs), 1, "We connected to old database but the run was missing.")
def test_editing_endpoint(self): """ Test if the product can successfully change its endpoint and keep the data. """ pr_client = env.setup_product_client(self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_endpoint = config.endpoint new_endpoint = "edited_endpoint" # Save a new endpoint. config.endpoint = new_endpoint self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") # Check if the configuration now uses the new values. config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.endpoint, new_endpoint, "Server didn't save new endpoint.") # The old product is gone. Thus, connection should NOT happen. res = self._cc_client.getRunData(None, None, 0, None) self.assertIsNone(res) # The new product should connect and have the data. codechecker_cfg = self.test_cfg['codechecker_cfg'] token = self._auth_client.performLogin("Username:Password", "cc:test") new_client = env.get_viewer_client( host=codechecker_cfg['viewer_host'], port=codechecker_cfg['viewer_port'], product=new_endpoint, # Use the new product URL. endpoint='/CodeCheckerService', session_token=token) self.assertEqual(len(new_client.getRunData(None, None, 0, None)), 1, "The new product did not serve the stored data.") # Set back to the old endpoint. config.endpoint = old_endpoint self.assertTrue(self._root_client.editProduct(product_id, config), "Product configuration restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.endpoint, old_endpoint, "Server didn't save back to old endpoint.") # The old product should have its data available again. runs = self._cc_client.getRunData(None, None, 0, None) self.assertEqual( len(runs), 1, "We connected to old database but the run was missing.")
def test_get_product_data(self): """ Test getting product configuration from server. """ # First, test calling the API through a product endpoint and not the # global endpoint. Also retrieve product ID this way. pr_client = env.setup_product_client( self.test_workspace, product=self.product_name) self.assertIsNotNone(pr_client, "Couldn't set up client") # This returns a USERSPACE product data. pr_data = pr_client.getCurrentProduct() self.assertIsNotNone(pr_data, "Couldn't retrieve product data properly") self.assertEqual(pr_data.endpoint, self.product_name, "The product's endpoint is improper.") self.assertTrue(pr_data.id > 0, "Product didn't have valid ID") # The connected attribute of a product will be always True if # database status is OK. connected = pr_data.databaseStatus == DBStatus.OK self.assertEqual(pr_data.connected, connected) # Now get the SERVERSPACE (configuration) for the product. # TODO: These things usually should only work for superusers! pr_conf = self._pr_client.getProductConfiguration(pr_data.id) self.assertIsNotNone(pr_conf, "Product configuration must come.") self.assertEqual(pr_conf.endpoint, self.product_name, "Product endpoint reproted by server must be the " "used endpoint... something doesn't make sense here!") self.assertIsNotNone(pr_conf.connection, "Product configuration must " "send a database connection.") self.assertIsNone(pr_conf.connection.password_b64, "!SECURITY LEAK! Server should NEVER send the " "product's database password out!") self.assertIn(self.product_name, pr_conf.connection.database, "The product's database (name|file) should contain " "the product's endpoint -- in the test context.") name = base64.b64decode(pr_conf.displayedName_b64) \ if pr_conf.displayedName_b64 else '' self.assertEqual(name, # libtest/codechecker.py uses the workspace's name. os.path.basename(self.test_workspace), "The displayed name must == the default value, as " "we didn't specify a custom displayed name.")
def setUp(self): self._test_workspace = os.environ.get('TEST_WORKSPACE') test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self._test_workspace) self._clang_to_test = env.clang_to_test() self._testproject_data = env.setup_test_proj_cfg(self._test_workspace) self.assertIsNotNone(self._testproject_data) # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self._test_workspace) self._product_name = self.test_cfg['codechecker_cfg']['viewer_product'] pr_client = env.setup_product_client(self._test_workspace, product=self._product_name) product_id = pr_client.getCurrentProduct().id # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') # Create an PRODUCT_ADMIN login. admin_token = self._auth_client.performLogin("Username:Password", "admin:admin123") extra_params = '{"productID":' + str(product_id) + '}' ret = self._auth_client.addPermission(Permission.PRODUCT_ADMIN, "admin", False, extra_params) self.assertTrue(ret) self._cc_client = env.setup_viewer_client(self._test_workspace, session_token=admin_token) self.assertIsNotNone(self._cc_client) # Get the run names which belong to this test run_names = env.get_run_names(self._test_workspace) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, 'There should be only one run for this test.') self._runid = test_runs[0].runId self._run_name = test_runs[0].name self._component_name = 'dummy_component' self._component_value = '\n'.join( ['+*/divide_zero.cpp', '-*/new_delete.cpp']) self._component_description = "Test component"
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self._test_workspace = os.environ['TEST_WORKSPACE'] # Display test name to log. test_class = self.__class__.__name__ print(f"Running {test_class} tests in {self._test_workspace}") # Get the test configuration from the prepared int the test workspace. test_config = env.import_test_cfg(self._test_workspace) # Log in and create credential file (if it is not exists). superuser_name = "root" superuser_passwd = "root" codechecker.login(test_config['codechecker_cfg'], self._test_workspace, superuser_name, superuser_passwd) temp_auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') # A non-authenticated session should return an empty user. user_name = temp_auth_client.getLoggedInUser() self.assertEqual(user_name, "") # Create a SUPERUSER login. self._session_token = temp_auth_client.performLogin( "Username:Password", f"{superuser_name}:{superuser_passwd}") self.assertIsNotNone(self._session_token, "Valid credentials didn't give us a token!") # Connect as root to the server. self._root_auth_client = env.setup_auth_client( self._test_workspace, session_token=self._session_token) user_name = self._root_auth_client.getLoggedInUser() self.assertEqual(user_name, superuser_name) # Query data of current product self._product_name = test_config['codechecker_cfg']['viewer_product'] self._product_client = env.setup_product_client( self._test_workspace, product=self._product_name) self.assertIsNotNone(self._product_client) self._current_product = self._product_client.getCurrentProduct() self.assertIsNotNone(self._current_product) self._product_id = self._current_product.id self.assertIsNotNone(self._product_id) self._extra_params = json.dumps({'productID': self._product_id})
def test_editing(self): """ Test editing the product details (without reconnecting it). """ pr_client = env.setup_product_client(self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_name = config.displayedName_b64 new_name = base64.b64encode("edited product name") config.displayedName_b64 = new_name with self.assertRaises(RequestFailed): self._pr_client.editProduct(product_id, config) print("Product was edited through non-superuser!") self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual( config.endpoint, self.product_name, "The product edit changed the endpoint, when it " "shouldn't have!") self.assertEqual(config.displayedName_b64, new_name, "The product edit didn't change the name.") # Restore the configuration of the product. config.displayedName_b64 = old_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product config restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.displayedName_b64, old_name, "The product edit didn't change the name back.")
def test_editing(self): """ Test editing the product details (without reconnecting it). """ pr_client = env.setup_product_client( self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_name = config.displayedName_b64 new_name = base64.b64encode("edited product name") config.displayedName_b64 = new_name with self.assertRaises(RequestFailed): self._pr_client.editProduct(product_id, config) print("Product was edited through non-superuser!") self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.endpoint, self.product_name, "The product edit changed the endpoint, when it " "shouldn't have!") self.assertEqual(config.displayedName_b64, new_name, "The product edit didn't change the name.") # Restore the configuration of the product. config.displayedName_b64 = old_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product config restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.displayedName_b64, old_name, "The product edit didn't change the name back.")
def test_editing(self): """ Test editing the product details (without reconnecting it). """ pr_client = env.setup_product_client(self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_name = config.displayedName_b64 new_name = convert.to_b64("edited product name") config.displayedName_b64 = new_name with self.assertRaises(RequestFailed): self._pr_client.editProduct(product_id, config) print("Product was edited through non-superuser!") self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual( config.endpoint, self.product_name, "The product edit changed the endpoint, when it " "shouldn't have!") self.assertEqual(config.displayedName_b64, new_name, "The product edit didn't change the name.") # Restore the configuration of the product. config.displayedName_b64 = old_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product config restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.displayedName_b64, old_name, "The product edit didn't change the name back.") # Change confidentiality. old_confidentiality = config.confidentiality new_confidentiality = Confidentiality.OPEN config.confidentiality = new_confidentiality self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.confidentiality, new_confidentiality, "Couldn't change the confidentiality to OPEN") new_confidentiality = Confidentiality.INTERNAL config.confidentiality = new_confidentiality self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.confidentiality, new_confidentiality, "Couldn't change the confidentiality to INTERNAL") new_confidentiality = Confidentiality.CONFIDENTIAL config.confidentiality = new_confidentiality self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual( config.confidentiality, new_confidentiality, "Couldn't change the confidentiality to CONFIDENTIAL") config.confidentiality = old_confidentiality self.assertTrue(self._root_client.editProduct(product_id, config), "Product config restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.confidentiality, old_confidentiality, "The edit didn't change back the confidentiality.")
def setUp(self): """ Set up the environment and the test module's configuration from the package. """ # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace_main = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace_main) # Set up a configuration for the main server. # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self.test_workspace_main) self.product_name = self.test_cfg['codechecker_cfg']['viewer_product'] # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace_main) self.assertIsNotNone(self._cc_client) # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self.test_workspace_main, session_token='_PROHIBIT') # Create a SUPERUSER login. root_token = self._auth_client.performLogin("Username:Password", "root:root") ret = self._auth_client.addPermission(Permission.SUPERUSER, "root", False, "") self.assertTrue(ret) # Setup a product client to test product API calls. self._pr_client = env.setup_product_client(self.test_workspace_main) self.assertIsNotNone(self._pr_client) # Setup a product client to test product API calls which requires root. self._root_client = env.setup_product_client(self.test_workspace_main, session_token=root_token) self.assertIsNotNone(self._pr_client) # Get the run names which belong to this test. run_names = env.get_run_names(self.test_workspace_main) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, "There should be only one run for this test.") self._runid = test_runs[0].runId # Start a second server with the same configuration database as the # main one. self.test_workspace_secondary = env.get_workspace('producttest_second') self.codechecker_cfg_2 = { 'check_env': self.test_cfg['codechecker_cfg']['check_env'], 'workspace': self.test_workspace_secondary, 'checkers': [], 'viewer_host': 'localhost', 'viewer_port': env.get_free_port(), 'viewer_product': 'producttest_second' } self.codechecker_cfg_2['check_env']['HOME'] = \ self.test_workspace_secondary env.export_test_cfg(self.test_workspace_secondary, {'codechecker_cfg': self.codechecker_cfg_2}) start_server(self.codechecker_cfg_2, EVENT) # Set up API clients for the secondary server. self._auth_client_2 = env.setup_auth_client( self.test_workspace_secondary, session_token='_PROHIBIT') root_token_2 = self._auth_client_2.performLogin( "Username:Password", "root:root") self._pr_client_2 = env.setup_product_client( self.test_workspace_secondary, session_token=root_token_2) self.assertIsNotNone(self._pr_client_2)
def test_editing_reconnect(self): """ Test if the product can successfully be set to connect to another db. This requires a SUPERUSER. """ pr_client = env.setup_product_client(self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_db_name = config.connection.database # Create a new database. tenv = self.test_cfg['codechecker_cfg']['check_env'] if config.connection.engine == 'sqlite': new_db_name = os.path.join(self.test_workspace, 'new.sqlite') elif config.connection.engine == 'postgresql': new_db_name = 'editeddb' env.add_database(new_db_name, tenv) else: raise ValueError("I was not prepared to handle database mode " + config.connection.engine) config.connection.database = new_db_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") # Check if the configuration now uses the new values. config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.connection.database, new_db_name, "Server didn't save new database name.") self.assertEqual( config.endpoint, self.product_name, "The endpoint was changed -- perhaps the " "temporary connection leaked into the database?") # There is no schema initialization if the product database # was changed. The inital schema needs to be created manually # for the new database. runs = self._cc_client.getRunData(None, None, 0, None) self.assertIsNone(runs) # Connect back to the old database. config.connection.database = old_db_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product configuration restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.connection.database, old_db_name, "Server didn't save back to old database name.") # The old database should have its data available again. runs = self._cc_client.getRunData(None, None, 0, None) self.assertEqual( len(runs), 1, "We connected to old database but the run was missing.") # Drop the temporary database. SQLite file will be removed with # the test workspace. if config.connection.engine == 'postgresql': env.del_database(new_db_name, tenv)
def test_editing_reconnect(self): """ Test if the product can successfully be set to connect to another db. This requires a SUPERUSER. """ pr_client = env.setup_product_client( self.test_workspace, product=self.product_name) product_id = pr_client.getCurrentProduct().id config = self._pr_client.getProductConfiguration(product_id) old_db_name = config.connection.database # Create a new database. tenv = self.test_cfg['codechecker_cfg']['check_env'] if config.connection.engine == 'sqlite': new_db_name = os.path.join(self.test_workspace, 'new.sqlite') elif config.connection.engine == 'postgresql': new_db_name = 'editeddb' env.add_database(new_db_name, tenv) else: raise ValueError("I was not prepared to handle database mode " + config.connection.engine) config.connection.database = new_db_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product edit didn't conclude.") # Check if the configuration now uses the new values. config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.connection.database, new_db_name, "Server didn't save new database name.") self.assertEqual(config.endpoint, self.product_name, "The endpoint was changed -- perhaps the " "temporary connection leaked into the database?") # There is no schema initialization if the product database # was changed. The inital schema needs to be created manually # for the new database. runs = self._cc_client.getRunData(None) self.assertIsNone(runs) # Connect back to the old database. config.connection.database = old_db_name self.assertTrue(self._root_client.editProduct(product_id, config), "Product configuration restore didn't conclude.") config = self._pr_client.getProductConfiguration(product_id) self.assertEqual(config.connection.database, old_db_name, "Server didn't save back to old database name.") # The old database should have its data available again. runs = self._cc_client.getRunData(None) self.assertEqual( len(runs), 1, "We connected to old database but the run was missing.") # Drop the temporary database. SQLite file will be removed with # the test workspace. if config.connection.engine == 'postgresql': env.del_database(new_db_name, tenv)
def setUp(self): self._test_workspace = os.environ.get('TEST_WORKSPACE') test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self._test_workspace) self._clang_to_test = env.clang_to_test() self._testproject_data = env.setup_test_proj_cfg(self._test_workspace) self.assertIsNotNone(self._testproject_data) # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self._test_workspace) self._product_name = self.test_cfg['codechecker_cfg']['viewer_product'] pr_client = env.setup_product_client( self._test_workspace, product=self._product_name) product_id = pr_client.getCurrentProduct().id # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') # Create an PRODUCT_ADMIN login. admin_token = self._auth_client.performLogin("Username:Password", "admin:admin123") extra_params = '{"productID":' + str(product_id) + '}' ret = self._auth_client.addPermission(Permission.PRODUCT_ADMIN, "admin", False, extra_params) self.assertTrue(ret) self._cc_client = env.setup_viewer_client(self._test_workspace, session_token=admin_token) self.assertIsNotNone(self._cc_client) # Get the run names which belong to this test run_names = env.get_run_names(self._test_workspace) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, 'There should be only one run for this test.') self._runid = test_runs[0].runId self._run_name = test_runs[0].name self.components = [ { 'name': 'test_component1', 'value': '\n'.join(['+*/divide_zero.cpp', '-*/new_delete.cpp']), 'description': 'Description of my first component' }, { 'name': 'component name with whitespaces', 'value': '\n'.join(['+*/divide_zero.cpp', '-*/new_delete.cpp']), 'description': 'Description of my second component' }, { 'name': 'test_component2', 'value': '\n'.join(['+*/divide_zero.cpp', '+*/null_dereference.cpp', '-*/call_and_message.cpp', '-*/new_delete.*']), 'description': 'Description of my second component' }, { 'name': 'complex1', 'value': '\n'.join(['+*/divide_zero.cpp', '-*/call_and_message.cpp']) }, { 'name': 'complex2', 'value': '\n'.join(['+*/null_dereference.cpp', '-*/new_delete.cpp']) }, { 'name': 'exclude_all', 'value': '-*' } ]