def Run(self):
    # Fix the time to avoid regressions.
    with test_lib.FakeTime(42):
      client_id = self.SetupClient(0)
      flow_id = flow_test_lib.StartFlow(
          discovery.Interrogate,
          client_id=client_id,
          creator=self.token.username)

      replace = api_regression_test_lib.GetFlowTestReplaceDict(
          client_id, flow_id, "F:ABCDEF12")

      self.Check(
          "GetFlow",
          args=flow_plugin.ApiGetFlowArgs(client_id=client_id, flow_id=flow_id),
          replace=replace)

      flow_base.TerminateFlow(client_id, flow_id,
                              "Pending termination: Some reason")

      replace = api_regression_test_lib.GetFlowTestReplaceDict(
          client_id, flow_id, "F:ABCDEF13")

      # Fetch the same flow which is now should be marked as pending
      # termination.
      self.Check(
          "GetFlow",
          args=flow_plugin.ApiGetFlowArgs(client_id=client_id, flow_id=flow_id),
          replace=replace)
예제 #2
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            client_urn = self.SetupClient(0)

            # Delete the certificates as it's being regenerated every time the
            # client is created.
            with aff4.FACTORY.Open(client_urn, mode="rw",
                                   token=self.token) as client_obj:
                client_obj.DeleteAttribute(client_obj.Schema.CERT)

            flow_id = flow.StartAFF4Flow(
                flow_name=discovery.Interrogate.__name__,
                client_id=client_urn,
                token=self.token)

            self.Check("GetFlow",
                       args=flow_plugin.ApiGetFlowArgs(
                           client_id=client_urn.Basename(),
                           flow_id=flow_id.Basename()),
                       replace={flow_id.Basename(): "F:ABCDEF12"})

            with data_store.DB.GetMutationPool() as pool:
                flow.GRRFlow.MarkForTermination(flow_id,
                                                reason="Some reason",
                                                mutation_pool=pool)

            # Fetch the same flow which is now should be marked as pending
            # termination.
            self.Check("GetFlow",
                       args=flow_plugin.ApiGetFlowArgs(
                           client_id=client_urn.Basename(),
                           flow_id=flow_id.Basename()),
                       replace={flow_id.Basename(): "F:ABCDEF13"})
예제 #3
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            client_id = self.SetupClient(0).Basename()
            if data_store.AFF4Enabled():
                # Delete the certificates as it's being regenerated every time the
                # client is created.
                with aff4.FACTORY.Open(client_id, mode="rw",
                                       token=self.token) as client_obj:
                    client_obj.DeleteAttribute(client_obj.Schema.CERT)

            flow_id = api_regression_test_lib.StartFlow(client_id,
                                                        discovery.Interrogate,
                                                        token=self.token)

            replace = api_regression_test_lib.GetFlowTestReplaceDict(
                client_id, flow_id, "F:ABCDEF12")

            self.Check("GetFlow",
                       args=flow_plugin.ApiGetFlowArgs(client_id=client_id,
                                                       flow_id=flow_id),
                       replace=replace)

            self._TerminateFlow(client_id, flow_id)

            replace = api_regression_test_lib.GetFlowTestReplaceDict(
                client_id, flow_id, "F:ABCDEF13")

            # Fetch the same flow which is now should be marked as pending
            # termination.
            self.Check("GetFlow",
                       args=flow_plugin.ApiGetFlowArgs(client_id=client_id,
                                                       flow_id=flow_id),
                       replace=replace)
예제 #4
0
 def testGetFlowWorksIfFlowWasCreatedBySameRouter(self):
     flow_id = self._CreateFlowWithRobotId()
     router = self._CreateRouter(get_flow=rr.RobotRouterGetFlowParams(
         enabled=True))
     router.GetFlow(api_flow.ApiGetFlowArgs(client_id=self.client_id,
                                            flow_id=flow_id),
                    token=self.token)
예제 #5
0
  def testGetFlowRaisesIfFlowWasNotCreatedBySameUser(self):
    flow_id = flow_test_lib.StartFlow(
        file_finder.FileFinder, self.client_id, creator=self.another_username)

    router = self._CreateRouter(
        get_flow=rr.RobotRouterGetFlowParams(enabled=True))
    with self.assertRaises(access_control.UnauthorizedAccess):
      router.GetFlow(
          api_flow.ApiGetFlowArgs(client_id=self.client_id, flow_id=flow_id),
          token=self.token)
예제 #6
0
    def testNestedFlowsAppearCorrectlyAfterAutoRefresh(self):
        self.Open("/#/clients/%s" % self.client_id)
        # Ensure auto-refresh updates happen every second.
        self.GetJavaScriptValue(
            "grrUi.flow.flowsListDirective.setAutoRefreshInterval(1000);")

        flow_1 = flow.StartAFF4Flow(
            client_id=self.client_id,
            flow_name=gui_test_lib.FlowWithOneLogStatement.__name__,
            token=self.token)

        # Go to the flows page without refreshing the page, so that
        # AUTO_REFRESH_INTERVAL_MS setting is not reset and wait
        # until flow_1 is visible.
        self.Click("css=a[grrtarget='client.flows']")
        self.WaitUntil(self.IsElementPresent,
                       "css=tr:contains('%s')" % flow_1.Basename())

        # Create a recursive flow_2 that will appear after auto-refresh.
        flow_2 = flow.StartAFF4Flow(
            client_id=self.client_id,
            flow_name=gui_test_lib.RecursiveTestFlow.__name__,
            token=self.token)

        # Check that the flow we started in the background appears in the list.
        self.WaitUntil(self.IsElementPresent,
                       "css=tr:contains('%s')" % flow_2.Basename())

        # Check that flow_2 is the row 1 (row 0 is the table header).
        self.WaitUntil(
            self.IsElementPresent,
            "css=grr-client-flows-list tr:nth(1):contains('%s')" %
            flow_2.Basename())

        # Click on a nested flow.
        self.Click("css=tr:contains('%s') span.tree_branch" %
                   flow_2.Basename())

        # Check that flow_2 is still row 1 and that nested flows occupy next
        # rows.
        self.WaitUntil(
            self.IsElementPresent,
            "css=grr-client-flows-list tr:nth(1):contains('%s')" %
            flow_2.Basename())

        flow_data = api_flow.ApiGetFlowHandler().Handle(
            api_flow.ApiGetFlowArgs(client_id=self.client_id,
                                    flow_id=flow_2.Basename()),
            token=self.token)

        for index, nested_flow in enumerate(flow_data.nested_flows):
            self.WaitUntil(
                self.IsElementPresent,
                "css=grr-client-flows-list tr:nth(%d):contains('%s')" %
                (index + 2, nested_flow.flow_id))
예제 #7
0
  def testAllClientFlowsMethodsAreAccessChecked(self):
    args = api_flow.ApiListFlowsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlows, "CheckClientAccess", args=args)

    args = api_flow.ApiGetFlowArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.GetFlow, "CheckClientAccess", args=args)

    args = api_flow.ApiCreateFlowArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.CreateFlow, "CheckClientAccess", args=args)
    self.CheckMethodIsAccessChecked(
        self.router.CreateFlow, "CheckIfCanStartClientFlow", args=args)

    args = api_flow.ApiCancelFlowArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.CancelFlow, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowRequestsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowRequests, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowResultsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowResults, "CheckClientAccess", args=args)

    args = api_flow.ApiGetExportedFlowResultsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.GetExportedFlowResults, "CheckClientAccess", args=args)

    args = api_flow.ApiGetFlowResultsExportCommandArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.GetFlowResultsExportCommand, "CheckClientAccess", args=args)

    args = api_flow.ApiGetFlowFilesArchiveArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.GetFlowFilesArchive, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowOutputPluginsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowOutputPlugins, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowOutputPluginLogsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowOutputPluginLogs, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowOutputPluginErrorsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowOutputPluginErrors, "CheckClientAccess", args=args)

    args = api_flow.ApiListFlowLogsArgs(client_id=self.client_id)
    self.CheckMethodIsAccessChecked(
        self.router.ListFlowLogs, "CheckClientAccess", args=args)
예제 #8
0
    def testGetFlowRaisesIfFlowWasNotCreatedBySameRouter(self):
        flow_urn = flow.StartFlow(client_id=self.client_id,
                                  flow_name=file_finder.FileFinder.__name__,
                                  token=self.token)

        router = self._CreateRouter(get_flow=rr.RobotRouterGetFlowParams(
            enabled=True))
        with self.assertRaises(access_control.UnauthorizedAccess):
            router.GetFlow(api_flow.ApiGetFlowArgs(
                client_id=self.client_id, flow_id=flow_urn.Basename()),
                           token=self.token)
예제 #9
0
 def Handle(self, args, context=None):
     return api_flow.ApiGetFlowHandler().Handle(api_flow.ApiGetFlowArgs(
         client_id=args.client_id, flow_id=self.flow_id),
                                                context=context)
예제 #10
0
 def Handle(self, args, token=None):
     return api_flow.ApiGetFlowHandler().Handle(api_flow.ApiGetFlowArgs(
         client_id=args.client_id, flow_id=self.flow_urn.Basename()),
                                                token=token)