class TestDeviceSettings(object): device_settings = DeviceSettings(DEVICE_DICT_W_SETTINGS) @pytest.mark.parametrize( "param", [ ("computer_id", TEST_COMPUTER_ID), ("guid", TEST_COMPUTER_GUID), ("user_id", TEST_USER_ID), ("org_id", TEST_COMPUTER_ORG_ID), ("version", TEST_DEVICE_VERSION), ( "available_destinations", { TEST_DESTINATION_GUID_1: TEST_DESTINATION_NAME_1, TEST_DESTINATION_GUID_2: TEST_DESTINATION_NAME_2, TEST_DESTINATION_GUID_3: TEST_DESTINATION_NAME_3, }, ), ], ) def test_device_settings_properties_return_expected_value_and_cannot_be_changed( self, param ): name, expected_value = param assert getattr(self.device_settings, name) == expected_value with pytest.raises(AttributeError): setattr(self.device_settings, name, expected_value) @pytest.mark.parametrize( "param", [ ("notes", None), ("name", TEST_COMPUTER_NAME), ("external_reference", None), ("warning_email_enabled", True), ("critical_email_enabled", True), ("warning_alert_days", 5), ("critical_alert_days", 10), ("backup_status_email_enabled", False), ("backup_status_email_frequency_days", 7), ], ) def test_device_settings_get_mutable_properties_return_expected_values(self, param): name, expected_value = param assert getattr(self.device_settings, name) == expected_value @pytest.mark.parametrize( "param", [ param( name="notes", new_val="a device note.", expected_stored_val="a device note.", dict_location=["notes"], ), param( name="name", new_val="Settings Test Device Updated", expected_stored_val="Settings Test Device Updated", dict_location=["name"], ), param( name="external_reference", new_val="reference#id", expected_stored_val="reference#id", dict_location=["computerExtRef"], ), param( name="warning_email_enabled", new_val=False, expected_stored_val="false", dict_location=[ "settings", "serviceBackupConfig", "warningEmailEnabled", ], ), param( name="critical_email_enabled", new_val=False, expected_stored_val="false", dict_location=["settings", "serviceBackupConfig", "severeEmailEnabled"], ), param( name="warning_alert_days", new_val=10, expected_stored_val="14400", dict_location=[ "settings", "serviceBackupConfig", "minutesUntilWarning", ], ), param( name="critical_alert_days", new_val=100, expected_stored_val="144000", dict_location=["settings", "serviceBackupConfig", "minutesUntilSevere"], ), ], ) def test_device_settings_setting_mutable_property_updates_dict_correctly_and_registers_changes( self, param, ): setattr(self.device_settings, param.name, param.new_val) assert ( get_val(self.device_settings.data, param.dict_location) == param.expected_stored_val ) assert param.name in self.device_settings.changes @pytest.mark.parametrize( "param", [ param( name="backup_status_email_frequency_days", new_val=9, expected_stored_val={"#text": "12960", "@locked": "true"}, dict_location=[ "settings", "serviceBackupConfig", "backupStatusEmailFreqInMinutes", ], ), param( name="backup_status_email_enabled", new_val=True, expected_stored_val={"#text": "true", "@locked": "true"}, dict_location=[ "settings", "serviceBackupConfig", "backupStatusEmailEnabled", ], ), ], ) def test_device_settings_setting_mutable_property_updates_dict_correctly_and_registers_changes_when_setting_locked( self, param, ): setattr(self.device_settings, param.name, param.new_val) assert ( get_val(self.device_settings.data, param.dict_location) == param.expected_stored_val ) assert param.name in self.device_settings.changes
class TestOrgSettings(object): @pytest.mark.parametrize( "param", [ ("org_name", "TEST_ORG"), ("external_reference", "test_ref"), ("notes", "test_note"), ("archive_hold_days", 365), ("maximum_user_subscriptions", 99), ("org_backup_quota", -1), ("user_backup_quota", -1), ("web_restore_admin_limit", 500), ("web_restore_user_limit", 250), ("backup_warning_email_days", 3), ("backup_critical_email_days", 14), ("backup_alert_recipient_emails", ["*****@*****.**"]), ], ) def test_org_settings_properties_retrieve_expected_results( self, param, org_settings_dict ): org_settings = OrgSettings(org_settings_dict, TEST_T_SETTINGS_DICT) attr, expected = param assert getattr(org_settings, attr) == expected def test_inherited_org_settings_inheritance_flags_return_true( self, org_settings_inherited_dict ): org_settings = OrgSettings(org_settings_inherited_dict, TEST_T_SETTINGS_DICT) assert org_settings.quota_settings_inherited assert org_settings.reporting_settings_inherited @pytest.mark.parametrize( "param", [ ("archive_hold_days", 14), ("maximum_user_subscriptions", -1), ("org_backup_quota", -1), ("user_backup_quota", -1), ("web_restore_admin_limit", 250), ("web_restore_user_limit", 250), ("backup_warning_email_days", 7), ("backup_critical_email_days", 14), ("backup_alert_recipient_emails", []), ], ) def test_inherited_org_settings_properties_retrieve_expected_results( self, param, org_settings_inherited_dict ): org_settings = OrgSettings(org_settings_inherited_dict, TEST_T_SETTINGS_DICT) attr, expected = param assert getattr(org_settings, attr) == expected @pytest.mark.parametrize( "param", [ ("archive_hold_days", 15), ("maximum_user_subscriptions", 100), ("org_backup_quota", 10000), ("user_backup_quota", 10000), ], ) def test_inherited_org_quota_settings_setattr_removes_inheritance( self, param, org_settings_inherited_dict ): org_settings = OrgSettings(org_settings_inherited_dict, TEST_T_SETTINGS_DICT) attr, val = param setattr(org_settings, attr, val) assert not org_settings.quota_settings_inherited @pytest.mark.parametrize( "param", [ ( "available_destinations", { "632540230984925185": "PROe Cloud, US - West", "43": "PROe Cloud, US", "673679195225718785": "PROe Cloud, AMS", "587738803578339329": "PROe Cloud, SIN", }, ), ("warning_email_enabled", False), ("critical_email_enabled", False), ("warning_alert_days", 3), ("critical_alert_days", 5), ("backup_status_email_enabled", False), ("backup_status_email_frequency_days", 7), ], ) def test_org_settings_device_defaults_retrieve_expected_results( self, param, org_settings_dict ): org_settings = OrgSettings(org_settings_dict, TEST_T_SETTINGS_DICT) attr, expected = param assert getattr(org_settings.device_defaults, attr) == expected def test_org_settings_endpoint_monitoring_enabled_returns_expected_results( self, org_settings_dict ): t_setting = deepcopy(TEST_T_SETTINGS_DICT) t_setting["org-securityTools-enable"]["value"] = "true" org_settings = OrgSettings(org_settings_dict, t_setting) assert org_settings.endpoint_monitoring_enabled is True t_setting["org-securityTools-enable"]["value"] = "false" org_settings = OrgSettings(org_settings_dict, t_setting) assert org_settings.endpoint_monitoring_enabled is False def test_org_settings_set_endpoint_monitoring_enabled_to_true_from_false_creates_expected_packets( self, org_settings_dict ): t_setting = deepcopy(TEST_T_SETTINGS_DICT) t_setting["org-securityTools-enable"]["value"] = "true" org_settings = OrgSettings(org_settings_dict, t_setting) org_settings.endpoint_monitoring_enabled = False assert { "key": "org-securityTools-enable", "value": "false", "locked": False, } in org_settings.packets assert { "key": "device_advancedExfiltrationDetection_enabled", "value": "false", "locked": False, } in org_settings.packets assert { "key": "org-securityTools-cloud-detection-enable", "value": "false", "locked": False, } in org_settings.packets assert { "key": "org-securityTools-open-file-detection-enable", "value": "false", "locked": False, } in org_settings.packets assert { "key": "org-securityTools-device-detection-enable", "value": "false", "locked": False, } in org_settings.packets assert { "key": "org_securityTools_printer_detection_enable", "value": "false", "locked": False, } in org_settings.packets assert len(org_settings.packets) == 6 def test_org_settings_set_endpoint_monitoring_enabled_to_false_from_true_creates_expected_packets( self, org_settings_dict ): t_setting = deepcopy(TEST_T_SETTINGS_DICT) t_setting["org-securityTools-enable"]["value"] = "false" org_settings = OrgSettings(org_settings_dict, t_setting) org_settings.endpoint_monitoring_enabled = True assert { "key": "org-securityTools-enable", "value": "true", "locked": False, } in org_settings.packets assert { "key": "device_advancedExfiltrationDetection_enabled", "value": "true", "locked": False, } in org_settings.packets assert len(org_settings.packets) == 2 @pytest.mark.parametrize( "param", [ ( "endpoint_monitoring_removable_media_enabled", "org-securityTools-device-detection-enable", ), ( "endpoint_monitoring_cloud_sync_enabled", "org-securityTools-cloud-detection-enable", ), ( "endpoint_monitoring_browser_and_applications_enabled", "org-securityTools-open-file-detection-enable", ), ( "endpoint_monitoring_file_metadata_collection_enabled", "device_fileForensics_enabled", ), ], ) def test_org_settings_set_endpoint_monitoring_sub_categories_when_endpoint_monitoring_disabled_sets_endpoint_monitoring_enabled( self, param, org_settings_dict ): attr, key = param t_setting = deepcopy(TEST_T_SETTINGS_DICT) settings = deepcopy(org_settings_dict) t_setting["org-securityTools-enable"]["value"] = "false" org_settings = OrgSettings(settings, t_setting) setattr(org_settings, attr, True) packet_keys = [packet["key"] for packet in org_settings.packets] assert key in packet_keys assert "org-securityTools-enable" in packet_keys for packet in org_settings.packets: if packet["key"] == "org-securityTools-enable": assert packet["value"] == "true" if packet["key"] == key: assert packet["value"] == "true" @pytest.mark.parametrize( "param", [ param( name="endpoint_monitoring_file_metadata_scan_enabled", new_val=True, expected_stored_val="true", dict_location="device_fileForensics_scan_enabled", ), param( name="endpoint_monitoring_file_metadata_ingest_scan_enabled", new_val=True, expected_stored_val="true", dict_location="device_fileForensics_enqueue_scan_events_during_ingest", ), param( name="endpoint_monitoring_background_priority_enabled", new_val=True, expected_stored_val="true", dict_location="device_background_priority_enabled", ), param( name="web_restore_enabled", new_val=True, expected_stored_val="true", dict_location="device_webRestore_enabled", ), ], ) def test_org_settings_set_independent_t_setting_properties( self, param, org_settings_dict ): t_setting = deepcopy(TEST_T_SETTINGS_DICT) settings = deepcopy(org_settings_dict) org_settings = OrgSettings(settings, t_setting) setattr(org_settings, param.name, param.new_val) packet_keys = [packet["key"] for packet in org_settings.packets] assert param.dict_location in packet_keys for packet in org_settings.packets: if packet["key"] == param.dict_location: assert packet["value"] == "true" setattr(org_settings, param.name, False) packet_keys = [packet["key"] for packet in org_settings.packets] assert param.dict_location in packet_keys for packet in org_settings.packets: if packet["key"] == param.dict_location: assert packet["value"] == "false" def test_missing_t_settings_return_none_when_accessed_by_property( self, org_settings_dict ): org_settings = OrgSettings(org_settings_dict, TEST_T_SETTINGS_DICT) assert org_settings.endpoint_monitoring_file_metadata_scan_enabled is None assert ( org_settings.endpoint_monitoring_file_metadata_ingest_scan_enabled is None ) assert org_settings.endpoint_monitoring_background_priority_enabled is None assert org_settings.endpoint_monitoring_custom_applications_win is None assert org_settings.endpoint_monitoring_custom_applications_mac is None assert ( org_settings.endpoint_monitoring_file_metadata_collection_exclusions is None ) @pytest.mark.parametrize( "param", [ param( name="org_name", new_val="Org Name Updated", expected_stored_val="Org Name Updated", dict_location=["orgName"], ), param( name="external_reference", new_val="Updated Reference", expected_stored_val="Updated Reference", dict_location=["orgExtRef"], ), param( name="notes", new_val="Updated Note", expected_stored_val="Updated Note", dict_location=["notes"], ), param( name="maximum_user_subscriptions", new_val=99, expected_stored_val=99, dict_location=["settings", "maxSeats"], ), param( name="org_backup_quota", new_val=42, expected_stored_val=ONEGB * 42, dict_location=["settings", "maxBytes"], ), param( name="user_backup_quota", new_val=42, expected_stored_val=ONEGB * 42, dict_location=["settings", "defaultUserMaxBytes"], ), param( name="web_restore_admin_limit", new_val=42, expected_stored_val=42, dict_location=["settings", "webRestoreAdminLimitMb"], ), param( name="web_restore_user_limit", new_val=42, expected_stored_val=42, dict_location=["settings", "webRestoreUserLimitMb"], ), param( name="backup_warning_email_days", new_val=14, expected_stored_val=14, dict_location=["settings", "warnInDays"], ), param( name="backup_critical_email_days", new_val=25, expected_stored_val=25, dict_location=["settings", "alertInDays"], ), param( name="backup_alert_recipient_emails", new_val="*****@*****.**", # test string input expected_stored_val=["*****@*****.**"], dict_location=["settings", "recipients"], ), param( name="backup_alert_recipient_emails", new_val=["*****@*****.**", "*****@*****.**"], # test list input expected_stored_val=["*****@*****.**", "*****@*****.**"], dict_location=["settings", "recipients"], ), ], ) def test_org_settings_setting_mutable_property_updates_dict_correctly_and_registers_changes( self, param, org_settings_dict ): org_settings = OrgSettings(org_settings_dict, TEST_T_SETTINGS_DICT) setattr(org_settings, param.name, param.new_val) assert ( get_val(org_settings.data, param.dict_location) == param.expected_stored_val ) assert param.name in org_settings.changes