-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up unit tests #1336
Speed up unit tests #1336
Changes from all commits
e12bc7a
2897755
5222230
162e375
ac9bd8d
f0033d0
ac52c30
41cf0f0
845c9d9
2496ed0
d9a1f22
adb1006
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
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 | ||
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
import pytest | ||
|
||
from infection_monkey.exploit.wmiexec import WmiExploiter | ||
from infection_monkey.exploit.sshexec import SSHExploiter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing the exploiter ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See commit messages: 2496ed0 |
||
from infection_monkey.model.host import VictimHost | ||
from infection_monkey.telemetry.exploit_telem import ExploitTelem | ||
|
||
|
@@ -19,10 +19,10 @@ | |
"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": [], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import logging | ||
import uuid | ||
from time import sleep | ||
|
||
import pytest | ||
|
||
|
@@ -24,9 +23,9 @@ def test_is_dead(self): | |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this here in the first place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¯\(ツ)/¯ |
||
mia_monkey_ttl.delete() | ||
|
||
dead_monkey = Monkey(guid=str(uuid.uuid4()), dead=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale behind this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.