예제 #1
0
    def Run(self):
        ref = rdf_hunts.FlowLikeObjectReference(
            object_type="FLOW_REFERENCE",
            flow_reference=rdf_objects.FlowReference(
                flow_id="F:332211", client_id="C.1111111111111111"))

        if data_store.RelationalDBReadEnabled("hunts"):
            with test_lib.FakeTime(42):
                hunt_id = self.CreateHunt(description="the hunt",
                                          original_object=ref)
                hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
                hunt_obj.client_resources_stats.user_cpu_stats.sum = 5000
                hunt_obj.client_resources_stats.network_bytes_sent_stats.sum = 1000000
                data_store.REL_DB.WriteHuntObject(hunt_obj)
        else:
            with test_lib.FakeTime(42):
                with self.CreateHunt(description="the hunt",
                                     original_object=ref) as hunt_obj:
                    hunt_id = hunt_obj.urn.Basename()

                    hunt_stats = hunt_obj.context.usage_stats
                    hunt_stats.user_cpu_stats.sum = 5000
                    hunt_stats.network_bytes_sent_stats.sum = 1000000

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
예제 #2
0
    def Run(self):
        with test_lib.FakeTime(42):
            # TODO(user): make hunt stats non-zero when AFF4 is gone to
            # improve test coverage.
            hunt_id = self.CreateHunt(description="the hunt")

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
예제 #3
0
    def Run(self):
        with test_lib.FakeTime(42):
            with self.CreateHunt(description="the hunt") as hunt_obj:
                hunt_urn = hunt_obj.urn

                hunt_stats = hunt_obj.context.usage_stats
                hunt_stats.user_cpu_stats.sum = 5000
                hunt_stats.network_bytes_sent_stats.sum = 1000000

        self.Check(
            "GetHunt",
            args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_urn.Basename()),
            replace={hunt_urn.Basename(): "H:123456"})
예제 #4
0
파일: hunt_test.py 프로젝트: sec-js/grr
    def testHuntDuration(self):
        duration = rdfvalue.Duration.From(42, rdfvalue.MINUTES)
        hunt_obj = rdf_hunt_objects.Hunt()
        hunt_obj.hunt_id = "12345678"
        hunt_obj.duration = duration
        data_store.REL_DB.WriteHuntObject(hunt_obj)

        args = hunt_plugin.ApiGetHuntArgs()
        args.hunt_id = "12345678"

        hunt_api_obj = self.handler.Handle(args, token=self.token)
        self.assertEqual(hunt_api_obj.duration, duration)
        self.assertEqual(hunt_api_obj.hunt_runner_args.expiry_time, duration)
예제 #5
0
    def Run(self):
        with test_lib.FakeTime(42):
            # TODO(user): make hunt stats non-zero when AFF4 is gone to
            # improve test coverage.
            if data_store.RelationalDBEnabled():
                hunt_id = self.CreateHunt(description="the hunt")
            else:
                with self.CreateHunt(description="the hunt") as hunt_obj:
                    hunt_urn = hunt_obj.urn
                    hunt_id = hunt_urn.Basename()

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
예제 #6
0
    def Run(self):
        ref = rdf_hunts.FlowLikeObjectReference(
            object_type="HUNT_REFERENCE",
            hunt_reference=rdf_objects.HuntReference(hunt_id="H:332211"))

        # TODO(user): make hunt stats non-zero when AFF4 is gone to
        # improve test coverage.
        with test_lib.FakeTime(42):
            hunt_id = self.CreateHunt(description="the hunt",
                                      original_object=ref)

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
예제 #7
0
    def Run(self):
        with test_lib.FakeTime(42):
            ref = rdf_hunts.FlowLikeObjectReference(
                object_type="HUNT_REFERENCE",
                hunt_reference=rdf_objects.HuntReference(hunt_id="H:332211"))
            with self.CreateHunt(description="the hunt",
                                 original_object=ref) as hunt_obj:
                hunt_urn = hunt_obj.urn

                hunt_stats = hunt_obj.context.usage_stats
                hunt_stats.user_cpu_stats.sum = 5000
                hunt_stats.network_bytes_sent_stats.sum = 1000000

        self.Check(
            "GetHunt",
            args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_urn.Basename()),
            replace={hunt_urn.Basename(): "H:123456"})
예제 #8
0
    def Run(self):
        ref = rdf_hunts.FlowLikeObjectReference(
            object_type="HUNT_REFERENCE",
            hunt_reference=rdf_objects.HuntReference(hunt_id="H:332211"))

        if data_store.RelationalDBReadEnabled("hunts"):
            # TODO(user): make hunt stats non-zero when AFF4 is gone to
            # improve test coverage.
            with test_lib.FakeTime(42):
                hunt_id = self.CreateHunt(description="the hunt",
                                          original_object=ref)
        else:
            with test_lib.FakeTime(42):
                with self.CreateHunt(description="the hunt",
                                     original_object=ref) as hunt_obj:
                    hunt_id = hunt_obj.urn.Basename()

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
예제 #9
0
    def Run(self):
        with test_lib.FakeTime(42):
            if data_store.RelationalDBReadEnabled("hunts"):
                hunt_id = self.CreateHunt(description="the hunt")
                hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
                hunt_obj.client_resources_stats.user_cpu_stats.sum = 5000
                hunt_obj.client_resources_stats.network_bytes_sent_stats.sum = 1000000
                data_store.REL_DB.WriteHuntObject(hunt_obj)

            else:
                with self.CreateHunt(description="the hunt") as hunt_obj:
                    hunt_urn = hunt_obj.urn

                    hunt_stats = hunt_obj.context.usage_stats
                    hunt_stats.user_cpu_stats.sum = 5000
                    hunt_stats.network_bytes_sent_stats.sum = 1000000

                    hunt_id = hunt_urn.Basename()

        self.Check("GetHunt",
                   args=hunt_plugin.ApiGetHuntArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})