Exemplo n.º 1
0
    def test_create_user_when_service_returns_cannot_find_user_bad_request_raises_unable_to_create_error(
        self,
        mocker,
        mock_detection_list_user_service,
        mock_departing_employee_service,
        mock_high_risk_employee_service,
    ):
        mock_err_response_content = """
            {
                "pop-bulletin": {
                    "type$": "com.code42.casemanagement.CaseMessages.InvalidUser",
                    "text$": "Could not find user: testusername",
                    "details": [],
                    "user": "******"
                }
            }"""
        mock_detection_list_user_service.get.side_effect = create_mock_error(
            Py42BadRequestError, mocker, mock_err_response_content)

        client = DetectionListsClient(
            mock_detection_list_user_service,
            mock_departing_employee_service,
            mock_high_risk_employee_service,
        )
        with pytest.raises(Py42UnableToCreateProfileError) as err:
            client.create_user("testusername")

        assert (
            "Detection-list profiles are now created automatically on the server. "
            "Unable to find a detection-list profile for 'testusername'. It is "
            "possibly still being created if you just recently created the Code42 "
            "user." in str(err.value))
        assert err.value.username == "testusername"
Exemplo n.º 2
0
 def test_refresh_user_scim_attributes_returns_response(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     response = client.refresh_user_scim_attributes(TEST_USER_ID)
     assert response
Exemplo n.º 3
0
 def test_remove_user_cloud_alias_returns_response(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     response = client.remove_user_cloud_alias(TEST_USER_ID, "oldalias")
     assert response
Exemplo n.º 4
0
 def test_add_user_risk_tags_returns_response(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     response = client.add_user_risk_tags(TEST_USER_ID, "newtag")
     assert response
Exemplo n.º 5
0
 def test_update_user_notes_returns_response(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     response = client.update_user_notes(TEST_USER_ID, "newnotes")
     assert response
Exemplo n.º 6
0
 def test_create_user_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.create_user("testusername")
     mock_detection_list_user_service.get.assert_called_once_with(
         "testusername")
Exemplo n.º 7
0
 def test_refresh_user_scim_attributes_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.refresh_user_scim_attributes(TEST_USER_ID)
     mock_detection_list_user_service.refresh.assert_called_once_with(
         TEST_USER_ID)
Exemplo n.º 8
0
 def test_remove_user_cloud_alias_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.remove_user_cloud_alias(TEST_USER_ID, "oldalias")
     mock_detection_list_user_service.remove_cloud_alias.assert_called_once_with(
         TEST_USER_ID, "oldalias")
Exemplo n.º 9
0
 def test_add_user_risk_tags_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.add_user_risk_tags(TEST_USER_ID, "newtag")
     mock_detection_list_user_service.add_risk_tags.assert_called_once_with(
         TEST_USER_ID, "newtag")
Exemplo n.º 10
0
 def test_update_user_notes_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.update_user_notes(TEST_USER_ID, "newnotes")
     mock_detection_list_user_service.update_notes.assert_called_once_with(
         TEST_USER_ID, "newnotes")
Exemplo n.º 11
0
 def test_get_user_by_id_calls_user_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     client.get_user_by_id(TEST_USER_ID)
     mock_detection_list_user_service.get_by_id.assert_called_once_with(
         TEST_USER_ID)
Exemplo n.º 12
0
 def test_create_user_when_service_returns_bad_request_raises(
     self,
     mocker,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     mock_detection_list_user_service.get.side_effect = create_mock_error(
         Py42BadRequestError, mocker, "")
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     with pytest.raises(Py42BadRequestError):
         client.create_user("testusername")
Exemplo n.º 13
0
def _init_clients(services, connection):
    # clients are imported within function to prevent circular imports when a client
    # imports anything from py42.sdk.queries
    from py42.clients import Clients
    from py42.clients._archiveaccess.accessorfactory import ArchiveAccessorFactory
    from py42.clients.alertrules import AlertRulesClient
    from py42.clients.alerts import AlertsClient
    from py42.clients.archive import ArchiveClient
    from py42.clients.auditlogs import AuditLogsClient
    from py42.clients.authority import AuthorityClient
    from py42.clients.cases import CasesClient
    from py42.clients.detectionlists import DetectionListsClient
    from py42.clients.loginconfig import LoginConfigurationClient
    from py42.clients.securitydata import SecurityDataClient
    from py42.clients.trustedactivities import TrustedActivitiesClient
    from py42.services.storage._service_factory import ConnectionManager
    from py42.services.storage._service_factory import StorageServiceFactory

    authority = AuthorityClient(
        administration=services.administration,
        archive=services.archive,
        devices=services.devices,
        legalhold=services.legalhold,
        orgs=services.orgs,
        users=services.users,
    )
    detectionlists = DetectionListsClient(services.userprofile,
                                          services.departingemployee,
                                          services.highriskemployee)
    storage_service_factory = StorageServiceFactory(connection,
                                                    services.devices,
                                                    ConnectionManager())
    alertrules = AlertRulesClient(services.alerts, services.alertrules)
    securitydata = SecurityDataClient(
        services.fileevents,
        services.preservationdata,
        services.savedsearch,
        storage_service_factory,
    )
    alerts = AlertsClient(services.alerts, alertrules)
    archive_accessor_factory = ArchiveAccessorFactory(services.archive,
                                                      storage_service_factory)
    archive = ArchiveClient(archive_accessor_factory, services.archive)
    auditlogs = AuditLogsClient(services.auditlogs)
    loginconfig = LoginConfigurationClient(connection)
    trustedactivities = TrustedActivitiesClient(services.trustedactivities)
    clients = Clients(
        authority=authority,
        detectionlists=detectionlists,
        alerts=alerts,
        securitydata=securitydata,
        archive=archive,
        auditlogs=auditlogs,
        cases=CasesClient(services.cases, services.casesfileevents),
        loginconfig=loginconfig,
        trustedactivities=trustedactivities,
    )
    return clients
Exemplo n.º 14
0
 def test_high_risk_employee_returns_high_risk_employee_client(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     assert client.high_risk_employee is mock_high_risk_employee_service
Exemplo n.º 15
0
 def test_departing_employee_call_get_departing_employee_client_with_expected_values(
     self,
     mock_detection_list_user_service,
     mock_departing_employee_service,
     mock_high_risk_employee_service,
 ):
     client = DetectionListsClient(
         mock_detection_list_user_service,
         mock_departing_employee_service,
         mock_high_risk_employee_service,
     )
     assert client.departing_employee is mock_departing_employee_service
Exemplo n.º 16
0
def _init_clients(services, connection):
    authority = AuthorityClient(
        administration=services.administration,
        archive=services.archive,
        devices=services.devices,
        legalhold=services.legalhold,
        orgs=services.orgs,
        securitydata=services.securitydata,
        users=services.users,
    )
    detectionlists = DetectionListsClient(services.userprofile,
                                          services.departingemployee,
                                          services.highriskemployee)

    storage_service_factory = StorageServiceFactory(connection,
                                                    services.devices,
                                                    ConnectionManager())
    alertrules = AlertRulesClient(services.alerts, services.alertrules)
    securitydata = SecurityDataClient(
        services.securitydata,
        services.fileevents,
        services.preservationdata,
        services.savedsearch,
        storage_service_factory,
    )
    alerts = AlertsClient(services.alerts, alertrules)
    archive_accessor_mgr = ArchiveAccessorManager(services.archive,
                                                  storage_service_factory)
    archive = ArchiveClient(archive_accessor_mgr, services.archive)
    auditlogs = AuditLogsClient(services.auditlogs)
    clients = Clients(
        authority=authority,
        detectionlists=detectionlists,
        alerts=alerts,
        securitydata=securitydata,
        archive=archive,
        auditlogs=auditlogs,
    )
    return clients