Exemplo n.º 1
0
 def testRaisesIfNoFlowIsFound(self):
     bad_opid = flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
         operation_id=utils.SmartUnicode(
             self.client_id.Add("flows").Add("X:123456")))
     with self.assertRaises(
             flow_plugin.RobotGetFilesOperationNotFoundError):
         self.handler.Handle(bad_opid, token=self.token)
Exemplo n.º 2
0
  def Run(self):
    # Fix the time to avoid regressions.
    with test_lib.FakeTime(42):
      self.SetupClients(1)

      start_handler = flow_plugin.ApiStartRobotGetFilesOperationHandler()
      start_args = flow_plugin.ApiStartRobotGetFilesOperationArgs(
          hostname="Host", paths=["/test"])
      start_result = start_handler.Handle(start_args, token=self.token)

      # Exploit the fact that 'get files' operation id is effectively a flow
      # URN.
      flow_urn = rdfvalue.RDFURN(start_result.operation_id)

      # Put something in the output collection
      flow_obj = aff4.FACTORY.Open(
          flow_urn, aff4_type=flow.GRRFlow, token=self.token)

      with aff4.FACTORY.Create(
          flow_obj.GetRunner().output_urn,
          aff4_type=sequential_collection.GeneralIndexedCollection,
          token=self.token) as collection:
        collection.Add(rdf_client.ClientSummary())

      self.Check(
          "GetRobotGetFilesOperationState",
          args=flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
              operation_id=start_result.operation_id),
          replace={flow_urn.Basename(): "F:ABCDEF12"})
Exemplo n.º 3
0
    def testValidatesClientId(self):
        """Check bad client id is rejected.

    Make sure our input is validated because this API doesn't require
    authorization.
    """
        bad_opid = flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
            operation_id="aff4:/C.1234546<script>/flows/X:12345678")
        with self.assertRaises(ValueError):
            self.handler.Handle(bad_opid, token=self.token)
Exemplo n.º 4
0
    def testRaisesIfFlowIsNotFileFinder(self):
        flow_id = flow.GRRFlow.StartFlow(
            flow_name=processes.ListProcesses.__name__,
            client_id=self.client_id,
            token=self.token)

        bad_opid = flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
            operation_id=utils.SmartUnicode(flow_id))
        with self.assertRaises(
                flow_plugin.RobotGetFilesOperationNotFoundError):
            self.handler.Handle(bad_opid, token=self.token)
Exemplo n.º 5
0
    def testValidatesFlowId(self):
        """Check bad flows id is rejected.

    Make sure our input is validated because this API doesn't require
    authorization.
    """
        bad_opid = flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
            operation_id=utils.SmartUnicode(
                self.client_id.Add("flows").Add("X:<script>")))
        with self.assertRaises(ValueError):
            self.handler.Handle(bad_opid, token=self.token)
Exemplo n.º 6
0
    def testReturnsCorrectResultIfFlowIsFileFinder(self):
        flow_id = flow.GRRFlow.StartFlow(
            flow_name=file_finder.FileFinder.__name__,
            paths=["/*"],
            client_id=self.client_id,
            token=self.token)

        opid = flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
            operation_id=utils.SmartUnicode(flow_id))
        result = self.handler.Handle(opid, token=self.token)
        self.assertEqual(result.state, "RUNNING")
        self.assertEqual(result.result_count, 0)
Exemplo n.º 7
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            self.SetupClients(1)

            start_handler = flow_plugin.ApiStartRobotGetFilesOperationHandler()
            start_args = flow_plugin.ApiStartRobotGetFilesOperationArgs(
                hostname="Host", paths=["/test"])
            start_result = start_handler.Handle(start_args, token=self.token)

            # Exploit the fact that 'get files' operation id is effectively a flow
            # URN.
            flow_urn = rdfvalue.RDFURN(start_result.operation_id)

            # Put something in the output collection
            collection = flow.GRRFlow.ResultCollectionForFID(flow_urn,
                                                             token=self.token)
            collection.Add(rdf_client.ClientSummary())

            self.Check("GetRobotGetFilesOperationState",
                       args=flow_plugin.ApiGetRobotGetFilesOperationStateArgs(
                           operation_id=start_result.operation_id),
                       replace={flow_urn.Basename(): "F:ABCDEF12"})