forked from p15670423/monkey
Island: Remove disused StringListEncryptor
This commit is contained in:
parent
60a1e79179
commit
7760520cc8
|
@ -21,5 +21,4 @@ from .dict_encryptor import (
|
|||
FieldNotFoundError,
|
||||
)
|
||||
from .field_encryptors.i_field_encryptor import IFieldEncryptor
|
||||
from .field_encryptors.string_list_encryptor import StringListEncryptor
|
||||
from .field_encryptors.string_encryptor import StringEncryptor
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
from .i_field_encryptor import IFieldEncryptor
|
||||
from .string_list_encryptor import StringListEncryptor
|
||||
from .string_encryptor import StringEncryptor
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
from typing import List
|
||||
|
||||
from ..data_store_encryptor import get_datastore_encryptor
|
||||
from . import IFieldEncryptor
|
||||
|
||||
|
||||
class StringListEncryptor(IFieldEncryptor):
|
||||
@staticmethod
|
||||
def encrypt(value: List[str]) -> List[str]:
|
||||
return [get_datastore_encryptor().encrypt(string.encode()).decode() for string in value]
|
||||
|
||||
@staticmethod
|
||||
def decrypt(value: List[str]) -> List[str]:
|
||||
return [get_datastore_encryptor().decrypt(string.encode()).decode() for string in value]
|
|
@ -1,16 +1,14 @@
|
|||
import copy
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
|
||||
from monkey_island.cc.models import Report
|
||||
from monkey_island.cc.models.report import get_report, save_report
|
||||
from monkey_island.cc.server_utils.encryption import IFieldEncryptor, SensitiveField
|
||||
|
||||
MOCK_SENSITIVE_FIELD_CONTENTS = ["the_string", "the_string2"]
|
||||
MOCK_REPORT_DICT = {
|
||||
"overview": {
|
||||
"foo": {"the_key": MOCK_SENSITIVE_FIELD_CONTENTS, "other_key": "other_value"},
|
||||
"foo": {"the_key": ["the_string", "the_string2"], "other_key": "other_value"},
|
||||
"bar": {"the_key": []},
|
||||
},
|
||||
"glance": {"foo": "bar"},
|
||||
|
@ -19,43 +17,6 @@ MOCK_REPORT_DICT = {
|
|||
}
|
||||
|
||||
|
||||
class MockStringListEncryptor(IFieldEncryptor):
|
||||
plaintext = []
|
||||
|
||||
@staticmethod
|
||||
def encrypt(value: List[str]) -> List[str]:
|
||||
return [MockStringListEncryptor._encrypt(v) for v in value]
|
||||
|
||||
@staticmethod
|
||||
def _encrypt(value: str) -> str:
|
||||
MockStringListEncryptor.plaintext.append(value)
|
||||
return f"ENCRYPTED_{str(len(MockStringListEncryptor.plaintext) - 1)}"
|
||||
|
||||
@staticmethod
|
||||
def decrypt(value: List[str]) -> List[str]:
|
||||
return MockStringListEncryptor.plaintext
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_sensitive_fields(monkeypatch):
|
||||
mock_sensitive_fields = [
|
||||
SensitiveField("overview.foo.the_key", MockStringListEncryptor),
|
||||
SensitiveField("overview.bar.the_key", MockStringListEncryptor),
|
||||
]
|
||||
monkeypatch.setattr(
|
||||
"monkey_island.cc.models.report.report_dal.sensitive_fields", mock_sensitive_fields
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_database")
|
||||
def test_report_encryption():
|
||||
save_report(MOCK_REPORT_DICT)
|
||||
|
||||
assert Report.objects.first()["overview"]["foo"]["the_key"] == ["ENCRYPTED_0", "ENCRYPTED_1"]
|
||||
assert Report.objects.first()["overview"]["bar"]["the_key"] == []
|
||||
assert get_report()["overview"]["foo"]["the_key"] == MOCK_SENSITIVE_FIELD_CONTENTS
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_database")
|
||||
def test_report_dot_encoding():
|
||||
mrd = copy.deepcopy(MOCK_REPORT_DICT)
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import pytest
|
||||
|
||||
from monkey_island.cc.server_utils.encryption import StringListEncryptor
|
||||
|
||||
MOCK_STRING_LIST = ["test_1", "test_2"]
|
||||
EMPTY_LIST = []
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_encryption_and_decryption(uses_encryptor):
|
||||
encrypted_list = StringListEncryptor.encrypt(MOCK_STRING_LIST)
|
||||
assert not encrypted_list == MOCK_STRING_LIST
|
||||
decrypted_list = StringListEncryptor.decrypt(encrypted_list)
|
||||
assert decrypted_list == MOCK_STRING_LIST
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_empty_list(uses_encryptor):
|
||||
# Tests that no errors are raised
|
||||
encrypted_list = StringListEncryptor.encrypt(EMPTY_LIST)
|
||||
StringListEncryptor.decrypt(encrypted_list)
|
Loading…
Reference in New Issue