def teardown_package(): """Clean up after the test.""" # TODO: If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE codechecker.remove_test_package_product(TEST_WORKSPACE) print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE)
def teardown_package(): """Clean up after the test.""" # TODO: If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE codechecker.remove_test_package_product(TEST_WORKSPACE) print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE)
def teardown_package(): """Clean up after the test.""" # TODO: If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg(TEST_WORKSPACE)[ 'codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) print("Removing: " + TEST_WORKSPACE)
def teardown_package(): """Clean up after the test.""" # TODO: If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg( TEST_WORKSPACE)['codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) print("Removing: " + TEST_WORKSPACE)
def teardown_package(): """ Delete the workspace associated with this test. """ # TODO: If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg( TEST_WORKSPACE)['codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE # Removing the product through this server requires credentials. codechecker_cfg = env.import_test_cfg(TEST_WORKSPACE)['codechecker_cfg'] codechecker.remove_test_package_product(TEST_WORKSPACE, codechecker_cfg['check_env']) __STOP_SERVER.set() print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE # Removing the product through this server requires credentials. codechecker_cfg = env.import_test_cfg(TEST_WORKSPACE)['codechecker_cfg'] codechecker.remove_test_package_product(TEST_WORKSPACE, codechecker_cfg['check_env']) __STOP_SERVER.set() print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg(TEST_WORKSPACE)[ 'codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) # Let the remaining CodeChecker servers die. EVENT_1.set() print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg(TEST_WORKSPACE)[ 'codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) # Let the remaining CodeChecker servers die. EVENT_1.set() print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE # Removing the product through this server requires credentials. codechecker_cfg = env.import_test_cfg(TEST_WORKSPACE)['codechecker_cfg'] codechecker.remove_test_package_product(TEST_WORKSPACE, codechecker_cfg['check_env']) __STOP_SERVER.set() # The custom server stated in a separate home needs to be waited, so it # can properly execute its finalizers. time.sleep(5) print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def teardown_package(): """Stop the CodeChecker server and clean up after the tests.""" # TODO If environment variable is set keep the workspace # and print out the path. global TEST_WORKSPACE check_env = env.import_test_cfg(TEST_WORKSPACE)[ 'codechecker_cfg']['check_env'] codechecker.remove_test_package_product(TEST_WORKSPACE, check_env) # Let the remaining CodeChecker servers die. EVENT_1.set() # The custom server stated in a separate home needs to be waited, so it # can properly execute its finalizers. time.sleep(5) print("Removing: " + TEST_WORKSPACE) shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ # Switch off certificate validation on the clients. os.environ["OSPYTHONHTTPSVERIFY"] = '0' # FIXME: change this to https access_protocol = 'http' auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT', proto=access_protocol) handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace, access_protocol) with self.assertRaises(TProtocolException): # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! client.getPackageVersion() print("Privileged client allowed access after logout.") handshake = auth_client.getAuthParameters() self.assertFalse(handshake.sessionStillActive, "Destroyed session was " + "reported to be still active.") codechecker.remove_test_package_product( self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol)
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ # Switch off certificate validation on the clients. os.environ["OSPYTHONHTTPSVERIFY"] = '0' # FIXME: change this to https access_protocol = 'http' auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT', proto=access_protocol) handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace, access_protocol) # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! version = client.getPackageVersion() self.assertIsNone(version, "Privileged client allowed access after logout.") handshake = auth_client.getAuthParameters() self.assertFalse( handshake.sessionStillActive, "Destroyed session was " + "reported to be still active.") codechecker.remove_test_package_product( self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol)