From aaf1009504c1caa3c95e20541e38e61d970c7eb2 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 11 Jul 2022 13:54:06 -0400 Subject: [PATCH] UT: Add InMemoryCredentialsRepository --- .../in_memory_credentials_repository.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 monkey/tests/monkey_island/in_memory_credentials_repository.py diff --git a/monkey/tests/monkey_island/in_memory_credentials_repository.py b/monkey/tests/monkey_island/in_memory_credentials_repository.py new file mode 100644 index 000000000..6eb8155e8 --- /dev/null +++ b/monkey/tests/monkey_island/in_memory_credentials_repository.py @@ -0,0 +1,35 @@ +from typing import Sequence + +from common.credentials import Credentials +from monkey_island.cc.repository import ICredentialsRepository + + +class InMemoryCredentialsRepository(ICredentialsRepository): + def __init__(self): + self._configured_credentials = [] + self._stolen_credentials = [] + + def get_configured_credentials(self) -> Sequence[Credentials]: + return self._configured_credentials + + def get_stolen_credentials(self) -> Sequence[Credentials]: + return self._stolen_credentials + + def get_all_credentials(self) -> Sequence[Credentials]: + return [*self._configured_credentials, *self._stolen_credentials] + + def save_configured_credentials(self, credentials: Sequence[Credentials]): + self._configured_credentials.extend(credentials) + + def save_stolen_credentials(self, credentials: Sequence[Credentials]): + self._stolen_credentials.extend(credentials) + + def remove_configured_credentials(self): + self._configured_credentials = [] + + def remove_stolen_credentials(self): + self._stolen_credentials = [] + + def remove_all_credentials(self): + self.remove_configured_credentials() + self.remove_stolen_credentials()