Ejemplo n.º 1
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            client_urn = self.SetupClients(1)[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.GRRFlow.StartFlow(
                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"})
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def testNestedFlowsAppearCorrectlyAfterAutoRefresh(self):
        self.Open("/#/clients/C.0000000000000001")
        # Ensure auto-refresh updates happen every second.
        self.GetJavaScriptValue(
            "grrUi.flow.flowsListDirective.setAutoRefreshInterval(1000);")

        flow_1 = flow.GRRFlow.StartFlow(
            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.GRRFlow.StartFlow(
            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.Basename(),
                                    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))
Ejemplo n.º 4
0
    def testGetFlowRaisesIfFlowWasNotCreatedBySameRouter(self):
        flow_urn = flow.GRRFlow.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)
Ejemplo n.º 5
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, "CheckIfCanStartFlow", 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.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)
Ejemplo n.º 6
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            client_urn = self.SetupClients(1)[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.GRRFlow.StartFlow(
                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"})
Ejemplo n.º 7
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)