UT: Fix tests for event encryption

This commit is contained in:
Kekoa Kaaikala 2022-09-16 13:43:10 +00:00
parent 54fe2a6dca
commit c19e50b7f1
2 changed files with 18 additions and 5 deletions

View File

@ -30,7 +30,7 @@ def encryptor(key_file):
@pytest.fixture
def serializer():
return PydanticAgentEventSerializer()
return PydanticAgentEventSerializer(FakeAgentEvent)
def test_agent_event_encryption__encrypts(encryptor, serializer):

View File

@ -18,6 +18,7 @@ from monkey_island.cc.repository import (
RetrievalError,
StorageError,
)
from monkey_island.cc.server_utils.encryption import RepositoryEncryptor
class FakeAgentEvent(AbstractAgentEvent):
@ -54,8 +55,20 @@ def mongo_client(event_serializer_registry):
@pytest.fixture
def mongo_repository(mongo_client, event_serializer_registry) -> IAgentEventRepository:
return MongoEventRepository(mongo_client, event_serializer_registry)
def key_file(tmp_path):
return tmp_path / "test_key.bin"
@pytest.fixture
def encryptor(key_file):
encryptor = RepositoryEncryptor(key_file)
encryptor.unlock(b"password")
return encryptor
@pytest.fixture
def mongo_repository(mongo_client, event_serializer_registry, encryptor) -> IAgentEventRepository:
return MongoEventRepository(mongo_client, event_serializer_registry, encryptor)
@pytest.fixture
@ -75,9 +88,9 @@ def error_raising_mongo_client(mongo_client) -> mongomock.MongoClient:
@pytest.fixture
def error_raising_mongo_repository(
error_raising_mongo_client, event_serializer_registry
error_raising_mongo_client, event_serializer_registry, encryptor
) -> IAgentEventRepository:
return MongoEventRepository(error_raising_mongo_client, event_serializer_registry)
return MongoEventRepository(error_raising_mongo_client, event_serializer_registry, encryptor)
def assert_same_contents(a, b):