Refactored unit tests and added a unit test for a function which checks whether or not config is encrypted.

This commit is contained in:
VakarisZ 2021-06-11 11:39:37 +03:00
parent a36fc81755
commit 5cf002d81a
4 changed files with 133 additions and 232 deletions

View File

@ -1,3 +1,20 @@
# Without these imports pytests can't use fixtures,
# because they are not found
import json
import os
import pytest
from tests.unit_tests.monkey_island.cc.mongomock_fixtures import * # noqa: F401,F403,E402
from tests.unit_tests.monkey_island.cc.services.utils.test_config_encryption import (
MONKEY_CONFIGS_DIR_PATH,
STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME,
)
@pytest.fixture
def monkey_config(data_for_tests_dir):
plaintext_monkey_config_standard_path = os.path.join(
data_for_tests_dir, MONKEY_CONFIGS_DIR_PATH, STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME
)
plaintext_config = json.loads(open(plaintext_monkey_config_standard_path, "r").read())
return plaintext_config

View File

@ -0,0 +1,31 @@
import json
import pytest
from tests.unit_tests.monkey_island.cc.services.utils.cyphertexts_for_encryption_test import (
MALFORMED_CYPHER_TEXT_CORRUPTED,
)
from tests.unit_tests.monkey_island.cc.services.utils.test_config_encryption import PASSWORD
from common.utils.exceptions import InvalidConfigurationError
from monkey_island.cc.resources.configuration_import import ConfigurationImport
from monkey_island.cc.services.utils.config_encryption import encrypt_config
def test_is_config_encrypted__json(monkey_config):
monkey_config = json.dumps(monkey_config)
assert not ConfigurationImport.is_config_encrypted(monkey_config)
def test_is_config_encrypted__ciphertext(monkey_config):
encrypted_config = encrypt_config(monkey_config, PASSWORD)
assert ConfigurationImport.is_config_encrypted(encrypted_config)
def test_is_config_encrypted__corrupt_ciphertext():
with pytest.raises(InvalidConfigurationError):
assert ConfigurationImport.is_config_encrypted(MALFORMED_CYPHER_TEXT_CORRUPTED)
def test_is_config_encrypted__unknown_format():
with pytest.raises(InvalidConfigurationError):
assert ConfigurationImport.is_config_encrypted("ABC")

View File

@ -1,206 +1,74 @@
MALFORMED_CYPHER_TEXT_TOO_SHORT = (
b"AES\x02\x00\x00\x1bCREATED_BY\x00pyAesCrypt "
b"6.0.0\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
MALFORMED_CYPHER_TEXT_CORRUPTED = (
b"AES\x02\x00\x00\x1bCREATED_BY\x00pyAesCrypt "
b"6.0.0\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\xc2\xc3w0\xe5\x06\xd2\xb9\x05b\xce\xb2\xc7"
b"\x18f\x87j|y\xcd\xbd\\("
b"V\xfa!%\xcc@\x11\x98>\x9c^\x11\xa1\x82\xe9@\x89\xde\xe9\xb2)h\xb2"
b"`\x07y\x01\xa8zr\xd0\xe2\xb9m\xb1&\xb5f\x95\x80\x98\xac\xa6\x04.8"
b"\xf0\xbf\xee\x18!\xf5T\x04a\xb5\xb2Q\xb0|\xff\xe7\xdd)F\xd5E\xa6"
b"\xbf\xf6\xb0D\x02\x92\xb9Z\x01 "
b"F\x9f.9\x92zc\x9bI\xaf\rB6\xcb\r\x1b\xbf\xb8m\xbdBBt5\x9d\xc9\xeb"
b"\x9b\xe0u\xe8'H5\x96\x11\xbf>\xa7\xaa\xb4\x06\x1e\xb7\x99\xf1\x86"
b"\xd1\x81\x8e.\xf5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2cjV0DJFMnMSVeX0xFLU1lgV/c6yTXr5Aj8eLl551luJosQ"
"/EQiwAUrUriQZY4g0ydhOStX4nMoEjBogH6AyJIAaAig2wCQZaAorqW712ihxjnfX86KiBxDBE19sIQjIv2tp0Nml0lf"
"oaH19iqmZgqH79KmTIdVBEFg0LIImPuBzxlPferszFSKslbP3HisWWfTDeF8QnBeBjBjhvSTXibj1uzvcs8+dAs17w6i"
"/QxHNKHzPK5Yb+/aEFYED3SgZ0NrhHi2TXSGzP4wGjMj96GRqDlVOx6Sg4Nyvhqm2rMtXpWI848KK7VZ"
"/BQddFttCiqXOm1P6oHu7ilHwG8cRau/GREyIsHQnWXWGXJFs2+s4vAxcQBMcm5yx8w3vYTiC+dxVivwrk+HYFWa"
"+Gs5s7490LyKqEFy9l7H4RTOhTlVJ3/f8yr6LRErBD7+5IzDeNlI"
"/dyfbEW5GyBtgR9bZPziawP5Ue8XhMJhXNf3r5mORmnr"
"+5M2e26BK3Zt4axjnQ82YRpfYsEJSNUgmYBS28qDV53NhouldyKVr0VwsCs2Lg5JYc1ejJPQEFi2w7RwvCkdcfOGqAnLy"
"1U8m+8uX5VZYjEdimDzA+LJQ2/zJmYREr0TWcjRmK"
"/MYyCXbJXarUhv0nhm9IT74qy36budxt60ub7zO0oemwCXw7uniS/MNdDaNWszdHHZ8zSDDI"
"/8lDNyP2QqaoyrJoy8COYX192FoMLvPcdGH7VoX8NX9Eag0OAOHtKZMRgfvvL"
"/bfHfAb6OOyGUstNgeheHB0KZj2u4CGdRPRYMSqJ/8LTZO+eSdCsgDDoxH42fO0XFe1T1O"
"/xg3HngdfM4tRWGeqXGYYA2cJwLJlHgrlP3MFimPhgT3j46K/OkoNPtZpbplyRBOZLskCXnhelO6EAVGJbfO0H"
"+KMo2IbesHjbswZfUpvw"
)

View File

@ -1,14 +1,13 @@
import json
import os
import pytest
from tests.unit_tests.monkey_island.cc.services.utils.cyphertexts_for_encryption_test import (
MALFORMED_CYPHER_TEXT_CORRUPTED,
MALFORMED_CYPHER_TEXT_TOO_SHORT,
)
from common.utils.exceptions import InvalidCredentialsError, NoCredentialsError
from monkey_island.cc.services.utils.config_encryption import decrypt_config, encrypt_config
from monkey_island.cc.services.utils.config_encryption import (
InvalidCredentialsError,
decrypt_config,
encrypt_config,
)
MONKEY_CONFIGS_DIR_PATH = "monkey_configs"
STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME = "monkey_config_standard.json"
@ -16,37 +15,23 @@ PASSWORD = "hello123"
INCORRECT_PASSWORD = "goodbye321"
@pytest.fixture
def plaintext_config(data_for_tests_dir):
plaintext_monkey_config_standard_path = os.path.join(
data_for_tests_dir, MONKEY_CONFIGS_DIR_PATH, STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME
)
plaintext_config = json.loads(open(plaintext_monkey_config_standard_path, "r").read())
return plaintext_config
def test_encrypt_decrypt_config(monkey_config):
encrypted_config = encrypt_config(monkey_config, PASSWORD)
assert decrypt_config(encrypted_config, PASSWORD) == monkey_config
def test_encrypt_decrypt_config(plaintext_config):
encrypted_config = encrypt_config(plaintext_config, PASSWORD)
assert decrypt_config(encrypted_config, PASSWORD) == plaintext_config
def test_encrypt_decrypt_config__wrong_password(plaintext_config):
encrypted_config = encrypt_config(plaintext_config, PASSWORD)
def test_encrypt_decrypt_config__wrong_password(monkey_config):
encrypted_config = encrypt_config(monkey_config, PASSWORD)
with pytest.raises(InvalidCredentialsError):
decrypt_config(encrypted_config, INCORRECT_PASSWORD)
def test_encrypt_decrypt_config__malformed_too_short():
with pytest.raises(ValueError):
decrypt_config(MALFORMED_CYPHER_TEXT_TOO_SHORT, PASSWORD)
def test_encrypt_decrypt_config__malformed_corrupted():
with pytest.raises(ValueError):
decrypt_config(MALFORMED_CYPHER_TEXT_CORRUPTED, PASSWORD)
def test_encrypt_decrypt_config__decrypt_no_password(plaintext_config):
encrypted_config = encrypt_config(plaintext_config, PASSWORD)
with pytest.raises(NoCredentialsError):
def test_encrypt_decrypt_config__decrypt_no_password(monkey_config):
encrypted_config = encrypt_config(monkey_config, PASSWORD)
with pytest.raises(InvalidCredentialsError):
decrypt_config(encrypted_config, "")