def Run(self): hunt_urn = rdfvalue.RDFURN("aff4:/hunts/H:123456") results = implementation.GRRHunt.ResultCollectionForHID(hunt_urn) with data_store.DB.GetMutationPool() as pool: result = rdf_flows.GrrMessage( payload=rdfvalue.RDFString("blah1"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(1)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) result = rdf_flows.GrrMessage( payload=rdfvalue.RDFString("blah2-foo"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id="H:123456")) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id="H:123456", count=1)) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id="H:123456", offset=1, count=1)) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id="H:123456", filter="foo"))
def Run(self): client_id = self.SetupClient(0) hunt_id = self.CreateHunt(creator=self.token.username) flow_id = flow_test_lib.StartFlow( flows_processes.ListProcesses, client_id=client_id, parent_hunt_id=hunt_id) with test_lib.FakeTime(rdfvalue.RDFDatetime.FromSecondsSinceEpoch(2)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah1")) ]) with test_lib.FakeTime(rdfvalue.RDFDatetime.FromSecondsSinceEpoch(43)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah2-foo")) ]) replace = {hunt_id: "H:123456"} self.Check( "ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id), replace=replace) self.Check( "ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, count=1), replace=replace) self.Check( "ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs( hunt_id=hunt_id, offset=1, count=1), replace=replace) self.Check( "ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, filter="foo"), replace=replace)
def Run(self): client_id = self.SetupClient(0).Basename() if data_store.RelationalDBEnabled(): hunt_id = self.CreateHunt() flow_id = flow_test_lib.StartFlow(flows_processes.ListProcesses, client_id=client_id, parent_hunt_id=hunt_id) with test_lib.FakeTime( rdfvalue.RDFDatetime.FromSecondsSinceEpoch(2)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah1")) ]) with test_lib.FakeTime( rdfvalue.RDFDatetime.FromSecondsSinceEpoch(43)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah2-foo")) ]) else: hunt_urn = rdfvalue.RDFURN("aff4:/hunts/H:123456") hunt_id = hunt_urn.Basename() results = implementation.GRRHunt.ResultCollectionForHID(hunt_urn) with data_store.DB.GetMutationPool() as pool: result = rdf_flows.GrrMessage( source=client_id, payload=rdfvalue.RDFString("blah1"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(1)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) result = rdf_flows.GrrMessage( source=client_id, payload=rdfvalue.RDFString("blah2-foo"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) replace = {hunt_id: "H:123456"} self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, count=1), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, offset=1, count=1), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, filter="foo"), replace=replace)