Merge pull request #1336 from guardicore/speed-up-unit-tests

Speed up unit tests
This commit is contained in:
Mike Salvatore 2021-07-20 09:04:51 -04:00 committed by GitHub
commit 5f3182298c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 154 additions and 72 deletions

View File

@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- MongoDb now gets launched by the Island via python. #1148
- Create/check data directory on Island init. #1170
- The formatting of some log messages to make them more readable. #1283
- Some unit tests to run faster. #1125
### Removed
- Relevant dead code as reported by Vulture. #1149

View File

@ -360,7 +360,7 @@ class ConfigService:
parent_config_arr = config_arr
config_arr = config_arr[config_key_part]
if isinstance(config_arr, collections.Sequence) and not isinstance(config_arr, str):
if isinstance(config_arr, collections.abc.Sequence) and not isinstance(config_arr, str):
for i in range(len(config_arr)):
# Check if array of shh key pairs and then decrypt
if isinstance(config_arr[i], dict) and "public_key" in config_arr[i]:

View File

@ -1,23 +0,0 @@
import os
import sys
from pathlib import Path
import pytest
MONKEY_BASE_PATH = str(Path(__file__).parent.parent)
sys.path.insert(0, MONKEY_BASE_PATH)
@pytest.fixture(scope="session")
def data_for_tests_dir(pytestconfig):
return Path(os.path.join(pytestconfig.rootdir, "monkey", "tests", "data_for_tests"))
@pytest.fixture(scope="session")
def stable_file(data_for_tests_dir) -> Path:
return data_for_tests_dir / "stable_file.txt"
@pytest.fixture(scope="session")
def stable_file_sha256_hash() -> str:
return "d9dcaadc91261692dafa86e7275b1bf39bb7e19d2efcfacd6fe2bfc9a1ae1062"

View File

@ -1,4 +1,27 @@
import os
import sys
from pathlib import Path
import pytest
from _pytest.monkeypatch import MonkeyPatch
MONKEY_BASE_PATH = str(Path(__file__).parent.parent.parent)
sys.path.insert(0, MONKEY_BASE_PATH)
@pytest.fixture(scope="session")
def data_for_tests_dir(pytestconfig):
return Path(os.path.join(pytestconfig.rootdir, "monkey", "tests", "data_for_tests"))
@pytest.fixture(scope="session")
def stable_file(data_for_tests_dir) -> Path:
return data_for_tests_dir / "stable_file.txt"
@pytest.fixture(scope="session")
def stable_file_sha256_hash() -> str:
return "d9dcaadc91261692dafa86e7275b1bf39bb7e19d2efcfacd6fe2bfc9a1ae1062"
@pytest.fixture
@ -6,3 +29,13 @@ def patched_home_env(monkeypatch, tmp_path):
monkeypatch.setenv("HOME", str(tmp_path))
return tmp_path
# The monkeypatch fixture is function scoped, so it cannot be used by session-scoped fixtures. This
# monkeypatch_session fixture can be session-scoped. For more information, see
# https://github.com/pytest-dev/pytest/issues/363#issuecomment-406536200
@pytest.fixture(scope="session")
def monkeypatch_session():
monkeypatch_ = MonkeyPatch()
yield monkeypatch_
monkeypatch_.undo()

View File

@ -1,6 +1,5 @@
import pytest
from infection_monkey.exploit.zerologon import ZerologonExploiter
from infection_monkey.model.host import VictimHost
DOMAIN_NAME = "domain-name"
@ -15,6 +14,8 @@ NT_HASHES = ["def456", "765vut"]
@pytest.fixture
def zerologon_exploiter_object(monkeypatch):
from infection_monkey.exploit.zerologon import ZerologonExploiter
def mock_report_login_attempt(**kwargs):
return None
@ -25,11 +26,13 @@ def zerologon_exploiter_object(monkeypatch):
return obj
@pytest.mark.slow
def test_assess_exploit_attempt_result_no_error(zerologon_exploiter_object):
dummy_exploit_attempt_result = {"ErrorCode": 0}
assert zerologon_exploiter_object.assess_exploit_attempt_result(dummy_exploit_attempt_result)
@pytest.mark.slow
def test_assess_exploit_attempt_result_with_error(zerologon_exploiter_object):
dummy_exploit_attempt_result = {"ErrorCode": 1}
assert not zerologon_exploiter_object.assess_exploit_attempt_result(
@ -37,6 +40,7 @@ def test_assess_exploit_attempt_result_with_error(zerologon_exploiter_object):
)
@pytest.mark.slow
def test_assess_restoration_attempt_result_restored(zerologon_exploiter_object):
dummy_restoration_attempt_result = object()
assert zerologon_exploiter_object.assess_restoration_attempt_result(
@ -44,6 +48,7 @@ def test_assess_restoration_attempt_result_restored(zerologon_exploiter_object):
)
@pytest.mark.slow
def test_assess_restoration_attempt_result_not_restored(zerologon_exploiter_object):
dummy_restoration_attempt_result = False
assert not zerologon_exploiter_object.assess_restoration_attempt_result(
@ -51,6 +56,7 @@ def test_assess_restoration_attempt_result_not_restored(zerologon_exploiter_obje
)
@pytest.mark.slow
def test__extract_user_creds_from_secrets_good_data(zerologon_exploiter_object):
mock_dumped_secrets = [
f"{USERS[i]}:{RIDS[i]}:{LM_HASHES[i]}:{NT_HASHES[i]}:::" for i in range(len(USERS))
@ -71,6 +77,7 @@ def test__extract_user_creds_from_secrets_good_data(zerologon_exploiter_object):
assert zerologon_exploiter_object._extracted_creds == expected_extracted_creds
@pytest.mark.slow
def test__extract_user_creds_from_secrets_bad_data(zerologon_exploiter_object):
mock_dumped_secrets = [
f"{USERS[i]}:{RIDS[i]}:::{LM_HASHES[i]}:{NT_HASHES[i]}:::" for i in range(len(USERS))

View File

@ -2,7 +2,6 @@ import pytest
from nmb.NetBIOS import NetBIOS
from common.utils.exceptions import DomainControllerNameFetchError
from infection_monkey.exploit.zerologon_utils.vuln_assessment import get_dc_details
from infection_monkey.model.host import VictimHost
DOMAIN_NAME = "domain-name"
@ -21,7 +20,10 @@ def _get_stub_queryIPForName(netbios_names):
return stub_queryIPForName
@pytest.mark.slow
def test_get_dc_details_multiple_netbios_names(host, monkeypatch):
from infection_monkey.exploit.zerologon_utils.vuln_assessment import get_dc_details
NETBIOS_NAMES = ["Name1", "Name2", "Name3"]
stub_queryIPForName = _get_stub_queryIPForName(NETBIOS_NAMES)
@ -33,7 +35,10 @@ def test_get_dc_details_multiple_netbios_names(host, monkeypatch):
assert dc_handle == f"\\\\{NETBIOS_NAMES[0]}"
@pytest.mark.slow
def test_get_dc_details_no_netbios_names(host, monkeypatch):
from infection_monkey.exploit.zerologon_utils.vuln_assessment import get_dc_details
NETBIOS_NAMES = []
stub_queryIPForName = _get_stub_queryIPForName(NETBIOS_NAMES)

View File

@ -2,7 +2,7 @@ import json
import pytest
from infection_monkey.exploit.wmiexec import WmiExploiter
from infection_monkey.exploit.sshexec import SSHExploiter
from infection_monkey.model.host import VictimHost
from infection_monkey.telemetry.exploit_telem import ExploitTelem
@ -19,10 +19,10 @@ HOST_AS_DICT = {
"default_tunnel": None,
"default_server": None,
}
EXPLOITER = WmiExploiter(HOST)
EXPLOITER_NAME = "WmiExploiter"
EXPLOITER = SSHExploiter(HOST)
EXPLOITER_NAME = "SSHExploiter"
EXPLOITER_INFO = {
"display_name": WmiExploiter._EXPLOITED_SERVICE,
"display_name": SSHExploiter._EXPLOITED_SERVICE,
"started": "",
"finished": "",
"vulnerable_urls": [],

View File

@ -1,6 +1,5 @@
import logging
import uuid
from time import sleep
import pytest
@ -24,9 +23,9 @@ class TestMonkey:
mia_monkey_ttl.save()
mia_monkey = Monkey(guid=str(uuid.uuid4()), dead=False, ttl_ref=mia_monkey_ttl.id)
mia_monkey.save()
# Emulate timeout - ttl is manually deleted here, since we're using mongomock and not a
# real mongo instance.
sleep(1)
mia_monkey_ttl.delete()
dead_monkey = Monkey(guid=str(uuid.uuid4()), dead=True)

View File

@ -9,12 +9,9 @@ import monkey_island.cc.resources.island_mode
from monkey_island.cc.services.representations import output_json
# We can't scope to module, because monkeypatch is a function scoped decorator.
# Potential solutions: https://github.com/pytest-dev/pytest/issues/363#issuecomment-406536200 or
# https://stackoverflow.com/questions/53963822/python-monkeypatch-setattr-with-pytest-fixture-at-module-scope
@pytest.fixture(scope="function")
def flask_client(monkeypatch):
monkeypatch.setattr(flask_jwt_extended, "verify_jwt_in_request", lambda: None)
@pytest.fixture(scope="session")
def flask_client(monkeypatch_session):
monkeypatch_session.setattr(flask_jwt_extended, "verify_jwt_in_request", lambda: None)
with mock_init_app().test_client() as client:
yield client

View File

@ -13,6 +13,7 @@ def test_is_config_encrypted__json(monkey_config_json):
assert not ConfigurationImport.is_config_encrypted(monkey_config_json)
@pytest.mark.slow
def test_is_config_encrypted__ciphertext(monkey_config_json):
encrypted_config = encrypt_string(monkey_config_json, PASSWORD)
assert ConfigurationImport.is_config_encrypted(encrypted_config)

View File

@ -1,14 +1,14 @@
from unittest import TestCase
import pytest
from monkey_island.cc.services.attack.mitre_api_interface import MitreApiInterface
class TestMitreApiInterface(TestCase):
def test_get_all_mitigations(self):
mitigations = MitreApiInterface.get_all_mitigations()
self.assertIsNotNone((len(mitigations.items()) >= 282))
mitigation = next(iter(mitigations.values()))
self.assertEqual(mitigation["type"], "course-of-action")
self.assertIsNotNone(mitigation["name"])
self.assertIsNotNone(mitigation["description"])
self.assertIsNotNone(mitigation["external_references"])
@pytest.mark.slow
def test_get_all_mitigations():
mitigations = MitreApiInterface.get_all_mitigations()
assert len(mitigations.items()) >= 282
mitigation = next(iter(mitigations.values()))
assert mitigation["type"] == "course-of-action"
assert mitigation["name"] is not None
assert mitigation["description"] is not None
assert mitigation["external_references"] is not None

View File

@ -23,14 +23,14 @@ def fake_mongo(monkeypatch):
@pytest.mark.usefixtures("uses_database")
def test_get_encrypted_files_table(fake_mongo, monkeypatch):
fake_mongo.db.monkey.insert(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert(EDGE_EXPLOITED)
fake_mongo.db.edge.insert(EDGE_SCANNED)
fake_mongo.db.telemetry.insert(ENCRYPTED)
fake_mongo.db.telemetry.insert(ENCRYPTED_2)
fake_mongo.db.telemetry.insert(ENCRYPTION_ERROR)
fake_mongo.db.telemetry.insert(ENCRYPTION_ONE_FILE)
fake_mongo.db.monkey.insert_one(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert_one(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert_one(EDGE_EXPLOITED)
fake_mongo.db.edge.insert_one(EDGE_SCANNED)
fake_mongo.db.telemetry.insert_one(ENCRYPTED)
fake_mongo.db.telemetry.insert_one(ENCRYPTED_2)
fake_mongo.db.telemetry.insert_one(ENCRYPTION_ERROR)
fake_mongo.db.telemetry.insert_one(ENCRYPTION_ONE_FILE)
monkeypatch.setattr(
ReportService,
@ -58,11 +58,11 @@ def test_get_encrypted_files_table(fake_mongo, monkeypatch):
@pytest.mark.usefixtures("uses_database")
def test_get_encrypted_files_table__only_errors(fake_mongo, monkeypatch):
fake_mongo.db.monkey.insert(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert(EDGE_EXPLOITED)
fake_mongo.db.edge.insert(EDGE_SCANNED)
fake_mongo.db.telemetry.insert(ENCRYPTION_ERROR)
fake_mongo.db.monkey.insert_one(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert_one(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert_one(EDGE_EXPLOITED)
fake_mongo.db.edge.insert_one(EDGE_SCANNED)
fake_mongo.db.telemetry.insert_one(ENCRYPTION_ERROR)
monkeypatch.setattr(
ReportService,
@ -84,10 +84,10 @@ def test_get_encrypted_files_table__only_errors(fake_mongo, monkeypatch):
@pytest.mark.usefixtures("uses_database")
def test_get_encrypted_files_table__no_telemetries(fake_mongo, monkeypatch):
fake_mongo.db.monkey.insert(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert(EDGE_EXPLOITED)
fake_mongo.db.edge.insert(EDGE_SCANNED)
fake_mongo.db.monkey.insert_one(MONKEY_AT_ISLAND)
fake_mongo.db.monkey.insert_one(MONKEY_AT_VICTIM)
fake_mongo.db.edge.insert_one(EDGE_EXPLOITED)
fake_mongo.db.edge.insert_one(EDGE_SCANNED)
monkeypatch.setattr(
ReportService,

View File

@ -1,3 +1,61 @@
VALID_CIPHER_TEXT = (
"QUVTAgAAG0NSRUFURURfQlkAcHlBZXNDcnlwdCA2LjAuMACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAA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UJpsoflmxEzdqaHlWrqJ6IK5knjv8PREY1Cf0mXVE7bmsSyonI7Tu0JhkRquN"
"8T+Eg1I7DGsqO3buWmAiulN/TTqC92uid3c+PiSGXJ6nEQ+RDlwwd2iq/wmDAu8hq6AbW6wA3Atu7xKQC0xkD2RhzF9yIu"
"t9tNYNWWRl14tjwmfvurE65F0mMqgbLhepQ3ajYXqSOytOBNxlrhpGJ7ZFngNiRLP90jYOcZ4tWIMpt5XPCDQXiehtvU+M"
"zRoDfKjtSXbux9/w92es+2nVJUxrWQPvjsoRphYK6eVO5FbClmc+w7np2ugFZ231isdHYaMRe4VaXA7YkVqMuiBY4ZXrnA"
"vtBZRzNGgSoFMmHQ0WebwipLXjJpLoQDktWItFbY1AI5MeJDu1fLR6EK9c5opCk/doK9RozfPfyinh9oBfZ3ZmSdY1WOxj"
"LGc3QmCXFbxapAFNdzS8satGjn/VV1ZbhZBU7fzW1auiRxk1H0/CjWK0w1g2KQ2DRPG2vPpLAJVjy3cyNn0oS6YgDStDN2"
"fUtRYH1oBt6cIeW4K8Mp7I1fD+Wa45ZFonmeeuBj53S6k+Ov2aX5cIUeRrB4tvmkBosYdL9N+lr1wORZLj2us8IWmnlKh4"
"nmV0tcZxh5kBZW1vgP+LWHEN4ialItBPmsggRWqyBSVTr8tbtLEaJrlZ2NXiUFhcVJkggItwU02Ueesvjpjngfd/UluO/d"
"5pnm3dizp6Q="
)
MALFORMED_CIPHER_TEXT_CORRUPTED = (
"QUVTAgAAGM0NKEYTESTURfQlkAcHlBZXNDcnlwdCA2LjAuMACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

View File

@ -1,6 +1,7 @@
import pytest
from tests.unit_tests.monkey_island.cc.services.utils.ciphertexts_for_encryption_test import (
MALFORMED_CIPHER_TEXT_CORRUPTED,
VALID_CIPHER_TEXT,
)
from monkey_island.cc.services.utils.encryption import (
@ -15,23 +16,25 @@ PASSWORD = "hello123"
INCORRECT_PASSWORD = "goodbye321"
@pytest.mark.slow
def test_encrypt_decrypt_string(monkey_config_json):
encrypted_config = encrypt_string(monkey_config_json, PASSWORD)
assert decrypt_ciphertext(encrypted_config, PASSWORD) == monkey_config_json
def test_encrypt_decrypt_string__wrong_password(monkey_config_json):
encrypted_config = encrypt_string(monkey_config_json, PASSWORD)
@pytest.mark.slow
def test_decrypt_string__wrong_password(monkey_config_json):
with pytest.raises(InvalidCredentialsError):
decrypt_ciphertext(encrypted_config, INCORRECT_PASSWORD)
decrypt_ciphertext(VALID_CIPHER_TEXT, INCORRECT_PASSWORD)
def test_encrypt_decrypt_string__malformed_corrupted():
@pytest.mark.slow
def test_decrypt_string__malformed_corrupted():
with pytest.raises(ValueError):
decrypt_ciphertext(MALFORMED_CIPHER_TEXT_CORRUPTED, PASSWORD)
def test_encrypt_decrypt_string__decrypt_no_password(monkey_config_json):
encrypted_config = encrypt_string(monkey_config_json, PASSWORD)
@pytest.mark.slow
def test_decrypt_string__no_password(monkey_config_json):
with pytest.raises(InvalidCredentialsError):
decrypt_ciphertext(encrypted_config, "")
decrypt_ciphertext(VALID_CIPHER_TEXT, "")

View File

@ -21,6 +21,7 @@ log_cli_format = "%(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d
log_cli_date_format = "%H:%M:%S"
addopts = "-v --capture=sys tests/unit_tests"
norecursedirs = "node_modules dist"
markers = ["slow: mark test as slow"]
[tool.vulture]
exclude = ["monkey/monkey_island/cc/ui/", "monkey/tests/"]