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_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_delete_generates_secret_with_garbage_in_list(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems, secret_cleaner, core_tenant): 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, 1, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2]) secret_name = "TestSecret-" + str(ResourceManager.time_mark_in_hours()) + "-" + guid() clean_delete_system_ids = list(all_systems) delete_system_ids = ["foo", "", clean_delete_system_ids[2]] + clean_delete_system_ids + ["!@#$%^&*()", "1", "?", "Jason Alexander", "bar"] ResourceManager.del_multiple_systems(core_session, delete_system_ids, savepasswords=True, secretname=secret_name) 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, "No secret was created" secret_cleaner.append(secret_id) user_name = core_tenant['admin_user'] user_id = UserManager.get_user_id(core_session, user_name) result, success = set_users_effective_permissions(core_session, user_name, "View,Edit,Retrieve", user_id, secret_id) assert success, f"Did not set secret permission successfully with message {result}" secret_file_contents = get_file_secret_contents(core_session, secret_id) assert secret_file_contents.count("\n") == 1 + len( all_accounts), f"Secret file contained the wrong number of lines {secret_file_contents}" assert secret_file_contents.count("bsd_tst_usr_") == len( all_accounts), f"Secret file contained the wrong number of accounts {secret_file_contents}" assert secret_file_contents.count("thisIsaPAsSwO0rd") == len( all_accounts), f"Secret file contained the wrong number of passwords {secret_file_contents}" for server_id in all_systems: assert server_id in secret_file_contents, f"Server ID absent from secret file {secret_file_contents}" for account_id in all_accounts: assert account_id in secret_file_contents, f"Account ID absent from secret file {secret_file_contents}"
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_system_delete_does_not_generate_secret_when_told_not_to(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 2, 7, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 5, 3, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2]) job_id, success = ResourceManager.del_multiple_systems(core_session, all_systems, False, "") assert len(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == 0, "Remaining added systems should be zero" report_contents = JobManager.get_job_report(core_session, job_id) assert report_contents['report'].find( 'No password secret created') > -1, f'A secret was created even though it should not have been.'
def test_ui_check_bulk_delete_account_scheduled(core_session, core_admin_ui, list_of_created_systems): """ Test case: C3088 :param core_session: Returns API session :param core_admin_ui: Centrify admin Ui session :param list_of_created_systems: creating a empty list of created systems. """ account_name_prefix = f'account_test{guid()}' # adding multiple systems with accounts result = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 2, list_of_created_systems, user_prefix=account_name_prefix) # arranging the results in the lists all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [result]) ui = core_admin_ui ui.navigate('Resources', 'Accounts') account_names = [] for account in all_accounts: # getting the account information query_result, query_success = ResourceManager.get_account_information( core_session, account) account_names.append(query_result['VaultAccount']['Row']['User']) ui.search(account_name_prefix) ui.action('Delete accounts', 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.expect( Div("A delete operation has been scheduled. You will receive an e-mail when the operation has been completed." ), "Expecting a info popup for delete schedule") logger.info("Popup with delete operation has been scheduled appeared") ui.button('Close') result, success = ResourceManager.del_multiple_systems( core_session, all_systems) assert success is True, 'Delete systems job failed when expected success' logger.info(f"Delete systems job executed successfully {result}")
def test_ui_check_bulk_delete_account_caution(core_session, core_admin_ui, list_of_created_systems): """ Test case: C3086 :param core_session: Returns API session :param core_admin_ui: Centrify admin Ui session :param list_of_created_systems: creating a empty list of created systems. """ account_name_prefix = f'account_test{guid()}' # adding multiple systems with accounts result = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 2, list_of_created_systems, user_prefix=account_name_prefix) # arranging the results in the lists all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [result]) ui = core_admin_ui ui.navigate('Resources', 'Accounts') account_names = [] for account in all_accounts: # getting the account information query_result, query_success = ResourceManager.get_account_information( core_session, account) account_names.append(query_result['VaultAccount']['Row']['User']) ui.search(account_name_prefix) ui.action('Delete accounts', account_names) ui.switch_context(Modal('Bulk Account Delete')) ui.expect(Label("Save password to secret"), "Expected to see the label of save the password") ui.expect( Div("Deleting an account means we will no longer know the password." " Saving deleted account passwords to a secret is recommended until you are sure they are " "no longer needed."), "Expected to see the Caution message.") result, success = ResourceManager.del_multiple_systems( core_session, all_systems) assert success is True, f'Delete systems job failed when expected success' logger.info(f"Delete systems job executed successfully {result}") result_acc, success_acc = ResourceManager.del_multiple_accounts( core_session, all_accounts) assert success_acc, f"Api did not complete successfully for bulk account delete MSG:{result_acc}"
def test_ui_check_bulk_delete_account_confirm(core_session, core_admin_ui, list_of_created_systems): """ Test case: C3087 :param core_session: Returns API session :param core_admin_ui: Centrify admin Ui session :param list_of_created_systems: creating a empty list of created systems. """ account_name_prefix = f'account_test{guid()}' # adding multiple systems with accounts result = ResourceManager.add_multiple_systems_with_accounts( core_session, 1, 2, list_of_created_systems, user_prefix=account_name_prefix) # arranging the results in the lists all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [result]) ui = core_admin_ui ui.navigate('Resources', 'Accounts') account_names = [] for account in all_accounts: # getting the account information query_result, query_success = ResourceManager.get_account_information( core_session, account) account_names.append(query_result['VaultAccount']['Row']['User']) ui.search(account_name_prefix) ui.action('Delete accounts', account_names) ui.switch_context(Modal('Bulk Account Delete')) ui.uncheck("SaveSecret") ui.button('Delete') ui.switch_context(ConfirmModal()) ui.expect( Div("You are about to delete accounts which contain passwords or SSH Keys. This cannot be undone. Are " "you sure you want to continue?"), "Expecting a confirm delete account popup") logger.info("Confirm delete accounts popup appeared.") ui.button('Yes') result, success = ResourceManager.del_multiple_systems( core_session, all_systems) assert success is True, 'Delete systems job failed when expected success' logger.info(f"Delete systems job executed successfully {result}")
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_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_ui_check_job_details_page(core_session, core_admin_ui, list_of_created_systems): """ Test case: C1674 :param core_session: Returns API session :param core_admin_ui: Centrify admin Ui session :param list_of_created_systems: returns the empty systems list. """ account_name_prefix = f'account_test{guid()}' # adding multiple systems with accounts result = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 1, list_of_created_systems, user_prefix=account_name_prefix) # arranging the results in the lists all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([result]) # Deleting systems for creating bulk delete scheduled report result_acc, success_acc = ResourceManager.del_multiple_accounts(core_session, all_accounts) assert success_acc, f"Api did not complete successfully for bulk account delete MSG:{result_acc}" # Deleting accounts for creating bulk delete scheduled report result, success = ResourceManager.del_multiple_systems(core_session, all_systems) assert success, f'Delete systems job failed when expected success' logger.info(f"Delete systems job executed successfully {result}") # Going to password storage page and click on migration job status link. ui = core_admin_ui ui.navigate("Settings", "Resources", "Password Storage", check_rendered_tab=False) ui.expect(Anchor("View Migration Job Status and Reports "), "Clicking migration job status").try_click( Span(text="Type")) ui.switch_to_newest_tab() ui._waitUntilSettled() ui.click_row(GridRowByGuid(result)) ui.expect(Span("Details"), "Clicking migration job status").try_click(Div("Job Details")) ui.expect_value(Div(result), value=None, expected_value=result, wrong_value_message="expected id value is not matched in the report", text=True) logger.info("Id value in the Job description appeared correctly")
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.'
def test_ui_check_job_details_page_values(core_session, core_admin_ui, list_of_created_systems): """ Test case: C1670 :param core_session: Returns API session :param core_admin_ui: Centrify admin Ui session :param list_of_created_systems: returns the empty systems list. """ account_name_prefix = f'account_test{guid()}' # adding multiple systems with accounts result = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 1, list_of_created_systems, user_prefix=account_name_prefix) # arranging the results in the lists all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([result]) # Deleting systems for creating bulk delete scheduled report result_acc, success_acc = ResourceManager.del_multiple_accounts(core_session, all_accounts) assert success_acc, f"Api did not complete successfully for bulk account delete MSG:{result_acc}" # Deleting accounts for creating bulk delete scheduled report result_sys, success = ResourceManager.del_multiple_systems(core_session, all_systems) assert success, f'Delete systems job failed when expected success' logger.info(f"Delete systems job executed successfully {result_sys}") # Going to password storage page and click on migration job status link. ui = core_admin_ui ui.navigate("Settings", "Resources", "Password Storage", check_rendered_tab=False) ui.expect(Anchor("View Migration Job Status and Reports "), "Clicking migration job status").try_click() ui.switch_to_newest_tab() ui._waitUntilSettled() ui.click_row(GridRowByGuid(result_sys)) ui.expect(Span("Details"), "Clicking migration job status").try_click(Div("Job Details")) # Checking the Job Id of system. ui.expect_value(Div(result_sys), value=None, expected_value=result_sys, wrong_value_message="expected id value is not matched in the report", text=True) logger.info("Id value in the Job description appeared correctly") # List of the Expected text from Job Details list_of_text = ['Job Information', 'Type', 'ID', 'Description', 'Submitted', 'Started', 'Completed', 'Retry Count', 'Items Synced', 'Items Failed'] # Getting the Job history job_history = JobManager.get_job_history(core_session) # Validating the Job history expected title appeared correctly on UI. for label in list_of_text: ui.expect_value(Label(label), value=None, expected_value=label, wrong_value_message=f"expected {label} value is not matched in the report", text=True) logger.info(f"expected {label} value is matched in the report") delete_scheduled_job = [] check_text = [] if job_history[1]['JobName'] == 'BulkSystemDelete': account_bulk_delete_schedule_id = job_history[0]['ID'] System_bulk_delete_schedule_id = job_history[1]['ID'] System_jobdescription = job_history[1]['JobDescription'] System_jobName = job_history[1]['JobName'] check_text.append(System_bulk_delete_schedule_id) check_text.append(System_jobdescription) check_text.append(System_jobName) check_text.append(account_bulk_delete_schedule_id) delete_scheduled_job.append(System_bulk_delete_schedule_id) ui.switch_context(RenderedTab("Job Details")) # Validating the Job history results from API appeared correctly on UI. for text in check_text: ui.expect_value(Div(text), value=None, expected_value=text, wrong_value_message=f"expected {text} value is not matched in the report", text=True) logger.info(f"expected {text} value is matched in the report") # Deleting the Scheduled jobs of Bulk System's and Account's for delete in delete_scheduled_job: result_account_delete, success, response = Discovery.delete_job_history(core_session, delete) assert success, f"Failed to delete Job history profile {result_account_delete}" logger.info(f"delete Job history profile with id {delete} successful {success}")