def test_have_delete_permission_on_parent_should_be_able_to_delete_child_members( core_session, users_and_roles, create_secret_inside_folder, pas_general_secrets): """ C3000: Have delete permission on parent, should be able to delete child members :param core_session: Authenticated Centrify Session. :param users_and_roles: Fixture to create New user with PAS Power Rights :param create_secret_inside_folder: Fixture to create text type secret inside folder & yields folder & secret details. :param pas_general_secrets: Fixture to read secret data from yaml file. """ folder_id_list, folder_name, secret_id_list = create_secret_inside_folder pas_power_user = users_and_roles.get_user( 'Privileged Access Service Power User') user_name = pas_power_user.get_login_name() user_id = pas_power_user.get_id() # Getting new session for User A pas_power_user_session = users_and_roles.get_session_for_user( 'Privileged Access Service Power User') assert pas_power_user_session.auth_details is not None, 'Failed to Login with PAS Power User' logger.info( f'User with PAS Power User Rights login successfully :user_Name: {user_name}' f' & Password: {pas_power_user.get_password()} ') # Api to give user permissions to folder user_permissions_result = give_user_permissions_to_folder( core_session, user_name, user_id, folder_id_list[0], 'View,Grant') assert user_permissions_result, f'Not Able to set user permissions to folder{user_permissions_result}' logger.info(f'User Permissions to folder: {user_permissions_result}') # Api to give member permissions(Delete) to folder member_perm_result, member_perm_success = set_member_permissions_to_folder( core_session, user_name, 'View,Grant,Delete,Retrieve', user_id, folder_id_list[0]) assert member_perm_success, f'Not Able to set member permissions to Folder{member_perm_result["Result"]}' logger.info(f'Member permissions to folder:{member_perm_result}') # Api to delete the child secret del_success, del_result = del_secret(pas_power_user_session, secret_id_list[0]) assert del_success, f'Not Able to delete the child secret: {del_result}' for secret_id in secret_id_list: secret_id_list.remove(secret_id) logger.info(f'Able to delete the child secret:{del_result}')
def test_delete_permission_on_secret_but_not_on_folder( core_session, create_secret_inside_folder, users_and_roles): """ test method to Delete permission on secret but not on folder :param core_session: Authenticated Centrify Session. :param create_secret_inside_folder: Fixture to create text type secret inside folder & yields folder id , folder name & secret id :param users_and_roles: Fixture to create New user with PAS Power Rights """ folder_id_list, folder_name, secret_id_list = create_secret_inside_folder pas_power_user = users_and_roles.get_user( 'Privileged Access Service Power User') user_name = pas_power_user.get_login_name() user_id = pas_power_user.get_id() pas_power_user_session = users_and_roles.get_session_for_user( 'Privileged Access Service Power User') assert pas_power_user_session.auth_details is not None, 'Failed to Login with PAS Power User' logger.info( f'User with PAS Power User Rights login successfully :user_Name: {user_name}' f' & Password: {pas_power_user.get_password()} ') # Api to give user permissions to folder user_permissions_result = give_user_permissions_to_folder( core_session, user_name, user_id, folder_id_list[0], 'View') assert user_permissions_result, f'Not Able to set user permissions to folder{user_permissions_result}' logger.info(f'User Permissions to folder: {user_permissions_result}') # Api to set DELETE permissions to secret text_type_secret_result, text_type_secret_success = set_users_effective_permissions( core_session, user_name, 'View,Delete,Retrieve', user_id, secret_id_list[0]) assert text_type_secret_success, f'Failed to Set Member permissions to secret:{text_type_secret_result}' logger.info( f'Setting Member permissions for secret: {text_type_secret_success}') # Api to delete the child secret del_success, del_result = del_secret(pas_power_user_session, secret_id_list[0]) assert del_success, f'Not Able to delete the child secret: {del_result}' secret_id_list.remove(secret_id_list[0]) logger.info(f'Able to delete the child secret: {del_result}')
def test_user_need_retrieve_secret_permission_to_delete( core_session, pas_general_secrets, cleanup_secrets_and_folders, users_and_roles): """ C283961: User needs Retrieve Secret permission to retrieve secret contents :param core_session: Authenticated Centrify Session :param users_and_roles: Fixture to create random user with pas user rights :param cleanup_secrets_and_folders: Fixture to cleanup the secrets & folders created. :param pas_general_secrets: Fixture to read secrets data from yaml file """ folder_params = pas_general_secrets folder_prefix = guid() folders_list = cleanup_secrets_and_folders[1] secret_folder_success, secret_folder_parameters, secret_folder_id = create_folder( core_session, folder_params['name'] + folder_prefix, folder_params['description']) assert secret_folder_success, f'Failed to create a folder{secret_folder_id} ' logger.info(f' Folder created successfully: {secret_folder_success} & details are {secret_folder_parameters}') folders_list.append(secret_folder_id) added_text_secret_success, added_text_secret_result = create_text_secret_within_folder( core_session, folder_prefix + folder_params['secret_name'], folder_params['secret_text'], folder_params['secret_description'], secret_folder_id) logger.info(f'Secret Created successfully: {added_text_secret_success}') assert added_text_secret_success, f'Unable to create secret {added_text_secret_result}' # API to get new session for User A pas_power_user_session = users_and_roles.get_session_for_user('Privileged Access Service Power User') assert pas_power_user_session.auth_details, 'Failed to Login with PAS User' user_name = pas_power_user_session.auth_details['User'] user_id = pas_power_user_session.auth_details['UserId'] logger.info(f'{pas_power_user_session.auth_details}') logger.info(f'User with PAS User Rights login successfully: user_Name:{user_name}') # Api to give user permissions to folder user_permissions = give_user_permissions_to_folder(core_session, user_name, user_id, secret_folder_id, 'View') assert user_permissions['success'], \ f'Not Able to set user permissions to folder{user_permissions["Result"]}' logger.info(f'User Permissions to folder: {user_permissions}') # Api to disable member permissions Retrieve in folder member_perm_result, member_perm_success = set_member_permissions_to_folder(core_session, user_name, 'View,Delete', user_id, secret_folder_id) assert member_perm_success, f'Not Able to set member permissions to Folder: {member_perm_result}' logger.info(f'Member permissions to folder:{member_perm_result}') # Deleting secret without Retrieve permission in folder. retrieve_success, retrieve_result, retrieve_message = retrieve_secret(pas_power_user_session, added_text_secret_result) assert retrieve_success is False, f'Users {user_name} have permission to retrieve the secret: {retrieve_result}' logger.info(f'No longer to delete as you have "Retrieve" ' f'permission which is required prior to delete:{retrieve_message}') # Api to give member permissions to folder member_perm_result, member_perm_success = set_member_permissions_to_folder(core_session, user_name, 'View,Delete,Retrieve', user_id, secret_folder_id) assert member_perm_success, f'Not Able to set member permissions to Folder: {member_perm_result}' logger.info(f'Member permissions to folder:{member_perm_result}') del_success, del_result = del_secret(pas_power_user_session, added_text_secret_result) assert del_success, f'Not Able to delete the child secret: {del_result}' logger.info(f'Secret is Successfully deleted:{del_result}')
def test_delete_mfa_policy_on_secret(core_session, pas_general_secrets, clean_up_policy, users_and_roles): """ C283962: MFA policy on Secret, verify challenged :param core_session: Authenticated Centrify session :param pas_general_secrets: Fixture to read secrets data from yaml file :param clean_up_policy: Fixture to cleanup the policy created :param users_and_roles: Fixture to create new user with restricted rights """ secrets_params = pas_general_secrets suffix = guid() # Create a folder A secret_folder_success, secret_folder_parameters, secret_folder_id = create_folder( core_session, secrets_params['mfa_folder_name'] + suffix, secrets_params['description']) assert secret_folder_success, f'Failed to create a folder {secret_folder_id}' logger.info(f' Folder created successfully: {secret_folder_success} ') secret_folder_parameters['ID'] = secret_folder_id # Create a secret under A folder added_secret_success, added_secret_id = create_text_secret_within_folder( core_session, secrets_params['mfa_secret_name'] + suffix, secrets_params['secret_text'], secrets_params['secret_description'], secret_folder_id) assert added_secret_success, f"Added Secret Failed {added_secret_id}" logger.info(f'Added secrets info {added_secret_success, added_secret_id}') # Getting details of the secret found_secret = get_secret(core_session, added_secret_id) assert found_secret['success'], \ f'Failed to get the details of the secret , API response result:{found_secret["Message"]}' logger.info(f'Getting details of the secret: {found_secret}') secret_name = found_secret['Result']['SecretName'] challenges = ["UP", ""] # Creating new policy policy_result = PolicyManager.create_new_auth_profile( core_session, secrets_params['policy_name'] + suffix, challenges, 0, 0) assert policy_result, f'Failed to create policy, API response result:{policy_result}' logger.info(f' Creating new policy:{policy_result}') clean_up_policy.append(policy_result) # Applying MFA on Secret result = update_secret( core_session, added_secret_id, secret_name, description=secrets_params['mfa_secret_description'], policy_id=policy_result) assert result[ 'success'], f' Failed to apply MFA on the secret, API response result:{result["Message"]} ' logger.info(f'MFA Applied on the secret: {result}') # Getting new session for User pas_power_user_session = users_and_roles.get_session_for_user( 'Privileged Access Service Power User') assert pas_power_user_session.auth_details, 'Failed to Login with PAS Power User' user_name = pas_power_user_session.auth_details['User'] user_id = pas_power_user_session.auth_details['UserId'] logger.info( f'User with PAS Power User Rights login successfully: user_Name: {user_name}' ) # Api to give user permissions to folder user_permissions_result = give_user_permissions_to_folder( core_session, user_name, user_id, secret_folder_id, 'Grant,View,Delete') assert user_permissions_result, f'Failed to set user permissions to folder{user_permissions_result}' logger.info(f'User Permissions to folder: {user_permissions_result}') # Api to set DELETE permissions to folder member_perm_result, member_perm_success = set_member_permissions_to_folder( core_session, user_name, 'Grant,View,Delete,Retrieve', user_id, secret_folder_id) assert member_perm_success, f'Failed to set member permissions to Folder{member_perm_result["Result"]}' logger.info(f'Member permissions to folder:{member_perm_result}') # Delete secret with Mfa Authentication del_success, del_result = del_secret(pas_power_user_session, added_secret_id) # StartChallenge MFA Authentication session, mechanism = pas_power_user_session.start_mfa_authentication( user_name, del_result['ChallengeId']) # AdvanceAuthentication MFA to Password result = pas_power_user_session.advance_authentication( answer=pas_power_user_session.user.user_input.password, session_id=session, mechanism_id=mechanism) assert result, "Password Authentication Failed" logger.info(f'Advance authentication: {result}') # After Authentication of MFA delete the secret under folder del_secret_success, del_secret_result = del_secret_mfa( pas_power_user_session, added_secret_id, ChallengeStateId=del_result['ChallengeId']) assert del_secret_success, f'User: {user_name} failed to delete secret from this folder: {secret_folder_id}' logger.info( f'User: {user_name} deleted secret: ' f'{added_secret_id} successfully from this folder: {secret_folder_id}') # Delete folder del_folder_res = del_folder(core_session, secret_folder_id) assert del_folder_res, f'User: {user_name} failed to delete folder: {secret_folder_id}' logger.info( f'User: {user_name} successfully deleted folder: {secret_folder_id}')
def test_delete_secret_with_mfa_on_parent(core_session, pas_general_secrets, clean_up_policy, users_and_roles, create_secret_inside_folder, cleanup_secrets_and_folders): """ C283963: MFA policy on Parent folder, verify challenged :param core_session: Authenticated Centrify Session :param pas_general_secrets: fixture to read secrets related data from yaml file :param clean_up_policy: Fixture to cleanup the policy created :param users_and_roles: Fixture to create new user with restricted rights :param create_secret_inside_folder: Fixture to create secrets inside folder & yields secrets & folders data :param cleanup_secrets_and_folders: Fixture to cleanup the secrets & folders created """ secrets_params = pas_general_secrets suffix = guid() folder_id_list, folder_name, secret_id_list = create_secret_inside_folder secrets_list = cleanup_secrets_and_folders[0] challenges = ["UP", ""] # Creating new policy policy_result = PolicyManager.create_new_auth_profile( core_session, secrets_params['policy_name'] + suffix, challenges, 0, 0) assert policy_result, f'Failed to create policy, API response result:{policy_result}' logger.info(f' Creating new policy:{policy_result}') clean_up_policy.append(policy_result) # Updating the Folder(Applying MFA) result = update_folder( core_session, folder_id_list[0], folder_name, folder_name, description=secrets_params['mfa_folder_description'], policy_id=policy_result) assert result[ 'success'], f' Failed to apply MFA on folder, API response result: {result["Message"]} ' logger.info(f'MFA Applied on Folder: {result}') # Getting new session for User A pas_power_user_session = users_and_roles.get_session_for_user( 'Privileged Access Service Power User') assert pas_power_user_session.auth_details, 'Failed to Login with PAS Power User' user_name = pas_power_user_session.auth_details['User'] user_id = pas_power_user_session.auth_details['UserId'] logger.info( f'User with PAS Power User Rights login successfully: user_Name: {user_name}' ) # Api to give user permissions to folder user_permissions_result = give_user_permissions_to_folder( core_session, user_name, user_id, folder_id_list[0], 'View') assert user_permissions_result, f'Failed to set user permissions to folder{user_permissions_result}' logger.info(f'User Permissions to folder: {user_permissions_result}') # Api to set DELETE permissions folder member_perm_result, member_perm_success = set_member_permissions_to_folder( core_session, user_name, 'Grant,View,Delete,Retrieve', user_id, folder_id_list[0]) assert member_perm_success, f'Failed to set member permissions to Folder{member_perm_result["Result"]}' logger.info(f'Member permissions to folder:{member_perm_result}') # Delete secret with Mfa Authentication del_success, del_result = del_secret(pas_power_user_session, secret_id_list[0]) # StartChallenge MFA Authentication session, mechanism = pas_power_user_session.start_mfa_authentication( user_name, del_result['ChallengeId']) # AdvanceAuthentication MFA to Password result = pas_power_user_session.advance_authentication( answer=pas_power_user_session.user.user_input.password, session_id=session, mechanism_id=mechanism) assert result, "Password Authentication Failed" # After Authentication of MFA delete the secret under folder del_secret_success, del_secret_result = del_secret_mfa( pas_power_user_session, secret_id_list[0], ChallengeStateId=del_result['ChallengeId']) assert del_secret_success, f'Failed to delete secret with MFA {del_secret_result} with User: {user_name}' logger.info( f'Successfully deleted secret with MFA {del_secret_result} for User: {user_name} ' ) secrets_list.remove(secret_id_list[0]) # Updating the Folder(Removing MFA) result = update_folder( core_session, folder_id_list[0], folder_name, folder_name, description=secrets_params['mfa_folder_description']) assert result[ 'success'], f'Failed to remove MFA on folder, API response result: {result["Message"]} ' logger.info(f'Successfully Removed MFA on Folder: {result}')
def test_needs_retrieve_permission_to_secret(core_session, users_and_roles, create_secret_inside_folder, pas_general_secrets): """ C283961: User needs Retrieve Secret permission to retrieve and delete secret :param core_session: Authenticated Centrify Session. :param users_and_roles: Fixture to create New user with PAS Power Rights :param create_secret_inside_folder: Fixture to create secret inside foledr & yield secrets & folders details. :param pas_general_secrets: Fixture to read secret data from yaml file. """ folder_id_list, folder_name, secret_id = create_secret_inside_folder params = pas_general_secrets suffix = guid() # Getting new session for User A pas_power_user_session = users_and_roles.get_session_for_user( 'Privileged Access Service Power User') assert pas_power_user_session.auth_details, 'Failed to Login with PAS Power User' user_name = pas_power_user_session.auth_details['User'] user_id = pas_power_user_session.auth_details['UserId'] logger.info( f'User with PAS Power User Rights login successfully: user_Name:{user_name}' ) # Create text type secret within folder added_text_secret_success, added_text_secret_result = create_text_secret_within_folder( core_session, params['secret_name'] + suffix, params['secret_text'], params['secret_description'], folder_id_list[0]) assert added_text_secret_success, f'Failed to create secret {added_text_secret_result}' logger.info(f'Secret Created successfully: {added_text_secret_success}') # Setting user permissions to folder user_permissions_result = give_user_permissions_to_folder( core_session, user_name, user_id, folder_id_list[0], 'View') assert user_permissions_result, f'Failed to set user permissions to folder:{user_permissions_result}' logger.info(f'User Permissions to folder: {user_permissions_result}') # Setting member permissions(Delete, Retrieve) to folder member_perm_result, member_perm_success = set_member_permissions_to_folder( core_session, user_name, 'View,Grant,Delete,Retrieve', user_id, folder_id_list[0]) assert member_perm_success, f'Failed to set member permissions to Folder:{member_perm_result["Result"]}' logger.info(f'Member permissions to folder:{member_perm_result}') # Deleting child secret should work del_success, del_result = del_secret(pas_power_user_session, added_text_secret_result) assert del_success, f'Failed to delete child secret: {del_result}' logger.info( f'Successfully deleted child secret: {del_success}{del_result}') # Setting member permissions(Delete) to folder member_perm_result, member_perm_success = set_member_permissions_to_folder( core_session, user_name, 'View,Grant,Delete', user_id, folder_id_list[0]) assert member_perm_success, f'Failed to set member permissions to Folder:{member_perm_result["Result"]}' logger.info(f'Member permissions to folder:{member_perm_result}') # Deleting child secret should work(without Retrieve) del_success, del_result = del_secret(pas_power_user_session, secret_id[0]) assert del_success, f'Failed to delete child secret: {del_result}' logger.info(f'Successfully deleted child secret: {del_result}') secret_id.remove(secret_id[0])
def test_union_of_all_its_permissions(core_session, pas_general_secrets, cleanup_secrets_and_folders, users_and_roles): """ C3056: test method Union of all its permissions 1)create multilevel folder /alpha/beta/charlie/delta 2) Login as Admin, set folder permissions "View" for alpha,"Edit" for beta, "Delete" for charlie,"Add" for delta 3) Login as pas user 4) verify sub folder permissions will have a union of all parent folders :param core_session: Authenticated Centrify session :param pas_general_secrets: Fixture to read secrets related data from yaml file :param cleanup_secrets_and_folders: Fixture to cleanup the secrets & folders created :param users_and_roles: Fixture to create random user with PAS User Rights """ params = pas_general_secrets folder_prefix = guid() folders_list = cleanup_secrets_and_folders[1] secrets_list = cleanup_secrets_and_folders[0] # creating multilevel folder /alpha/beta/charlie/delta child_folder_success, child_folder_parameters, child_folder_id = create_folder( core_session, folder_prefix + params['multi_level_folder_name'], params['description']) assert child_folder_success, f'Failed to create multilevel folder, API response result: {child_folder_id}' logger.info(f'Multilevel Folder created successfully: {child_folder_success} & details are {child_folder_id}') # Getting details of Folder Charlie charlie_folder = get_folder(core_session, child_folder_id) assert charlie_folder['success'], \ f'Failed to retrieve charlie folder details, API response result:{charlie_folder["Message"]}' logger.info(f'charlie folder details:{charlie_folder}') charlie_id = charlie_folder['Result']['Results'][0]['Row']['Parent'] # Getting details of parent folder parent_path = charlie_folder['Result']['Results'][0]['Row']['ParentPath'] parent_folder_name = parent_path.split('\\') parent_folder_sliced = parent_folder_name[0] # Getting id of parent folder parent_folder = get_folder(core_session, parent_folder_sliced) assert parent_folder['success'], \ f'Failed to retrieve parent folder details, API response result:{parent_folder["Message"]}' logger.info(f'Parent folder details:{parent_folder}') parent_folder_id = parent_folder['Result']['Results'][0]['Row']['ID'] # Getting details of Folder alpha alpha_folder = get_secrets_and_folders_in_folders(core_session, parent_folder_id) assert alpha_folder['success'], f'Failed to retrieve alpha folder id, API response result: {alpha_folder["Result"]}' logger.info(f'Details of Alpha Folder Retrieved:{alpha_folder}') alpha_folder_id = alpha_folder["Result"]["Results"][0]["Entities"][0]["Key"] # Getting details of Folder beta folder_beta = get_secrets_and_folders_in_folders(core_session, alpha_folder_id) assert folder_beta['success'], f'Failed to retrieve beta folder id, API response result: {folder_beta["Result"]}' logger.info(f'Details of Beta Folder Retrieved:{folder_beta}') folder_beta_id = folder_beta["Result"]["Results"][0]["Entities"][0]["Key"] # API to get new session for User A pas_power_user_session = users_and_roles.get_session_for_user('Privileged Access Service User') assert pas_power_user_session.auth_details, 'Failed to Login with PAS User' user_name = pas_power_user_session.auth_details['User'] user_id = pas_power_user_session.auth_details['UserId'] logger.info(f'User with PAS User Rights login successfully: user_Name:{user_name}') # Adding secrets inside child folder added_secret_success, added_secret_id = create_text_secret_within_folder(core_session, params['mfa_secret_name'] + folder_prefix, params['secret_text'], params['secret_description'], child_folder_id) assert added_secret_success, f"Added Secret Failed, API response result {added_secret_id}" logger.info(f'Added secrets info: {added_secret_id}') # Api to give user permissions to folder alpha user_permissions_alpha = give_user_permissions_to_folder(core_session, user_name, user_id, alpha_folder_id, 'View') assert user_permissions_alpha['success'], \ f'Not Able to set user permissions to folder, API response result: {user_permissions_alpha["Result"]}' logger.info(f'User Permissions to folder: {user_permissions_alpha}') # Api to give user permissions to folder beta user_permissions_beta = give_user_permissions_to_folder(core_session, user_name, user_id, folder_beta_id, 'Edit') assert user_permissions_beta['success'], \ f'Not Able to set user permissions to folder, API response result: {user_permissions_beta["Result"]}' logger.info(f'User Permissions to folder: {user_permissions_beta}') # Api to give member permissions(View, Edit) to folder beta member_perm_result, member_perm_success = set_member_permissions_to_folder(core_session, user_name, 'View, Edit', user_id, folder_beta_id) assert member_perm_success,\ f'Not Able to set "View" member permissions to Folder, API response result: {member_perm_result}' logger.info(f'Member permissions to folder:{member_perm_result}') # Api to give member permissions(Delete, Retrieve) to folder member_perm_result, member_perm_success = set_member_permissions_to_folder(core_session, user_name, 'Delete,Retrieve', user_id, charlie_id) assert member_perm_success,\ f'Not Able to set "View" member permissions to Folder, API response result: {member_perm_result}' logger.info(f'Member permissions to folder:{member_perm_result}') # Updating the secret name & description result = update_secret(pas_power_user_session, added_secret_id, folder_prefix + params['mfa_secret_name_update'], description=params['mfa_secret_description']) assert result['success'], f'Not Able to update the secret, API response result: {result["Message"]} ' logger.info(f'Secret Updated Details: {result}') # Getting details of the Secret updated get_secret_details, get_secret_success, get_secret_created_date, get_secret_text = get_secret_contents( pas_power_user_session, added_secret_id) description_updated = get_secret_details['Description'] name_updated = get_secret_details['SecretName'] assert 'MFAOnSecretUpdate' in name_updated,\ f'Failed to update the name, API response result:{get_secret_success}' assert 'mfa_description' in description_updated,\ f'Failed to update the description, API response result:{get_secret_success}' logger.info(f'Details of the secret updated: {get_secret_details}') # Deleting newly created secrets del_success, del_result = del_secret(pas_power_user_session, added_secret_id) assert del_success, f'Failed to delete the secret with pas user, API response result: {del_result}' logger.info(f'Secret deleted successfully with pas user:{del_result}') folders_list.append(child_folder_id) folders_list.append(charlie_id) folders_list.append(folder_beta_id) folders_list.append(alpha_folder_id) folders_list.append(parent_folder_id) logger.info(f'Added Folders are deleted successfully: {folders_list}') logger.info(f'Added Secrets deleted successfully: {secrets_list}')