示例#1
0
  def Run(self):
    # Create a running mock refresh operation.
    self.running_flow_urn = self.CreateMultiGetFileFlow(
        self.client_id, file_path="fs/os/c/bin/bash", token=self.token)

    # Create a mock refresh operation and complete it.
    self.finished_flow_urn = self.CreateMultiGetFileFlow(
        self.client_id, file_path="fs/os/c/bin/bash", token=self.token)
    with aff4.FACTORY.Open(
        self.finished_flow_urn,
        aff4_type=flow.GRRFlow,
        mode="rw",
        token=self.token) as flow_obj:
      flow_obj.GetRunner().Error("Fake error")

    # Create an arbitrary flow to check on 404s.
    self.non_update_flow_urn = flow.GRRFlow.StartFlow(
        client_id=self.client_id,
        flow_name=discovery.Interrogate.__name__,
        token=self.token)

    # Unkonwn flow ids should also cause 404s.
    self.unknown_flow_id = "F:12345678"

    # Check both operations.
    self.Check(
        "GetVfsFileContentUpdateState",
        args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
            client_id=self.client_id.Basename(),
            operation_id=str(self.running_flow_urn)),
        replace={
            self.running_flow_urn.Basename(): "W:ABCDEF"
        })
    self.Check(
        "GetVfsFileContentUpdateState",
        args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
            client_id=self.client_id.Basename(),
            operation_id=str(self.finished_flow_urn)),
        replace={
            self.finished_flow_urn.Basename(): "W:ABCDEF"
        })
    self.Check(
        "GetVfsFileContentUpdateState",
        args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
            client_id=self.client_id.Basename(),
            operation_id=str(self.non_update_flow_urn)),
        replace={
            self.non_update_flow_urn.Basename(): "W:ABCDEF"
        })
    self.Check(
        "GetVfsFileContentUpdateState",
        args=vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
            client_id=self.client_id.Basename(),
            operation_id=str(self.unknown_flow_id)),
        replace={
            self.unknown_flow_id: "W:ABCDEF"
        })
示例#2
0
    def testHandlerRaisesOnArbitraryFlowId(self):
        # Create a mock flow.
        self.flow_urn = flow.GRRFlow.StartFlow(
            client_id=self.client_id,
            flow_name=discovery.Interrogate.__name__,
            token=self.token)

        args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
            operation_id=str(self.flow_urn))

        # Our mock flow is not a MultiGetFile flow, so an error should be raised.
        with self.assertRaises(vfs_plugin.VfsFileContentUpdateNotFoundError):
            self.handler.Handle(args, token=self.token)
示例#3
0
  def testHandlerReturnsCorrectStateForFlow(self):
    # Create a mock refresh operation.
    self.flow_urn = self.CreateMultiGetFileFlow(
        self.client_id, file_path="fs/os/c/bin/bash", token=self.token)

    args = vfs_plugin.ApiGetVfsFileContentUpdateStateArgs(
        operation_id=str(self.flow_urn))

    # Flow was started and should be running.
    result = self.handler.Handle(args, token=self.token)
    self.assertEqual(result.state, "RUNNING")

    # Terminate flow.
    with aff4.FACTORY.Open(
        self.flow_urn, aff4_type=flow.GRRFlow, mode="rw",
        token=self.token) as flow_obj:
      flow_obj.GetRunner().Error("Fake error")

    # Recheck status and see if it changed.
    result = self.handler.Handle(args, token=self.token)
    self.assertEqual(result.state, "FINISHED")