def test_bulk_system_delete_works_with_built_in_set(clean_bulk_delete_systems_and_accounts, core_session, core_tenant, clean_users, users_and_roles, list_of_created_systems, get_environment): Engines = get_environment if Engines == "AWS - PLV8": batch = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 3, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch]) right_data = ("Privileged Access Service Power User", "role_Privileged Access Service Power User") requester_session = users_and_roles.get_session_for_user(right_data[0]) role_info = users_and_roles.get_role(right_data[0]) account_ids = ResourceManager.get_multi_added_account_ids(core_session, all_systems) for account_id in account_ids: permission_string = 'Owner,View,Manage,Delete,Login,Naked,UpdatePassword,FileTransfer,UserPortalLogin' result, success = ResourceManager.assign_account_permissions( core_session, permission_string, role_info['Name'], role_info['ID'], "Role", account_id) assert success, "Did not set account permissions " + str(result) system_ids = list(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) for system_id in system_ids: permission_string = 'Grant,View,Edit,Delete,ManageSession,AgentAuth,RequestZoneRole,AddAccount,' \ 'UnlockAccount ' result, success = ResourceManager.assign_system_permissions(core_session, permission_string, role_info['Name'], role_info['ID'], "Role", system_id) assert success, "Did not set system permissions " + result job_id, result = ResourceManager.del_multiple_systems_by_query(requester_session, '@@Windows Servers') report = JobManager.get_job_report(core_session, job_id) # not asserting success or failure, the admin may have access to windows systems created by other tests which # would not succeed such as windows systems with uncertain accounts assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 0, f"Expected no remaining added accounts {report}" assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 0, f"Expected no remaining added systems {report}" else: skip('todo: Fix this test to work on azure')
def test_bulk_system_deletes_manually_single_system_and_secret(clean_bulk_delete_systems_and_accounts, core_session, core_ui, list_of_created_systems, secret_cleaner): server_prefix, names_of_servers, server_ids = _make_one_server_get_name(core_session, list_of_created_systems) ui = core_ui ui.navigate('Resources', 'Systems') ui.search(server_prefix) for name in names_of_servers: assert ui.check_exists(GridCell(name)), "Missing server from view " + name ui.action('Delete', names_of_servers) core_ui.switch_context(Modal('System Delete')) secret_name = "secret_e2e_name_" + guid() core_ui.input("SecretName", secret_name) core_ui.button('Delete') ResourceManager.wait_for_systems_to_delete_or_timeout(core_session, server_ids) assert len(ResourceManager.get_multi_added_account_ids(core_session, server_ids)) == 0, "All added accounts not removed" assert len(ResourceManager.get_multi_added_system_ids(core_session, server_ids)) == 0, "All added systems not removed" ResourceManager.wait_for_secret_to_exist_or_timeout(core_session, secret_name) secret_id = RedrockController.get_secret_id_by_name(core_session, secret_name) assert secret_id is not None, "Secret not found" secret_cleaner.append(secret_id)
def test_bulk_system_delete_no_secret_manually(clean_bulk_delete_systems_and_accounts, core_session, core_ui, list_of_created_systems, secret_cleaner): server_prefix, names_of_servers, server_ids = _make_two_servers_get_names(core_session, list_of_created_systems) ui = core_ui ui.navigate('Resources', 'Systems') ui.search(server_prefix) for name in names_of_servers: assert ui.check_exists(GridCell(name)), "Server not found in grid " + name ui.action('Delete Systems', names_of_servers) core_ui.switch_context(Modal('Bulk System Delete')) core_ui.uncheck("SaveSecret") core_ui.button('Delete') core_ui.switch_context(ConfirmModal()) core_ui.button('Yes') core_ui.switch_context(NoTitleModal()) core_ui.button('Close') ResourceManager.wait_for_systems_to_delete_or_timeout(core_session, server_ids) assert len(ResourceManager.get_multi_added_account_ids(core_session, server_ids)) == 0, "All added accounts not removed" assert len(ResourceManager.get_multi_added_system_ids(core_session, server_ids)) == 0, "All added systems not removed"
def test_bulk_system_deletes_manually_from_set(clean_bulk_delete_systems_and_accounts, core_session, core_ui, list_of_created_systems): server_prefix, names_of_servers, server_ids = _make_two_servers_get_names(core_session, list_of_created_systems) ui = core_ui ui.navigate('Resources', 'Systems') ui.search(server_prefix) not_favorite_stars = ui.browser.get_list_of_elements_by_css_selector("img.server-is-not-favorite") assert len(not_favorite_stars) == 2, "Expected two favorite stars to be found, but other number returned" for star in not_favorite_stars: star.click() # favorite server core_ui.set_action("Favorites", "Delete Systems") core_ui.switch_context(Modal('Bulk System Delete')) core_ui.button('Delete') core_ui.switch_context(NoTitleModal()) core_ui.button('Close') ResourceManager.wait_for_systems_to_delete_or_timeout(core_session, server_ids) assert len(ResourceManager.get_multi_added_account_ids(core_session, server_ids)) == 0, "All added accounts not removed" assert len(ResourceManager.get_multi_added_system_ids(core_session, server_ids)) == 0, "All added systems not removed"
def test_app_management_user_can_create_job_but_not_delete_servers(clean_bulk_delete_systems_and_accounts, core_session, core_tenant, clean_users, users_and_roles, list_of_created_systems): batch = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch]) requestor_session = users_and_roles.get_session_for_user('Application Management') user_info = requestor_session.get_current_session_user_info().json()['Result'] all_systems = batch.keys() job_id, result = ResourceManager.del_multiple_systems(requestor_session, all_systems) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" assert len( ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 3, "Wrong number of remaining systems" assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 6, "Wrong number of remaining accounts" username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.Failure.Multi' start_message = f'{username} initiated delete of {len(all_systems)} systems' end_message = f'{username} failed to delete {len(all_systems)} of {len(all_systems)} systems' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_bulk_system_by_api_set_correct_systems_and_accounts_fast_track(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 2, list_of_created_systems, sys_type="Unix") batch3 = ResourceManager.add_multiple_systems_with_accounts(core_session, 5, 1, list_of_created_systems, sys_type="Unix") delete_system_ids, delete_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch2]) keep_system_ids, keep_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch1, batch3]) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2, batch3]) some_set_name = "ApiSet" + guid() SetsManager.create_manual_collection(core_session, some_set_name, "Server", None) set_id = SetsManager.get_collection_id(core_session, some_set_name, "Server") SetsManager.update_members_collection(core_session, 'add', list(delete_system_ids), 'Server', set_id) collection_and_filters = SetsManager.get_object_collection_and_filter_by_name(core_session, some_set_name, "Server") filters = collection_and_filters['Filters'] logger.info(f'Manual set {collection_and_filters} - members - {delete_system_ids}') result, success = ResourceManager.del_multiple_systems_by_query(core_session, filters, savepasswords=False, secretname="", run_sync=True) assert success is True, f'Delete systems job failed when expected success' SetsManager.delete_collection(core_session, set_id) assert set(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) == keep_system_ids, "Set of expected remaining systems did not match search" assert set(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == keep_account_ids, "Set of expected remaining accounts did not match search"
def test_bulk_account_deletes_with_ui_no_secret( clean_bulk_delete_systems_and_accounts, core_session, core_admin_ui, list_of_created_systems): server_prefix, account_prefix, all_systems, all_accounts, all_account_names = _make_four_accounts_get_names( core_session, list_of_created_systems, ssh=True) ui = core_admin_ui ui.navigate('Resources', 'Accounts') ui.search(server_prefix) for name in all_account_names: assert ui.check_exists( GridCell(name)), f"Account name {name} not found in grid" ui.action('Delete accounts', all_account_names) ui.switch_context(Modal('Bulk Account Delete')) ui.uncheck("SaveSecret") ui.button('Delete') ui.switch_context(ConfirmModal()) ui.button('Yes') ui.switch_context(InfoModal()) ui.button('Close') ResourceManager.wait_for_accounts_to_delete_or_timeout( core_session, all_systems, all_accounts) assert len( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == 0, "All added accounts not removed" assert len( ResourceManager.get_multi_added_system_ids( core_session, all_systems)) == 2, "Wrong number of added systems remain"
def test_bulk_system_delete_by_ids_only_deletes_correct_systems_and_accounts_fast_track( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): user_info = core_session.get_current_session_user_info().json()['Result'] batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 2, list_of_created_systems) batch3 = ResourceManager.add_multiple_systems_with_accounts(core_session, 4, 6, list_of_created_systems) batch4 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 8, list_of_created_systems) batch5 = ResourceManager.add_multiple_systems_with_accounts(core_session, 5, 1, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2, batch3, batch4, batch5]) delete_system_ids, delete_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch2, batch4]) keep_system_ids, keep_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch1, batch3, batch5]) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2, batch3, batch4, batch5]) ResourceManager.del_multiple_systems(core_session, delete_system_ids, savepasswords=True, wait_time=0, skip_if_has_apps_or_services=True, run_sync=True) assert set(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) == keep_system_ids, "Set of expected remaining systems did not match search" assert set(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == keep_account_ids, "Set of expected remaining accounts did not match search" username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.Success.Multi' start_message = f'{username} initiated delete of {len(delete_system_ids)} systems' end_message = f'{username} successfully deleted {len(delete_system_ids)} systems' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_bulk_account_delete_performs_quickly( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): # test constants large_number_for_stress_testing = 50 # tested once with higher numbers but reduced for quick execution reasonable_amount_of_time_to_execute = 90 batch1 = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, large_number_for_stress_testing // 2, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, large_number_for_stress_testing // 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2]) start_time = time.time() result, success = ResourceManager.del_multiple_accounts( core_session, all_accounts) assert success, "Api did not complete successfully for bulk account delete " + result end_time = time.time() elapsed_time = end_time - start_time assert elapsed_time <= reasonable_amount_of_time_to_execute, \ "Did not complete operation in a reasonable amount of time" assert len( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == 0, "Expected 0 added accounts found" assert len( ResourceManager.get_multi_added_system_ids( core_session, all_systems)) == 2, "Expected 2 added systems found"
def test_bulk_account_delete_by_sql_query_only_deletes_correct_accounts_fast_track( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 12, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch]) delete_ids, keep_ids = DataManipulation.shuffle_and_split_into_two_lists( all_accounts) sql_query = 'SELECT * FROM VaultAccount WHERE ' + ' OR '.join( ('VaultAccount.ID = "' + str(n) + '"' for n in list(delete_ids))) result, success = ResourceManager.del_multiple_accounts_by_query( core_session, sql_query, run_sync=True) assert success, "del_multiple_accounts_by_query failed " + result assert set(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) == set(all_systems), \ "Wrong set of added systems found" assert set(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == set(keep_ids), \ "Wrong set of added accounts found" user_info = core_session.get_current_session_user_info().json()['Result'] username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.StartQuery.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.Success.Multi' start_message = f'{username} initiated delete of multiple accounts' end_message = f'{username} successfully deleted {len(delete_ids)} accounts' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_app_management_user_can_create_job_but_not_delete_accounts( clean_bulk_delete_systems_and_accounts, core_session, core_tenant, clean_users, users_and_roles, list_of_created_systems): batch = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch]) assert len( ResourceManager.get_multi_added_system_ids( core_session, all_systems)) == 2, "Added systems not reflected in search" assert len( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == 4, "Added accounts not reflected in search" requestor_session = users_and_roles.get_session_for_user( 'Application Management') job_id, result = ResourceManager.del_multiple_accounts( requestor_session, all_accounts) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 2, \ "Expected 2 added systems to be found, but received different number" assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 4, \ "Expected 4 added accounts to be found, but received different number" user_info = requestor_session.get_current_session_user_info().json( )['Result'] username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.Failure.Multi' start_message = f'{username} initiated delete of {len(all_accounts)} accounts' end_message = f'{username} failed to delete {len(all_accounts)} of {len(all_accounts)} accounts' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def _make_one_server_get_name(session, mutable_list, ssh=False): server_prefix = "bsd_tst_sys" + "-" + str(ResourceManager.time_mark_in_hours()) + "-" + guid() if ssh: batch1 = ResourceManager.add_multiple_ssh_systems_with_accounts(session, 1, 2, mutable_list, system_prefix=server_prefix) else: batch1 = ResourceManager.add_multiple_systems_with_accounts(session, 1, 2, mutable_list, system_prefix=server_prefix) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1]) names_of_servers = list(ResourceManager.get_multi_added_system_ids(session, all_systems).keys()) return server_prefix, names_of_servers, batch1.keys()
def test_bulk_system_delete_by_sql_query_only_deletes_correct_systems_and_accounts( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): user_info = core_session.get_current_session_user_info().json()['Result'] assert len(ResourceManager.get_multi_added_system_ids(core_session, [ "x"])) == 0 # Use fake GUID string to ensure that filter is working properly, since empty list means no filter assert len(ResourceManager.get_multi_added_account_ids(core_session, ["x"])) == 0 batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 2, list_of_created_systems) batch3 = ResourceManager.add_multiple_systems_with_accounts(core_session, 4, 6, list_of_created_systems) batch4 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 8, list_of_created_systems) batch5 = ResourceManager.add_multiple_systems_with_accounts(core_session, 5, 1, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2, batch3, batch4, batch5]) assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 15, "Found wrong number of added systems" assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 59, "Found wrong number of add accounts" delete_system_ids, delete_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch2, batch4]) keep_system_ids, keep_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch1, batch3, batch5]) sql_query = RedrockController.get_query_for_ids('Server', delete_system_ids) ResourceManager.del_multiple_systems_by_query(core_session, sql_query, False, "") assert set(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) == keep_system_ids, "Set of expected remaining systems did not match search" assert set(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == keep_account_ids, "Set of expected remaining accounts did not match search" username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.StartQuery.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkSystemDelete.Success.Multi' start_message = f'{username} initiated delete of multiple systems' end_message = f'{username} successfully deleted {len(delete_system_ids)} systems' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_other_user_cant_see_secret_created_by_first_user(core_session, users_and_roles, created_system_id_list, swap_roles): roles = ["Privileged Access Service Administrator", "Privileged Access Service Power User"] if swap_roles: roles_new = [roles[1], roles[0]] roles = roles_new batch = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 2, created_system_id_list) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch]) deleter_user_0_session = users_and_roles.get_session_for_user(roles[0]) deleter_user_0_role = users_and_roles.get_role(roles[0]) deleter_user_0_role_name = deleter_user_0_role['Name'] deleter_user_0_role_id = deleter_user_0_role['ID'] other_user_1_session = users_and_roles.get_session_for_user(roles[1]) for account_id in all_accounts: permission_string = 'Owner,View,Manage,Delete,Login,Naked,UpdatePassword,FileTransfer,UserPortalLogin' result, success = ResourceManager.assign_account_permissions(core_session, permission_string, deleter_user_0_role_name, deleter_user_0_role_id, "Role", account_id) assert success, "Did not set account permissions " + str(result) for system_id in all_systems: permission_string = 'Grant,View,Edit,Delete,ManageSession,AgentAuth,RequestZoneRole,AddAccount,UnlockAccount' result, success = ResourceManager.assign_system_permissions(core_session, permission_string, deleter_user_0_role_name, deleter_user_0_role_id, "Role", system_id) assert success, "Did not set system permissions " + result secret_name = f"secret{guid()}" job_id, result = ResourceManager.del_multiple_systems(deleter_user_0_session, batch.keys(), secretname=secret_name) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" remaining_accounts = set(ResourceManager.get_multi_added_account_ids(core_session, created_system_id_list)) remaining_systems = set(ResourceManager.get_multi_added_system_ids(core_session, created_system_id_list).values()) assert remaining_accounts == set(), "Remaining accounts did not match expectation" assert remaining_systems == set(), "Remaining systems did not match expectation" secret_id = RedrockController.get_secret_id_by_name(deleter_user_0_session, secret_name) assert secret_id is not None, f"Secret was not visible to creator '{roles[0]}' user, either because it wasn't created or because of a permissions issue" secret_id = RedrockController.get_secret_id_by_name(other_user_1_session, secret_name) assert secret_id is None, f"Secret should not be '{roles[1]}' user when created by '{roles[0]}' user" secret_id = RedrockController.get_secret_id_by_name(core_session, secret_name) assert secret_id is not None, f"Sys admin should be able to see secret created by {roles[0]}"
def test_redundant_requests_succeed(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 2, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2]) ResourceManager.del_multiple_systems(core_session, batch1.keys()) ResourceManager.del_multiple_systems(core_session, batch2.keys()) ResourceManager.del_multiple_systems(core_session, batch1.keys()) ResourceManager.del_multiple_systems(core_session, batch2.keys()) assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 0, "Expected no remaining added accounts" assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 0, "Expected no remaining added systems"
def test_overlapping_requests_succeed(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 4, 2, list_of_created_systems) batch3 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 1, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2, batch3]) ResourceManager.del_multiple_systems(core_session, batch1.keys(), wait_time=-1) ResourceManager.del_multiple_systems(core_session, batch1.keys(), wait_time=-1) # redundancy deliberate ResourceManager.del_multiple_systems(core_session, batch2.keys(), wait_time=-1) ResourceManager.del_multiple_systems(core_session, batch3.keys()) # wait on final call assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 0, "Expected no remaining added accounts" assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 0, "Expected no remaining added systems"
def test_bulk_account_delete_one_account_at_a_time( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): server_prefix, account_prefix, all_systems, all_accounts, all_account_names = _make_four_accounts_get_names \ (core_session, list_of_created_systems, ssh=False) for i in all_accounts: ResourceManager.del_account(core_session, i) ResourceManager.wait_for_accounts_to_delete_or_timeout( core_session, all_systems, all_accounts) assert len( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == 0, "All added accounts not removed" assert len( ResourceManager.get_multi_added_system_ids( core_session, all_systems)) == 1, "Wrong number of added systems remain"
def test_bulk_account_delete_by_ids_only_deletes_correct_accounts( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts( core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 2, list_of_created_systems) batch3 = ResourceManager.add_multiple_systems_with_accounts( core_session, 4, 6, list_of_created_systems) batch4 = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 8, list_of_created_systems) batch5 = ResourceManager.add_multiple_systems_with_accounts( core_session, 5, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2, batch3, batch4, batch5]) delete_ids, keep_ids = DataManipulation.shuffle_and_split_into_two_lists( all_accounts) result, success = ResourceManager.del_multiple_accounts( core_session, delete_ids) assert success, "Api did not complete successfully for bulk account delete MSG: " + result assert set( ResourceManager.get_multi_added_system_ids( core_session, all_systems).values()) == set( all_systems), "Wrong set of added systems found" assert set( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == set(keep_ids), "Wrong set of added accounts found" user_info = core_session.get_current_session_user_info().json()['Result'] username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkAccountDelete.Success.Multi' start_message = f'{username} initiated delete of {len(delete_ids)} accounts' end_message = f'{username} successfully deleted {len(delete_ids)} accounts' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_add_and_delete_system_with_multiple_benchmarks_per_test( core_session, created_system_id_list, csv_benchmark): """ This test demonstrates measuring multiple things within the same pytest test See example output at bottom of this file """ start, end, info = csv_benchmark info(filenamesuffix="Bulk System Delete Time Test") for i in range(3): info(row=f"Test Run {i+1}") info(column="Generate Systems") start() batch = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 2, created_system_id_list) end() secret_name = f"secret{guid()}" info(column="Delete Job") start() job_id, result = ResourceManager.del_multiple_systems( core_session, batch.keys(), secretname=secret_name) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" end() info(column="Query Systems and Accounts") start() remaining_accounts = set( ResourceManager.get_multi_added_account_ids( core_session, created_system_id_list)) remaining_systems = set( ResourceManager.get_multi_added_system_ids( core_session, created_system_id_list).values()) assert remaining_accounts == set( ), "Remaining accounts did not match expectation" assert remaining_systems == set( ), "Remaining systems did not match expectation" end() info(column="Query Secret") start() secret_id = RedrockController.get_secret_id_by_name( core_session, secret_name) assert secret_id is not None, "No secret was created" end()
def test_bulk_system_deletes_mixed_ssh_systems(clean_bulk_delete_systems_and_accounts, core_session, core_ui, list_of_created_systems, secret_cleaner): server_prefix, names_of_servers, server_ids = _make_two_servers_get_names(core_session, list_of_created_systems, ssh=True) ui = core_ui ui.navigate('Resources', 'Systems') ui.search(server_prefix) for name in names_of_servers: assert ui.check_exists(GridCell(name)), "Missing server from view " + name ui.action('Delete Systems', names_of_servers) core_ui.switch_context(Modal('Bulk System Delete')) core_ui.button('Delete') core_ui.switch_context(InfoModal()) core_ui.button('Close') ResourceManager.wait_for_systems_to_delete_or_timeout(core_session, server_ids) assert len(ResourceManager.get_multi_added_account_ids(core_session, server_ids)) == 0, "All added accounts not removed" assert len(ResourceManager.get_multi_added_system_ids(core_session, server_ids)) == 0, "All added systems not removed"
def test_power_user_cant_see_secret_created_by_sysadmin_bsd(core_session, users_and_roles, created_system_id_list): batch = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 2, created_system_id_list) secret_name = f"secret{guid()}" job_id, result = ResourceManager.del_multiple_systems(core_session, batch.keys(), secretname=secret_name) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" remaining_accounts = set(ResourceManager.get_multi_added_account_ids(core_session, created_system_id_list)) remaining_systems = set(ResourceManager.get_multi_added_system_ids(core_session, created_system_id_list).values()) assert remaining_accounts == set(), "Remaining accounts did not match expectation" assert remaining_systems == set(), "Remaining systems did not match expectation" requester_session = users_and_roles.get_session_for_user("Privileged Access Service Power User") secret_id = RedrockController.get_secret_id_by_name(core_session, secret_name) assert secret_id is not None, "No secret was created" secret_id = RedrockController.get_secret_id_by_name(requester_session, secret_name) assert secret_id is None, "Secret should not be visible to Privileged Access Service Power User"
def test_overlapping_redundant_requests_succeed( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 16, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 15, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2]) all_accounts_list = list(all_accounts) random.shuffle(all_accounts_list) delete_ids1, keep_ids1 = DataManipulation.shuffle_and_split_into_two_lists( all_accounts_list[1::] ) # by excluding the first, we ensure one account is guaranteed to remain delete_ids2, _ = DataManipulation.shuffle_and_split_into_two_lists( all_accounts_list[1::]) delete_ids3, _ = DataManipulation.shuffle_and_split_into_two_lists( all_accounts_list[1::]) ResourceManager.del_multiple_accounts(core_session, delete_ids1, wait_time=-60) ResourceManager.del_multiple_accounts(core_session, delete_ids2, wait_time=-60) ResourceManager.del_multiple_accounts(core_session, delete_ids3) # wait on final call all_delete = set(delete_ids1).union(delete_ids2).union(delete_ids3) assert len( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == len(all_accounts) - len( all_delete), "Wrong number of remaining added accounts found" assert len(ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 2, \ "Wrong number of remaining added systems found"
def test_bulk_account_by_api_set_correct_accounts( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems, core_admin_ui): batch = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch]) delete_ids, keep_ids = DataManipulation.shuffle_and_split_into_two_lists( all_accounts) some_set_name = "ApiSet" + guid() success, set_id = SetsManager.create_manual_collection( core_session, some_set_name, "VaultAccount", None) assert success, "Did not create collection" SetsManager.update_members_collection(core_session, 'add', list(delete_ids), 'VaultAccount', set_id) filters = SetsManager.get_object_collection_and_filter_by_name( core_session, some_set_name, "VaultAccount")['Filters'] result, success = ResourceManager.del_multiple_accounts_by_query( core_session, filters) assert success, "del_multiple_accounts_by_query failed " + result SetsManager.delete_collection(core_session, set_id) assert set( ResourceManager.get_multi_added_system_ids( core_session, all_systems).values()) == set( all_systems), "Wrong set of added systems found" assert set( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == set(keep_ids), "Wrong set of added accounts found"
def test_check_menu_two_sys_under_password_checkouts(core_session, list_of_created_systems, core_admin_ui, cleanup_resources, cleanup_accounts): """ TC:C2174 Check menu when choosing two systems under My Password Checkouts. :param:core_session: Returns Authenticated Centrify session. :param:list_of_created_systems:Container for created system. :param:core_admin_ui: Returns browser session. :param:cleanup_resources: Cleans up system. :param:cleanup_accounts:Cleans up accounts. """ system_list = cleanup_resources[0] accounts_list = cleanup_accounts[0] # Creating multiple system and accounts. batches = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 1, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batches]) assert len( ResourceManager.get_multi_added_system_ids(core_session, all_systems)) == 2, f"Failed to create multiple " \ f"system with accounts: API " \ f"response result: {batches} " assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 2, f"Failed to create multiple system " \ f"with accounts: API response result: " \ f"{batches} " logger.info( f'Successfully Created multiple system with accounts.:{batches}') # Appending the created system and accounts id for cleanup. for all_account in all_accounts: accounts_list.append(all_account) for all_system in all_systems: system_list.append(all_system) # Checking out password for the account created. accounts_password_checkout = [] for account_id in all_accounts: result, status = ResourceManager.check_out_password( core_session, 1, account_id, 'test checkout account') accounts_password_checkout.append(result['COID']) assert status, f'Failed to checkout password: API response result: {result}' # Getting the account name. accounts_name = [] for account_id in all_accounts: result, success = ResourceManager.get_account_information( core_session, account_id) accounts_name.append(result["VaultAccount"]["Row"]['User']) # Validating "No actions available" after selecting two accounts from My Password Checkout Title in workspace. ui = core_admin_ui ui.navigate(("Workspace", "My Password Checkouts")) ui.switch_context(RenderedTab('My Password Checkouts')) ui.check_actions_by_guid([], accounts_password_checkout) logger.info( 'Successfully found "No actions available." after password account checkout.' )
def test_missing_permissions_on_bsd_accounts_and_systems(core_session, users_and_roles, created_system_id_list, explicit_missing_delete_permission): """ Make three systems, with accounts System 0 - Delete permissions on every account and on system System 1 - Delete permissions on HALF its accounts and on system System 2 - Delete permissions on every of its accounts, but not on system Then Bulk System Delete. All accounts with delete permissions will be gone. Systems 0 and 1 will remain. :param explicit_missing_delete_permission: If True, the permission string will be set without Delete. If False, the permissions will not be modified (with Delete missing assumed) :param core_session: Authenticated Centrify Session. :param users_and_roles: Fixture to create New user with PAS Power Rights :param created_system_id_list: A list for holding created systems, that will be deleted after the test :return: """ original_systems = 3 original_accounts_per_system = 4 batch = ResourceManager.add_multiple_systems_with_accounts(core_session, original_systems, original_accounts_per_system, created_system_id_list) # These two variables will have extra set items added below from System 1 deleted_accounts, expected_preserved_accounts = set(batch[created_system_id_list[0]]).union( set(batch[created_system_id_list[2]])), set() split1, split2 = DataManipulation.shuffle_and_split_into_two_lists(batch[created_system_id_list[1]]) deleted_accounts = deleted_accounts.union(set(split1)) expected_preserved_accounts = expected_preserved_accounts.union(set(split2)) # System 1 fails to delete because some of its child accounts are not deleted # System 2 fails for missing delete permission expected_preserved_systems = {created_system_id_list[1], created_system_id_list[2]} delete_system_permissions = {created_system_id_list[0], created_system_id_list[1]} requester_session = users_and_roles.get_session_for_user("Privileged Access Service Power User") results_role = users_and_roles.get_role("Privileged Access Service Power User") for account_id in deleted_accounts: permission_string = 'Owner,View,Manage,Delete,Login,Naked,UpdatePassword,FileTransfer,UserPortalLogin' result, success = ResourceManager.assign_account_permissions(core_session, permission_string, results_role['Name'], results_role['ID'], "Role", account_id) assert success, "Did not set account permissions " + str(result) if explicit_missing_delete_permission: for account_id in expected_preserved_accounts: permission_string = 'Owner,View,Manage,Login,Naked,UpdatePassword,FileTransfer,UserPortalLogin' result, success = ResourceManager.assign_account_permissions(core_session, permission_string, results_role['Name'], results_role['ID'], "Role", account_id) assert success, "Did not set account permissions " + str(result) for system_id in created_system_id_list: if system_id in delete_system_permissions: permission_string = 'Grant,View,Edit,Delete,ManageSession,AgentAuth,RequestZoneRole,AddAccount,UnlockAccount' else: if not explicit_missing_delete_permission: continue permission_string = 'Grant,View,Edit,ManageSession,AgentAuth,RequestZoneRole,AddAccount,UnlockAccount' result, success = ResourceManager.assign_system_permissions(core_session, permission_string, results_role['Name'], results_role['ID'], "Role", system_id) assert success, "Did not set system permissions " + result job_id, result = ResourceManager.del_multiple_systems(requester_session, batch.keys()) result = ResourceManager.get_job_state(core_session, job_id) assert result == "Succeeded", "Job did not execute" remaining_accounts = set(ResourceManager.get_multi_added_account_ids(core_session, created_system_id_list)) remaining_systems = set(ResourceManager.get_multi_added_system_ids(core_session, created_system_id_list).values()) assert remaining_accounts == expected_preserved_accounts, "Remaining accounts did not match expectation" assert remaining_systems == expected_preserved_systems, "Remaining systems did not match expectation"
def test_delete_systems_respects_skip_parameter(core_session, desktop_application_factory, list_of_created_systems, service_factory, core_ui): session = core_session factory = desktop_application_factory batch1 = ResourceManager.add_multiple_systems_with_accounts( session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts( session, 1, 2, list_of_created_systems) batch3 = ResourceManager.add_multiple_systems_with_accounts( session, 4, 6, list_of_created_systems) batch4 = ResourceManager.add_multiple_systems_with_accounts( session, 1, 8, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch1, batch2, batch3, batch4]) # these should get deleted systems_without_apps_and_services_ids, accounts_without_apps_and_services_ids = DataManipulation.aggregate_lists_in_dict_values( [batch1]) # these should not systems_with_apps_and_services_ids, accounts_with_apps_and_services_ids = DataManipulation.aggregate_lists_in_dict_values( [batch2, batch3]) # these should not keep_system_ids, keep_account_ids = DataManipulation.aggregate_lists_in_dict_values( [batch4]) delete_system_ids = systems_without_apps_and_services_ids.union( systems_with_apps_and_services_ids) system_ids_that_should_stay = keep_system_ids.union( systems_with_apps_and_services_ids) account_ids_that_should_stay = keep_account_ids.union( accounts_with_apps_and_services_ids) desktop_apps = [ 'SQL Server Management Studio', 'TOAD for Oracle', 'VMware vSphere Client' ] template_ids = list( map(lambda app_name: factory.get_template_id_from_name(app_name), desktop_apps)) resource_user = core_session.get_current_session_user_info().json( )['Result'] application_user = factory.session.get_current_session_user_info().json( )['Result'] for system_id in systems_with_apps_and_services_ids: # give 3 desktop apps per system ResourceManager.assign_system_permissions(core_session, ('View'), application_user['Name'], application_user['Id'], 'User', system_id) for template_id in template_ids: app_id = factory.add_desktop_app(template_id) factory.give_user_permissions(app_id, resource_user['Name'], resource_user['Id']) factory.assign_system(app_id, system_id) service_name = template_id + '_' + guid() service_factory.add_service( system_id, guid(), service_name, f'Service for {template_id} {service_name}') created_service_ids = service_factory.get_all_service_ids() created_desktop_app_ids = factory.get_all_app_ids() assert len( created_service_ids ) == len(systems_with_apps_and_services_ids) * len( template_ids), f'Failed to create all services. {created_service_ids}' assert len(created_desktop_app_ids) == len( systems_with_apps_and_services_ids) * len( template_ids ), f'Failed to create all desktop apps. {created_desktop_app_ids}' logger.info(f'Created apps {created_desktop_app_ids}') logger.info(f'Created services {created_service_ids}') secret_name = "TestSecret-" + str( ResourceManager.time_mark_in_hours()) + "-" + guid() # Send the system ids that both have and do not have apps and services so we can test that only the ones w/o apps and services are deleted. job_id, success = ResourceManager.del_multiple_systems( core_session, delete_system_ids, True, secret_name, skip_if_has_apps_or_services=True) job_report = JobManager.get_job_report(core_session, job_id) assert set( ResourceManager.get_multi_added_system_ids(core_session, all_systems).values() ) == system_ids_that_should_stay, f"Set of expected remaining systems did not match search. Job results {job_report}" assert set( ResourceManager.get_multi_added_account_ids(core_session, all_systems) ) == account_ids_that_should_stay, "Set of expected remaining accounts did not match search" remaining_apps = get_desktop_apps(core_session, created_desktop_app_ids) assert len(remaining_apps) == len( created_desktop_app_ids ), f'Some desktop apps were deleted that should not have been.' logger.debug(f'Checking on services {created_service_ids}') remaining_services = RedrockController.get_rows_matching_ids( core_session, 'Subscriptions', created_service_ids) assert len(remaining_services) == len( created_service_ids ), f'Some services were deleted that should not have been.'