def test_get_all_posts_expected_data_with_non_default_values( self, user_context, mock_connection, mock_detection_list_user_client ): high_risk_employee_client = HighRiskEmployeeService( mock_connection, user_context, mock_detection_list_user_client ) for _ in high_risk_employee_client.get_all( filter_type="NEW_FILTER", sort_direction="DESC", sort_key="DISPLAY_NAME", page_size=200, ): break posted_data = mock_connection.post.call_args[1]["json"] assert mock_connection.post.call_count == 1 assert mock_connection.post.call_args[0][0] == "v2/highriskemployee/search" assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["filterType"] == "NEW_FILTER" and posted_data["pgNum"] == 1 and posted_data["pgSize"] == 200 and posted_data["srtKey"] == "DISPLAY_NAME" and posted_data["srtDirection"] == "DESC" )
def test_get_page_posts_data_to_expected_url( self, user_context, mock_connection, mock_detection_list_user_client ): high_risk_employee_client = HighRiskEmployeeService( mock_connection, user_context, mock_detection_list_user_client ) high_risk_employee_client.get_page( filter_type="NEW_FILTER", page_num=3, page_size=10, sort_direction="DESC", sort_key="DISPLAY_NAME", ) posted_data = mock_connection.post.call_args[1]["json"] assert mock_connection.post.call_count == 1 assert ( mock_connection.post.call_args[0][0] == "/svc/api/v2/highriskemployee/search" ) assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["filterType"] == "NEW_FILTER" and posted_data["pgNum"] == 3 and posted_data["pgSize"] == 10 and posted_data["srtKey"] == "DISPLAY_NAME" and posted_data["srtDirection"] == "DESC" )
def test_remove_posts_expected_data(self, user_context, mock_connection, mock_detection_list_user_client): high_risk_employee_client = HighRiskEmployeeService( mock_connection, user_context, mock_detection_list_user_client) high_risk_employee_client.remove("942897397520289999") posted_data = mock_connection.post.call_args[1]["json"] assert mock_connection.post.call_count == 1 assert mock_connection.post.call_args[0][ 0] == "v2/highriskemployee/remove" assert posted_data["tenantId"] == user_context.get_current_tenant_id() assert posted_data["userId"] == "942897397520289999"
def test_set_alerts_enabled_posts_expected_data_with_default_value( self, user_context, mock_connection, mock_detection_list_user_client): high_risk_employee_client = HighRiskEmployeeService( mock_connection, user_context, mock_detection_list_user_client) high_risk_employee_client.set_alerts_enabled() posted_data = mock_connection.post.call_args[1]["json"] assert mock_connection.post.call_count == 1 assert (mock_connection.post.call_args[0][0] == "v2/highriskemployee/setalertstate") assert (posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["alertsEnabled"] is True)
def test_remove_raises_error_when_user_id_does_not_exist( self, user_context, mock_post_not_found_session, mock_detection_list_user_client, ): high_risk_employee_client = HighRiskEmployeeService( mock_post_not_found_session, user_context, mock_detection_list_user_client) user_id = "942897397520289999" with pytest.raises(Py42NotFoundError) as err: high_risk_employee_client.remove(user_id) assert "User with ID '{}' is not currently on the high-risk-employee list.".format( user_id) in str(err.value)
def test_add_when_user_already_on_list_raises_user_already_added_error( self, mocker, mock_connection, user_context, mock_detection_list_user_client): def side_effect(url, json): if "add" in url: raise create_mock_error(Py42BadRequestError, mocker, "User already on list") mock_connection.post.side_effect = side_effect client = HighRiskEmployeeService(mock_connection, user_context, mock_detection_list_user_client) with pytest.raises(Py42UserAlreadyAddedError) as err: client.add("user_id") expected = "User with ID user_id is already on the high-risk-employee list." assert str(err.value) == expected
def _init_services(main_connection, main_auth): alert_rules_key = u"FedObserver-API_URL" alerts_key = u"AlertService-API_URL" file_events_key = u"FORENSIC_SEARCH-API_URL" preservation_data_key = u"PRESERVATION-DATA-SERVICE_API-URL" employee_case_mgmt_key = u"employeecasemanagement-API_URL" kv_prefix = u"simple-key-value-store" audit_logs_key = u"AUDIT-LOG_API-URL" kv_connection = Connection.from_microservice_prefix( main_connection, kv_prefix) kv_service = KeyValueStoreService(kv_connection) alert_rules_conn = Connection.from_microservice_key(kv_service, alert_rules_key, auth=main_auth) alerts_conn = Connection.from_microservice_key(kv_service, alerts_key, auth=main_auth) file_events_conn = Connection.from_microservice_key(kv_service, file_events_key, auth=main_auth) pds_conn = Connection.from_microservice_key(kv_service, preservation_data_key, auth=main_auth) ecm_conn = Connection.from_microservice_key(kv_service, employee_case_mgmt_key, auth=main_auth) audit_logs_conn = Connection.from_microservice_key(kv_service, audit_logs_key, auth=main_auth) user_svc = UserService(main_connection) administration_svc = AdministrationService(main_connection) file_event_svc = FileEventService(file_events_conn) user_ctx = UserContext(administration_svc) user_profile_svc = DetectionListUserService(ecm_conn, user_ctx, user_svc) services = Services( administration=administration_svc, archive=ArchiveService(main_connection), devices=DeviceService(main_connection), legalhold=LegalHoldService(main_connection), orgs=OrgService(main_connection), securitydata=SecurityDataService(main_connection), users=UserService(main_connection), alertrules=AlertRulesService(alert_rules_conn, user_ctx, user_profile_svc), alerts=AlertService(alerts_conn, user_ctx), fileevents=file_event_svc, savedsearch=SavedSearchService(file_events_conn, file_event_svc), preservationdata=PreservationDataService(pds_conn), departingemployee=DepartingEmployeeService(ecm_conn, user_ctx, user_profile_svc), highriskemployee=HighRiskEmployeeService(ecm_conn, user_ctx, user_profile_svc), userprofile=user_profile_svc, auditlogs=AuditLogsService(audit_logs_conn), ) return services, user_ctx
def test_add_posts_expected_data( self, user_context, mock_connection_post_success, mock_detection_list_user_client, ): high_risk_employee_client = HighRiskEmployeeService( mock_connection_post_success, user_context, mock_detection_list_user_client) high_risk_employee_client.add("942897397520289999") posted_data = mock_connection_post_success.post.call_args[1]["json"] assert mock_connection_post_success.post.call_count == 1 assert (mock_connection_post_success.post.call_args[0][0] == "v2/highriskemployee/add") assert (posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userId"] == "942897397520289999")
def test_get_all_posts_expected_data( self, user_context, mock_connection, mock_detection_list_user_client, ): high_risk_employee_client = HighRiskEmployeeService( mock_connection, user_context, mock_detection_list_user_client ) for _ in high_risk_employee_client.get_all(): break posted_data = mock_connection.post.call_args[1]["json"] assert mock_connection.post.call_count == 1 assert mock_connection.post.call_args[0][0] == "v2/highriskemployee/search" assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["filterType"] == "OPEN" and posted_data["pgNum"] == 1 and posted_data["pgSize"] == 100 and posted_data["srtKey"] is None and posted_data["srtDirection"] is None )
def _init_services(main_connection, main_auth): # services are imported within function to prevent circular imports when a service # imports anything from py42.sdk.queries from py42.services import Services from py42.services._keyvaluestore import KeyValueStoreService from py42.services.administration import AdministrationService from py42.services.alertrules import AlertRulesService from py42.services.alerts import AlertService from py42.services.archive import ArchiveService from py42.services.auditlogs import AuditLogsService from py42.services.cases import CasesService from py42.services.casesfileevents import CasesFileEventsService from py42.services.detectionlists.departing_employee import DepartingEmployeeService from py42.services.detectionlists.high_risk_employee import HighRiskEmployeeService from py42.services.detectionlists.user_profile import DetectionListUserService from py42.services.devices import DeviceService from py42.services.fileevent import FileEventService from py42.services.legalhold import LegalHoldService from py42.services.orgs import OrgService from py42.services.preservationdata import PreservationDataService from py42.services.savedsearch import SavedSearchService from py42.services.trustedactivities import TrustedActivitiesService from py42.services.users import UserService alert_rules_key = "FedObserver-API_URL" alerts_key = "AlertService-API_URL" file_events_key = "FORENSIC_SEARCH-API_URL" preservation_data_key = "PRESERVATION-DATA-SERVICE_API-URL" employee_case_mgmt_key = "employeecasemanagementV2-API_URL" kv_prefix = "simple-key-value-store" audit_logs_key = "AUDIT-LOG_API-URL" cases_key = "CASES_API-URL" trusted_activities_key = "TRUSTED-DOMAINS_API-URL" kv_connection = Connection.from_microservice_prefix( main_connection, kv_prefix) kv_service = KeyValueStoreService(kv_connection) alert_rules_conn = Connection.from_microservice_key(kv_service, alert_rules_key, auth=main_auth) alerts_conn = Connection.from_microservice_key(kv_service, alerts_key, auth=main_auth) file_events_conn = Connection.from_microservice_key(kv_service, file_events_key, auth=main_auth) pds_conn = Connection.from_microservice_key(kv_service, preservation_data_key, auth=main_auth) ecm_conn = Connection.from_microservice_key(kv_service, employee_case_mgmt_key, auth=main_auth) audit_logs_conn = Connection.from_microservice_key(kv_service, audit_logs_key, auth=main_auth) user_svc = UserService(main_connection) administration_svc = AdministrationService(main_connection) file_event_svc = FileEventService(file_events_conn) user_ctx = UserContext(administration_svc) user_profile_svc = DetectionListUserService(ecm_conn, user_ctx, user_svc) cases_conn = Connection.from_microservice_key(kv_service, cases_key, auth=main_auth) trusted_activities_conn = Connection.from_microservice_key( kv_service, trusted_activities_key, auth=main_auth) services = Services( administration=administration_svc, archive=ArchiveService(main_connection), devices=DeviceService(main_connection), legalhold=LegalHoldService(main_connection), orgs=OrgService(main_connection), users=UserService(main_connection), alertrules=AlertRulesService(alert_rules_conn, user_ctx, user_profile_svc), alerts=AlertService(alerts_conn, user_ctx), fileevents=file_event_svc, savedsearch=SavedSearchService(file_events_conn, file_event_svc), preservationdata=PreservationDataService(pds_conn), departingemployee=DepartingEmployeeService(ecm_conn, user_ctx, user_profile_svc), highriskemployee=HighRiskEmployeeService(ecm_conn, user_ctx, user_profile_svc), userprofile=user_profile_svc, auditlogs=AuditLogsService(audit_logs_conn), cases=CasesService(cases_conn), casesfileevents=CasesFileEventsService(cases_conn), trustedactivities=TrustedActivitiesService(trusted_activities_conn), ) return services, user_ctx