Merge pull request #1094 from shreyamalviya/unit-test-files-consistency

Unit test files consistency
This commit is contained in:
Mike Salvatore 2021-04-14 08:49:16 -04:00 committed by GitHub
commit 286dab5c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 45 additions and 43 deletions

View File

@ -81,7 +81,7 @@
"type": "snippet", "type": "snippet",
"path": "monkey/monkey_island/cc/services/config_schema/definitions/post_breach_actions.py", "path": "monkey/monkey_island/cc/services/config_schema/definitions/post_breach_actions.py",
"comments": [], "comments": [],
"firstLineNumber": 4, "firstLineNumber": 5,
"lines": [ "lines": [
" \"might do after breaching a new machine. Used in ATT&CK and Zero trust reports.\",", " \"might do after breaching a new machine. Used in ATT&CK and Zero trust reports.\",",
" \"type\": \"string\",", " \"type\": \"string\",",
@ -113,7 +113,7 @@
"monkey/common/common_consts/post_breach_consts.py": "25e6679cb1623aae1a732deb05cc011a452743e3", "monkey/common/common_consts/post_breach_consts.py": "25e6679cb1623aae1a732deb05cc011a452743e3",
"monkey/infection_monkey/post_breach/actions/add_user.py": "cae5a2428fa01b333a2e70365c9da1e189e31bc4", "monkey/infection_monkey/post_breach/actions/add_user.py": "cae5a2428fa01b333a2e70365c9da1e189e31bc4",
"monkey/monkey_island/cc/services/attack/technique_reports/T1136.py": "dfc5945a362b88c1135f4476526c6c82977b02ee", "monkey/monkey_island/cc/services/attack/technique_reports/T1136.py": "dfc5945a362b88c1135f4476526c6c82977b02ee",
"monkey/monkey_island/cc/services/config_schema/definitions/post_breach_actions.py": "ea9b18aba7f71da12c9c82ac39d8a0cf2c472a9c" "monkey/monkey_island/cc/services/config_schema/definitions/post_breach_actions.py": "086dc85693ae02ddfa106099245c0f155139805c"
} }
} }
} }

View File

@ -6,7 +6,7 @@ from .aws_service import filter_instance_data_from_aws_response
__author__ = "shay.nehmad" __author__ = "shay.nehmad"
class TestFilterInstanceDataFromAwsResponse(TestCase): class TestAwsService(TestCase):
def test_filter_instance_data_from_aws_response(self): def test_filter_instance_data_from_aws_response(self):
json_response_full = """ json_response_full = """
{ {

View File

@ -4,7 +4,7 @@ from common.network.network_range import CidrRange, SingleIpRange
from infection_monkey.model.victim_host_generator import VictimHostGenerator from infection_monkey.model.victim_host_generator import VictimHostGenerator
class VictimHostGeneratorTester(TestCase): class TestVictimHostGenerator(TestCase):
def setUp(self): def setUp(self):
self.cidr_range = CidrRange("10.0.0.0/28", False) # this gives us 15 hosts self.cidr_range = CidrRange("10.0.0.0/28", False) # this gives us 15 hosts
self.local_host_range = SingleIpRange("localhost") self.local_host_range = SingleIpRange("localhost")

View File

@ -1,4 +1,4 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin # noqa: F401 from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester # noqa: F401
class SomeDummyPlugin: class SomeDummyPlugin:

View File

@ -1,6 +1,6 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester
class BadPluginInit(TestPlugin): class BadPluginInit(PluginTester):
def __init__(self): def __init__(self):
raise Exception("TestException") raise Exception("TestException")

View File

@ -1,14 +1,14 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester
class NoInheritance: class NoInheritance:
pass pass
class BadInit(TestPlugin): class BadInit(PluginTester):
def __init__(self): def __init__(self):
raise Exception("TestException") raise Exception("TestException")
class ProperClass(TestPlugin): class ProperClass(PluginTester):
pass pass

View File

@ -2,7 +2,7 @@ import infection_monkey.utils.plugins.pluginTests
from infection_monkey.utils.plugins.plugin import Plugin from infection_monkey.utils.plugins.plugin import Plugin
class TestPlugin(Plugin): class PluginTester(Plugin):
classes_to_load = [] classes_to_load = []
@staticmethod @staticmethod
@ -11,7 +11,7 @@ class TestPlugin(Plugin):
Decides if post breach action is enabled in config Decides if post breach action is enabled in config
:return: True if it needs to be ran, false otherwise :return: True if it needs to be ran, false otherwise
""" """
return class_name in TestPlugin.classes_to_load return class_name in PluginTester.classes_to_load
@staticmethod @staticmethod
def base_package_file(): def base_package_file():

View File

@ -1,5 +1,5 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester
class PluginWorking(TestPlugin): class PluginWorking(PluginTester):
pass pass

View File

@ -3,33 +3,33 @@ from unittest import TestCase
from infection_monkey.utils.plugins.pluginTests.BadImport import SomeDummyPlugin from infection_monkey.utils.plugins.pluginTests.BadImport import SomeDummyPlugin
from infection_monkey.utils.plugins.pluginTests.BadInit import BadPluginInit from infection_monkey.utils.plugins.pluginTests.BadInit import BadPluginInit
from infection_monkey.utils.plugins.pluginTests.ComboFile import BadInit, ProperClass from infection_monkey.utils.plugins.pluginTests.ComboFile import BadInit, ProperClass
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester
from infection_monkey.utils.plugins.pluginTests.PluginWorking import PluginWorking from infection_monkey.utils.plugins.pluginTests.PluginWorking import PluginWorking
class PluginTester(TestCase): class TestPlugin(TestCase):
def test_combo_file(self): def test_combo_file(self):
TestPlugin.classes_to_load = [BadInit.__name__, ProperClass.__name__] PluginTester.classes_to_load = [BadInit.__name__, ProperClass.__name__]
to_init = TestPlugin.get_classes() to_init = PluginTester.get_classes()
self.assertEqual(len(to_init), 2) self.assertEqual(len(to_init), 2)
objects = TestPlugin.get_instances() objects = PluginTester.get_instances()
self.assertEqual(len(objects), 1) self.assertEqual(len(objects), 1)
def test_bad_init(self): def test_bad_init(self):
TestPlugin.classes_to_load = [BadPluginInit.__name__] PluginTester.classes_to_load = [BadPluginInit.__name__]
to_init = TestPlugin.get_classes() to_init = PluginTester.get_classes()
self.assertEqual(len(to_init), 1) self.assertEqual(len(to_init), 1)
objects = TestPlugin.get_instances() objects = PluginTester.get_instances()
self.assertEqual(len(objects), 0) self.assertEqual(len(objects), 0)
def test_bad_import(self): def test_bad_import(self):
TestPlugin.classes_to_load = [SomeDummyPlugin.__name__] PluginTester.classes_to_load = [SomeDummyPlugin.__name__]
to_init = TestPlugin.get_classes() to_init = PluginTester.get_classes()
self.assertEqual(len(to_init), 0) self.assertEqual(len(to_init), 0)
def test_flow(self): def test_flow(self):
TestPlugin.classes_to_load = [PluginWorking.__name__] PluginTester.classes_to_load = [PluginWorking.__name__]
to_init = TestPlugin.get_classes() to_init = PluginTester.get_classes()
self.assertEqual(len(to_init), 1) self.assertEqual(len(to_init), 1)
objects = TestPlugin.get_instances() objects = PluginTester.get_instances()
self.assertEqual(len(objects), 1) self.assertEqual(len(objects), 1)

View File

@ -12,6 +12,12 @@ from monkey_island.cc.resources.attack.attack_config import AttackConfiguration
from monkey_island.cc.resources.attack.attack_report import AttackReport from monkey_island.cc.resources.attack.attack_report import AttackReport
from monkey_island.cc.resources.auth.auth import Authenticate, init_jwt from monkey_island.cc.resources.auth.auth import Authenticate, init_jwt
from monkey_island.cc.resources.auth.registration import Registration from monkey_island.cc.resources.auth.registration import Registration
from monkey_island.cc.resources.blackbox.clear_caches import ClearCaches
from monkey_island.cc.resources.blackbox.log_blackbox_endpoint import LogBlackboxEndpoint
from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyBlackboxEndpoint
from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import (
TelemetryBlackboxEndpoint,
)
from monkey_island.cc.resources.bootloader import Bootloader from monkey_island.cc.resources.bootloader import Bootloader
from monkey_island.cc.resources.client_run import ClientRun from monkey_island.cc.resources.client_run import ClientRun
from monkey_island.cc.resources.edge import Edge from monkey_island.cc.resources.edge import Edge
@ -36,10 +42,6 @@ from monkey_island.cc.resources.security_report import SecurityReport
from monkey_island.cc.resources.T1216_pba_file_download import T1216PBAFileDownload from monkey_island.cc.resources.T1216_pba_file_download import T1216PBAFileDownload
from monkey_island.cc.resources.telemetry import Telemetry from monkey_island.cc.resources.telemetry import Telemetry
from monkey_island.cc.resources.telemetry_feed import TelemetryFeed from monkey_island.cc.resources.telemetry_feed import TelemetryFeed
from monkey_island.cc.resources.test.clear_caches import ClearCaches
from monkey_island.cc.resources.test.log_test import LogTest
from monkey_island.cc.resources.test.monkey_test import MonkeyTest
from monkey_island.cc.resources.test.telemetry_test import TelemetryTest
from monkey_island.cc.resources.version_update import VersionUpdate from monkey_island.cc.resources.version_update import VersionUpdate
from monkey_island.cc.resources.zero_trust.finding_event import ZeroTrustFindingEvent from monkey_island.cc.resources.zero_trust.finding_event import ZeroTrustFindingEvent
from monkey_island.cc.resources.zero_trust.scoutsuite_auth.aws_keys import AWSKeys from monkey_island.cc.resources.zero_trust.scoutsuite_auth.aws_keys import AWSKeys
@ -165,10 +167,10 @@ def init_api_resources(api):
api.add_resource(AWSKeys, "/api/aws_keys") api.add_resource(AWSKeys, "/api/aws_keys")
# Resources used by black box tests # Resources used by black box tests
api.add_resource(MonkeyTest, "/api/test/monkey") api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey")
api.add_resource(ClearCaches, "/api/test/clear_caches") api.add_resource(ClearCaches, "/api/test/clear_caches")
api.add_resource(LogTest, "/api/test/log") api.add_resource(LogBlackboxEndpoint, "/api/test/log")
api.add_resource(TelemetryTest, "/api/test/telemetry") api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry")
def init_app(mongo_url): def init_app(mongo_url):

View File

@ -6,7 +6,7 @@ from monkey_island.cc.database import database, mongo
from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.auth.auth import jwt_required
class LogTest(flask_restful.Resource): class LogBlackboxEndpoint(flask_restful.Resource):
@jwt_required @jwt_required
def get(self): def get(self):
find_query = json_util.loads(request.args.get("find_query")) find_query = json_util.loads(request.args.get("find_query"))

View File

@ -6,7 +6,7 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.auth.auth import jwt_required
class MonkeyTest(flask_restful.Resource): class MonkeyBlackboxEndpoint(flask_restful.Resource):
@jwt_required @jwt_required
def get(self, **kw): def get(self, **kw):
find_query = json_util.loads(request.args.get("find_query")) find_query = json_util.loads(request.args.get("find_query"))

View File

@ -6,7 +6,7 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.auth.auth import jwt_required
class TelemetryTest(flask_restful.Resource): class TelemetryBlackboxEndpoint(flask_restful.Resource):
@jwt_required @jwt_required
def get(self, **kw): def get(self, **kw):
find_query = json_util.loads(request.args.get("find_query")) find_query = json_util.loads(request.args.get("find_query"))

View File

@ -6,7 +6,7 @@ from flask import request
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.auth.auth import jwt_required
from monkey_island.cc.resources.test.utils.telem_store import TestTelemStore from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
from monkey_island.cc.services.log import LogService from monkey_island.cc.services.log import LogService
from monkey_island.cc.services.node import NodeService from monkey_island.cc.services.node import NodeService

View File

@ -7,7 +7,7 @@ from flask import request
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.models.monkey_ttl import create_monkey_ttl_document from monkey_island.cc.models.monkey_ttl import create_monkey_ttl_document
from monkey_island.cc.resources.test.utils.telem_store import TestTelemStore from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS
from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.services.edge.edge import EdgeService from monkey_island.cc.services.edge.edge import EdgeService

View File

@ -10,7 +10,7 @@ from common.common_consts.telem_categories import TelemCategoryEnum
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.models.monkey import Monkey from monkey_island.cc.models.monkey import Monkey
from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.auth.auth import jwt_required
from monkey_island.cc.resources.test.utils.telem_store import TestTelemStore from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
from monkey_island.cc.services.node import NodeService from monkey_island.cc.services.node import NodeService
from monkey_island.cc.services.telemetry.processing.processing import process_telemetry from monkey_island.cc.services.telemetry.processing.processing import process_telemetry

View File

@ -4,7 +4,7 @@ from datetime import datetime
from flask import jsonify from flask import jsonify
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.resources.test.utils.telem_store import TestTelemStore from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.services.node import NodeService from monkey_island.cc.services.node import NodeService
from monkey_island.cc.services.reporting.report import ReportService from monkey_island.cc.services.reporting.report import ReportService

View File

@ -6,7 +6,7 @@ import bson
from monkey_island.cc.services.representations import normalize_obj from monkey_island.cc.services.representations import normalize_obj
class TestJsonRepresentations(TestCase): class TestRepresentations(TestCase):
def test_normalize_obj(self): def test_normalize_obj(self):
# empty # empty
self.assertEqual({}, normalize_obj({})) self.assertEqual({}, normalize_obj({}))

View File

@ -3,7 +3,7 @@ from unittest import TestCase
from monkey_island.cc.services.utils.node_states import NodeStates, NoGroupsFoundException from monkey_island.cc.services.utils.node_states import NodeStates, NoGroupsFoundException
class TestNodeGroups(TestCase): class TestNodeStates(TestCase):
def test_get_group_by_keywords(self): def test_get_group_by_keywords(self):
self.assertEqual(NodeStates.get_by_keywords(["island"]), NodeStates.ISLAND) self.assertEqual(NodeStates.get_by_keywords(["island"]), NodeStates.ISLAND)
self.assertEqual( self.assertEqual(