From 7c920cced358dfc20c7d4f39c04d95141757edbe Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 18 Jul 2022 09:07:11 -0400 Subject: [PATCH] Agent: Fix identity logic in AggregatingCredentialsStore --- .../credential_store/aggregating_credentials_store.py | 8 +++++--- .../test_aggregating_credentials_store.py | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py index dacfbdcee..23ad7ee19 100644 --- a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py +++ b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py @@ -26,9 +26,11 @@ class AggregatingCredentialsStore(ICredentialsStore): def add_credentials(self, credentials_to_add: Iterable[Credentials]): for credentials in credentials_to_add: - self._stored_credentials.setdefault("exploit_user_list", set()).add( - credentials.identity.username - ) + identity = credentials.identity + if identity and identity.credential_type is CredentialComponentType.USERNAME: + self._stored_credentials.setdefault("exploit_user_list", set()).add( + identity.username + ) secret = credentials.secret diff --git a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py index 54d43f59c..871f0db44 100644 --- a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py +++ b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py @@ -38,6 +38,10 @@ TEST_CREDENTIALS = [ identity=Username("user3"), secret=SSHKeypair(public_key="some_public_key_1", private_key="some_private_key_1"), ), + Credentials( + identity=None, + secret=Password("super_secret"), + ), ] SSH_KEYS_CREDENTIALS = [ @@ -93,6 +97,7 @@ def test_add_credentials_to_store(aggregating_credentials_store): "abcdefg", "password", "root", + "super_secret", ] )