diff --git a/monkey/infection_monkey/credential_repository/aggregating_propagation_credentials_repository.py b/monkey/infection_monkey/credential_repository/aggregating_propagation_credentials_repository.py index 59ff279e0..ab380fdef 100644 --- a/monkey/infection_monkey/credential_repository/aggregating_propagation_credentials_repository.py +++ b/monkey/infection_monkey/credential_repository/aggregating_propagation_credentials_repository.py @@ -63,12 +63,11 @@ class AggregatingPropagationCredentialsRepository(IPropagationCredentialsReposit try: propagation_credentials = self._get_credentials_from_control_channel() self.add_credentials(propagation_credentials) - - return self._stored_credentials except Exception as ex: - self._stored_credentials = {} logger.error(f"Error while attempting to retrieve credentials for propagation: {ex}") + return self._stored_credentials + def _set_attribute(self, attribute_to_be_set: str, credentials_values: Iterable[Any]): if not credentials_values: return diff --git a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_propagation_credentials_repository.py b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_propagation_credentials_repository.py index f2cc0dcfa..c992aaf85 100644 --- a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_propagation_credentials_repository.py +++ b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_propagation_credentials_repository.py @@ -122,3 +122,16 @@ def test_all_keys_if_credentials_empty(): assert "exploit_password_list" in actual_stored_credentials assert "exploit_ntlm_hash_list" in actual_stored_credentials assert "exploit_ssh_keys" in actual_stored_credentials + + +def test_credentials_obtained_if_propagation_credentials_fails(): + control_channel = MagicMock() + control_channel.get_credentials_for_propagation.return_value = EMPTY_CHANNEL_CREDENTIALS + control_channel.get_credentials_for_propagation.side_effect = Exception( + "No credentials for you!" + ) + credentials_repository = AggregatingPropagationCredentialsRepository(control_channel) + + credentials = credentials_repository.get_credentials() + + assert credentials is not None