UT: Add tests for adding credentials from event to repository

This commit is contained in:
Ilija Lazoroski 2022-08-12 15:00:53 +02:00
parent db8e1e50da
commit b3ac7a6538
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
from unittest.mock import MagicMock
from uuid import UUID
from common.credentials import Credentials, Password, Username
from common.events import CredentialsStolenEvent
from infection_monkey.credential_repository import (
IPropagationCredentialsRepository,
add_credentials_from_event_to_propagation_credentials_repository,
)
credentials = [Credentials(identity=Username("test_username"), secret=Password("some_password"))]
credentials_stolen_event = CredentialsStolenEvent(
source=UUID("f811ad00-5a68-4437-bd51-7b5cc1768ad5"),
target=None,
timestamp=0.0,
tags=frozenset({"stolen credentials"}),
stolen_credentials=credentials,
)
def test_add_credentials_from_event_to_propagation_credentials_repository():
mock_propagation_credentials_repository = MagicMock(spec=IPropagationCredentialsRepository)
fn = add_credentials_from_event_to_propagation_credentials_repository(
mock_propagation_credentials_repository
)
fn(credentials_stolen_event)
assert mock_propagation_credentials_repository.add_credentials.called_with(credentials)