示例#1
0
    def test_generate_map_nodes(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        self.assertEqual(PTHReportService.generate_map_nodes(), [])

        windows_monkey_with_services = Monkey(
            guid=str(uuid.uuid4()),
            hostname="A_Windows_PC_1",
            critical_services=["aCriticalService", "Domain Controller"],
            ip_addresses=["1.1.1.1", "2.2.2.2"],
            description="windows 10")
        windows_monkey_with_services.save()

        windows_monkey_with_no_services = Monkey(guid=str(uuid.uuid4()),
                                                 hostname="A_Windows_PC_2",
                                                 critical_services=[],
                                                 ip_addresses=["3.3.3.3"],
                                                 description="windows 10")
        windows_monkey_with_no_services.save()

        linux_monkey = Monkey(guid=str(uuid.uuid4()),
                              hostname="A_Linux_PC",
                              ip_addresses=["4.4.4.4"],
                              description="linux ubuntu")
        linux_monkey.save()

        map_nodes = PTHReportService.generate_map_nodes()

        self.assertEquals(2, len(map_nodes))
    def test_dispatch_to_relevant_collector(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        a_monkey = Monkey(guid=str(uuid.uuid4()))
        a_monkey.save()

        dispatcher = SystemInfoTelemetryDispatcher()

        # JSON with results - make sure functions are called
        instance_id = "i-0bd2c14bd4c7d703f"
        telem_json = {
            "data": {
                "collectors": {
                    "AwsCollector": {
                        "instance_id": instance_id
                    },
                }
            },
            "monkey_guid": a_monkey.guid
        }
        dispatcher.dispatch_collector_results_to_relevant_processors(
            telem_json)

        self.assertEquals(
            Monkey.get_single_monkey_by_guid(a_monkey.guid).aws_instance_id,
            instance_id)
    def test_create_findings_for_all_done_pairs(self):
        self.fail_if_not_testing_env()
        self.clean_finding_db()

        all_subnets = [FIRST_SUBNET, SECOND_SUBNET, THIRD_SUBNET]

        monkey = Monkey(guid=str(uuid.uuid4()), ip_addresses=[FIRST_SUBNET])

        # no findings
        self.assertEquals(len(Finding.objects(test=TEST_SEGMENTATION)), 0)

        # This is like the monkey is done and sent done telem
        create_or_add_findings_for_all_pairs(all_subnets, monkey)

        # There are 2 subnets in which the monkey is NOT
        self.assertEquals(
            len(Finding.objects(test=TEST_SEGMENTATION, status=STATUS_PASSED)),
            2)

        # This is a monkey from 2nd subnet communicated with 1st subnet.
        SegmentationFinding.create_or_add_to_existing_finding(
            [FIRST_SUBNET, SECOND_SUBNET], STATUS_FAILED,
            Event.create_event(title="sdf",
                               message="asd",
                               event_type=EVENT_TYPE_MONKEY_NETWORK))

        self.assertEquals(
            len(Finding.objects(test=TEST_SEGMENTATION, status=STATUS_PASSED)),
            1)
        self.assertEquals(
            len(Finding.objects(test=TEST_SEGMENTATION, status=STATUS_FAILED)),
            1)
        self.assertEquals(len(Finding.objects(test=TEST_SEGMENTATION)), 2)
示例#4
0
    def test_process_environment_telemetry(self):
        # Arrange
        monkey_guid = str(uuid.uuid4())
        a_monkey = Monkey(guid=monkey_guid)
        a_monkey.save()
        dispatcher = SystemInfoTelemetryDispatcher()

        on_premise = "On Premise"
        telem_json = {
            "data": {
                "collectors": {
                    "EnvironmentCollector": {"environment": on_premise},
                }
            },
            "monkey_guid": monkey_guid
        }
        dispatcher.dispatch_collector_results_to_relevant_processors(telem_json)

        assert Monkey.get_single_monkey_by_guid(monkey_guid).environment == on_premise
示例#5
0
    def test_generate_map_nodes_parsing(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        monkey_id = str(uuid.uuid4())
        hostname = "A_Windows_PC_1"
        windows_monkey_with_services = Monkey(
            guid=monkey_id,
            hostname=hostname,
            critical_services=["aCriticalService", "Domain Controller"],
            ip_addresses=["1.1.1.1"],
            description="windows 10")
        windows_monkey_with_services.save()

        map_nodes = PTHReportService.generate_map_nodes()

        self.assertEquals(map_nodes[0]["id"], monkey_id)
        self.assertEquals(map_nodes[0]["label"], "A_Windows_PC_1 : 1.1.1.1")
        self.assertEquals(map_nodes[0]["group"], "critical")
        self.assertEquals(len(map_nodes[0]["services"]), 2)
        self.assertEquals(map_nodes[0]["hostname"], hostname)