def Run(self):
    with test_lib.FakeTime(42):
      hunt_id = self.CreateHunt(creator=self.token.username)

    client_id = self.SetupClient(0)
    flow_id = flow_test_lib.StartFlow(
        flows_processes.ListProcesses,
        client_id=client_id,
        parent_hunt_id=hunt_id)

    with test_lib.FakeTime(52):
      data_store.REL_DB.WriteFlowLogEntries([
          rdf_flow_objects.FlowLogEntry(
              client_id=client_id,
              flow_id=flow_id,
              hunt_id=hunt_id,
              message="Sample message: foo")
      ])

    with test_lib.FakeTime(55):
      data_store.REL_DB.WriteFlowLogEntries([
          rdf_flow_objects.FlowLogEntry(
              client_id=client_id,
              flow_id=flow_id,
              hunt_id=hunt_id,
              message="Sample message: bar")
      ])

    self.Check(
        "ListHuntLogs",
        args=hunt_plugin.ApiListHuntLogsArgs(hunt_id=hunt_id),
        replace={hunt_id: "H:123456"})
    self.Check(
        "ListHuntLogs",
        args=hunt_plugin.ApiListHuntLogsArgs(hunt_id=hunt_id, count=1),
        replace={hunt_id: "H:123456"})
    self.Check(
        "ListHuntLogs",
        args=hunt_plugin.ApiListHuntLogsArgs(
            hunt_id=hunt_id, offset=1, count=1),
        replace={hunt_id: "H:123456"})
Esempio n. 2
0
    def Run(self):
        with test_lib.FakeTime(42):
            with self.CreateHunt(description="the hunt") as hunt_obj:

                with test_lib.FakeTime(52):
                    hunt_obj.Log("Sample message: foo.")

                with test_lib.FakeTime(55):
                    hunt_obj.Log("Sample message: bar.")

        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(
                       hunt_id=hunt_obj.urn.Basename()),
                   replace={hunt_obj.urn.Basename(): "H:123456"})
        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(
                       hunt_id=hunt_obj.urn.Basename(), count=1),
                   replace={hunt_obj.urn.Basename(): "H:123456"})
        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(
                       hunt_id=hunt_obj.urn.Basename(), offset=1, count=1),
                   replace={hunt_obj.urn.Basename(): "H:123456"})
Esempio n. 3
0
    def Run(self):
        if data_store.RelationalDBEnabled():
            with test_lib.FakeTime(42):
                hunt_id = self.CreateHunt()

            client_id = self.SetupClient(0).Basename()
            flow_id = flow_test_lib.StartFlow(flows_processes.ListProcesses,
                                              client_id=client_id,
                                              parent_hunt_id=hunt_id)

            with test_lib.FakeTime(52):
                data_store.REL_DB.WriteFlowLogEntries([
                    rdf_flow_objects.FlowLogEntry(
                        client_id=client_id,
                        flow_id=flow_id,
                        hunt_id=hunt_id,
                        message="Sample message: foo")
                ])

            with test_lib.FakeTime(55):
                data_store.REL_DB.WriteFlowLogEntries([
                    rdf_flow_objects.FlowLogEntry(
                        client_id=client_id,
                        flow_id=flow_id,
                        hunt_id=hunt_id,
                        message="Sample message: bar")
                ])
        else:
            with test_lib.FakeTime(42):
                client_id = self.SetupClient(0)
                flow_id = "H:123456"
                with self.CreateHunt(description="the hunt") as hunt_obj:
                    hunt_id = hunt_obj.urn.Basename()
                    logs_collection_urn = hunt_obj.logs_collection_urn

                log_entry = rdf_flows.FlowLog(
                    client_id=client_id,
                    urn=client_id.Add(flow_id),
                    flow_name=hunt_obj.__class__.__name__,
                    log_message="Sample message: foo")
                with test_lib.FakeTime(52):
                    with data_store.DB.GetMutationPool() as pool:
                        grr_collections.LogCollection.StaticAdd(
                            logs_collection_urn, log_entry, mutation_pool=pool)

                log_entry = rdf_flows.FlowLog(
                    client_id=client_id,
                    urn=client_id.Add(flow_id),
                    flow_name=hunt_obj.__class__.__name__,
                    log_message="Sample message: bar")
                with test_lib.FakeTime(55):
                    with data_store.DB.GetMutationPool() as pool:
                        grr_collections.LogCollection.StaticAdd(
                            logs_collection_urn, log_entry, mutation_pool=pool)

        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(hunt_id=hunt_id),
                   replace={hunt_id: "H:123456"})
        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(hunt_id=hunt_id,
                                                        count=1),
                   replace={hunt_id: "H:123456"})
        self.Check("ListHuntLogs",
                   args=hunt_plugin.ApiListHuntLogsArgs(hunt_id=hunt_id,
                                                        offset=1,
                                                        count=1),
                   replace={hunt_id: "H:123456"})