Esempio n. 1
0
 def test_stream_to_device_calls_accessor_stream_to_device(
     self,
     archive_accessor_factory,
     archive_service,
     archive_explorer,
     archive_content_pusher,
 ):
     archive_accessor_factory.create_archive_accessor.return_value = archive_explorer
     archive_accessor_factory.create_archive_content_pusher.return_value = (
         archive_content_pusher
     )
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.stream_to_device(
         TEST_PATHS,
         TEST_DEVICE_GUID,
         TEST_ACCEPTING_GUID,
         TEST_RESTORE_PATH,
         destination_guid=TEST_DESTINATION_GUID_1,
         archive_password=TEST_PASSWORD,
         encryption_key=TEST_ENCRYPTION_KEY,
         file_size_calc_timeout=100,
         show_deleted=True,
         overwrite_existing_files=True,
     )
     archive_content_pusher.stream_to_device.assert_called_once_with(
         TEST_RESTORE_PATH,
         TEST_ACCEPTING_GUID,
         TEST_FILE_SELECTIONS,
         TEST_BACKUP_SET_ID,
         True,
         True,
     )
Esempio n. 2
0
 def test_get_by_archive_guid_calls_get_single_archive_with_expected_params(
         self, archive_service, archive_accessor_manager):
     archive_guid = 42
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.get_by_archive_guid(archive_guid)
     archive_service.get_single_archive.assert_called_once_with(
         archive_guid)
Esempio n. 3
0
 def test_get_all_by_device_guid_calls_get_all_archives_from_value_with_expected_params(
         self, archive_service, archive_accessor_factory):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     for _ in archive.get_all_by_device_guid(TEST_DEVICE_GUID):
         pass
     archive_service.get_all_archives_from_value.assert_called_once_with(
         TEST_DEVICE_GUID, "backupSourceGuid")
Esempio n. 4
0
 def test_stream_to_device_prefers_backup_set_id_of_1(
     self,
     mocker,
     archive_accessor_factory,
     archive_service,
     archive_explorer,
     archive_content_pusher,
 ):
     backup_set_text = f'{{"backupSets": [{{"backupSetId": "{TEST_BACKUP_SET_ID}"}}, {{"backupSetId": "1"}}]}}'
     backup_set_response = create_mock_response(mocker, backup_set_text)
     archive_service.get_backup_sets.return_value = backup_set_response
     archive_accessor_factory.create_archive_accessor.return_value = archive_explorer
     archive_accessor_factory.create_archive_content_pusher.return_value = (
         archive_content_pusher)
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.stream_to_device(
         TEST_PATHS,
         TEST_DEVICE_GUID,
         TEST_ACCEPTING_GUID,
         TEST_RESTORE_PATH,
         destination_guid=TEST_DESTINATION_GUID_1,
         archive_password=TEST_PASSWORD,
         encryption_key=TEST_ENCRYPTION_KEY,
         file_size_calc_timeout=100,
         show_deleted=True,
     )
     archive_content_pusher.stream_to_device.assert_called_once_with(
         TEST_RESTORE_PATH,
         TEST_ACCEPTING_GUID,
         TEST_FILE_SELECTIONS,
         "1",
         True,
         False,
     )
Esempio n. 5
0
 def test_get_all_device_restore_history_calls_get_all_restore_history_with_expected_id(
     self, archive_accessor_factory, archive_service
 ):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.get_all_device_restore_history(TEST_DAYS, TEST_ORG_ID)
     archive_service.get_all_restore_history.assert_called_once_with(
         TEST_DAYS, "computerId", TEST_ORG_ID
     )
Esempio n. 6
0
 def test_update_cold_storage_purge_date_calls_update_cold_storage_with_expected_data(
     self, archive_accessor_factory, archive_service
 ):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.update_cold_storage_purge_date(u"123", u"2020-04-24")
     archive_service.update_cold_storage_purge_date.assert_called_once_with(
         u"123", u"2020-04-24"
     )
Esempio n. 7
0
 def test_get_all_by_device_guid_calls_get_all_archives_from_value_with_expected_params(
         self, archive_service, archive_accessor_manager):
     device_guid = 42
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     for _ in archive.get_all_by_device_guid(device_guid):
         pass
     archive_service.get_all_archives_from_value.assert_called_once_with(
         device_guid, u"backupSourceGuid")
Esempio n. 8
0
 def test_get_backup_sets_calls_archive_service_get_backup_sets_with_expected_params(
     self, archive_accessor_factory, archive_service
 ):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.get_backup_sets(TEST_DEVICE_GUID, TEST_DESTINATION_GUID_1)
     archive_service.get_backup_sets.assert_called_once_with(
         TEST_DEVICE_GUID, TEST_DESTINATION_GUID_1
     )
Esempio n. 9
0
 def test_get_all_org_cold_storage_archives_calls_client_with_expected_data(
         self, archive_accessor_manager, archive_service):
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.get_all_org_cold_storage_archives("TEST ORG ID", True,
                                               "sort_key", "sort_dir")
     archive_service.get_all_org_cold_storage_archives.assert_called_once_with(
         org_id="TEST ORG ID",
         include_child_orgs=True,
         sort_key="sort_key",
         sort_dir="sort_dir",
     )
Esempio n. 10
0
 def test_stream_from_backup_calls_get_archive_accessor_with_expected_params(
         self, archive_accessor_manager, archive_service):
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.stream_from_backup("path", "device_guid", "dest_guid",
                                "password", "encryption_key")
     archive_accessor_manager.get_archive_accessor.assert_called_once_with(
         "device_guid",
         destination_guid="dest_guid",
         private_password="******",
         encryption_key="encryption_key",
     )
Esempio n. 11
0
 def test_stream_from_backup_when_given_multiple_paths_calls_archive_accessor_stream_from_backup_with_expected_params(
         self, archive_accessor_manager, archive_service, archive_accessor):
     archive_accessor_manager.get_archive_accessor.return_value = archive_accessor
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.stream_from_backup(
         ["path/to/first/file", "path/to/second/file"],
         "device_guid",
         "dest_guid",
         "password",
         "encryption_key",
     )
     archive_accessor.stream_from_backup.assert_called_once_with(
         ["path/to/first/file", "path/to/second/file"],
         file_size_calc_timeout=10)
Esempio n. 12
0
 def test_stream_from_backup_calls_get_archive_accessor_with_expected_params(
         self, archive_accessor_factory, archive_service):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.stream_from_backup(
         TEST_PATHS[0],
         TEST_DEVICE_GUID,
         TEST_DESTINATION_GUID_1,
         TEST_PASSWORD,
         TEST_ENCRYPTION_KEY,
     )
     archive_accessor_factory.create_archive_accessor.assert_called_once_with(
         TEST_DEVICE_GUID,
         ArchiveContentStreamer,
         destination_guid=TEST_DESTINATION_GUID_1,
         private_password=TEST_PASSWORD,
         encryption_key=TEST_ENCRYPTION_KEY,
     )
Esempio 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
Esempio n. 14
0
 def test_stream_from_backup_when_given_multiple_paths_calls_archive_accessor_stream_from_backup_with_expected_params(
         self, archive_accessor_factory, archive_service,
         archive_content_streamer):
     archive_accessor_factory.create_archive_accessor.return_value = (
         archive_content_streamer)
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.stream_from_backup(
         TEST_PATHS,
         TEST_DEVICE_GUID,
         TEST_DESTINATION_GUID_1,
         TEST_PASSWORD,
         TEST_ENCRYPTION_KEY,
         file_size_calc_timeout=10000,
         show_deleted=True,
     )
     archive_content_streamer.stream_from_backup.assert_called_once_with(
         TEST_BACKUP_SET_ID,
         TEST_PATHS,
         file_size_calc_timeout=10000,
         show_deleted=True,
     )
Esempio n. 15
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
Esempio n. 16
0
 def test_get_backup_sets_calls_archive_service_get_backup_sets_with_expected_params(
         self, archive_accessor_manager, archive_service):
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.get_backup_sets("device_guid", "dest_guid")
     archive_service.get_backup_sets.assert_called_once_with(
         "device_guid", "dest_guid")
Esempio n. 17
0
 def test_get_by_archive_guid_calls_get_single_archive_with_expected_params(
     self, archive_service, archive_accessor_factory
 ):
     archive = ArchiveClient(archive_accessor_factory, archive_service)
     archive.get_by_archive_guid(TEST_ARCHIVE_GUID)
     archive_service.get_single_archive.assert_called_once_with(TEST_ARCHIVE_GUID)
Esempio n. 18
0
 def test_get_all_user_restore_history_calls_get_all_restore_history_with_expected_id(
         self, archive_accessor_manager, archive_service):
     archive = ArchiveClient(archive_accessor_manager, archive_service)
     archive.get_all_user_restore_history(self._TEST_DAYS, self._TEST_ID)
     archive_service.get_all_restore_history.assert_called_once_with(
         self._TEST_DAYS, "userId", self._TEST_ID)