예제 #1
0
  def Run(self):
    email_descriptor = output_plugin.OutputPluginDescriptor(
        plugin_name=email_plugin.EmailOutputPlugin.__name__,
        plugin_args=email_plugin.EmailOutputPluginArgs(
            email_address="test@localhost", emails_limit=42))

    with test_lib.FakeTime(42):
      flow_urn = flow.GRRFlow.StartFlow(
          flow_name=flow_test_lib.DummyFlowWithSingleReply.__name__,
          client_id=self.client_id,
          output_plugins=[email_descriptor],
          token=self.token)

    with test_lib.FakeTime(43):
      for _ in flow_test_lib.TestFlowHelper(flow_urn, token=self.token):
        pass

    self.Check(
        "ListFlowOutputPluginLogs",
        args=flow_plugin.ApiListFlowOutputPluginLogsArgs(
            client_id=self.client_id.Basename(),
            flow_id=flow_urn.Basename(),
            plugin_id="EmailOutputPlugin_0"),
        replace={
            flow_urn.Basename(): "W:ABCDEF"
        })
예제 #2
0
    def testEmailPluginSendsEmailPerEveyBatchOfResponses(self):
        self.ProcessResponses(plugin_args=email_plugin.EmailOutputPluginArgs(
            email_address=self.email_address),
                              responses=[rdf_client.Process(pid=42)])

        self.assertEqual(len(self.email_messages), 1)

        msg = self.email_messages[0]
        self.assertEqual(msg["address"], self.email_address)
        self.assertTrue("got a new result in %s" %
                        self.results_urn in msg["title"])
        self.assertTrue(utils.SmartStr(self.client_id) in msg["message"])
        self.assertTrue(utils.SmartStr(self.hostname) in msg["message"])
예제 #3
0
  def setUp(self):
    super(TestFlowCopy, self).setUp()

    # Prepare our fixture.
    self.client_id = rdf_client.ClientURN("C.0000000000000001")
    # This attribute is used by StandardHuntTestMixin.
    self.client_ids = [self.client_id]
    fixture_test_lib.ClientFixture(self.client_id, self.token)
    self.RequestAndGrantClientApproval("C.0000000000000001")

    self.email_descriptor = output_plugin.OutputPluginDescriptor(
        plugin_name=email_plugin.EmailOutputPlugin.__name__,
        plugin_args=email_plugin.EmailOutputPluginArgs(
            email_address="test@localhost", emails_limit=42))
예제 #4
0
    def Run(self):
        email_descriptor = output_plugin.OutputPluginDescriptor(
            plugin_name=email_plugin.EmailOutputPlugin.__name__,
            plugin_args=email_plugin.EmailOutputPluginArgs(
                email_address="test@localhost", emails_limit=42))

        with test_lib.FakeTime(42):
            flow_urn = flow.GRRFlow.StartFlow(
                flow_name=processes.ListProcesses.__name__,
                client_id=self.client_id,
                output_plugins=[email_descriptor],
                token=self.token)

        self.Check("ListFlowOutputPlugins",
                   args=flow_plugin.ApiListFlowOutputPluginsArgs(
                       client_id=self.client_id.Basename(),
                       flow_id=flow_urn.Basename()),
                   replace={flow_urn.Basename(): "W:ABCDEF"})
예제 #5
0
    def testEmailPluginStopsSendingEmailsAfterLimitIsReached(self):
        responses = [rdf_client.Process(pid=i) for i in range(11)]
        self.ProcessResponses(plugin_args=email_plugin.EmailOutputPluginArgs(
            email_address=self.email_address, emails_limit=10),
                              responses=responses,
                              process_responses_separately=True)

        self.assertEqual(len(self.email_messages), 10)

        for msg in self.email_messages:
            self.assertEqual(msg["address"], self.email_address)
            self.assertTrue("got a new result in %s" %
                            self.results_urn in msg["title"])
            self.assertTrue(utils.SmartStr(self.client_id) in msg["message"])
            self.assertTrue(utils.SmartStr(self.hostname) in msg["message"])

        for msg in self.email_messages[:10]:
            self.assertFalse("sending of emails will be disabled now" in msg)

        self.assertTrue("sending of emails will be disabled now" in
                        self.email_messages[9]["message"])
예제 #6
0
  def testCreateHuntFromFlow(self):
    email_descriptor = output_plugin.OutputPluginDescriptor(
        plugin_name=email_plugin.EmailOutputPlugin.__name__,
        plugin_args=email_plugin.EmailOutputPluginArgs(
            email_address="test@localhost", emails_limit=42))

    args = flows_processes.ListProcessesArgs(
        filename_regex="test[a-z]*", fetch_binaries=True)

    flow.GRRFlow.StartFlow(
        flow_name=flows_processes.ListProcesses.__name__,
        args=args,
        client_id=self.client_id,
        output_plugins=[email_descriptor],
        token=self.token)

    # Navigate to client and select newly created flow.
    self.Open("/#/clients/%s" % self.client_id)
    self.Click("css=a[grrtarget='client.flows']")
    self.Click("css=td:contains('ListProcesses')")

    # Open wizard and check if flow arguments are copied.
    self.Click("css=button[name=create_hunt]")

    self.WaitUntilEqual("test[a-z]*", self.GetValue,
                        "css=label:contains('Filename Regex') ~ * input")

    self.WaitUntil(
        self.IsChecked, "css=label:contains('Fetch Binaries') "
        "~ * input[type=checkbox]")

    # Go to output plugins page and check that we did not copy the output
    # plugins.
    self.Click("css=button:contains('Next')")
    self.WaitUntil(self.IsElementPresent,
                   "css=grr-wizard-form:contains('Hunt parameters')")
    self.Click("css=grr-new-hunt-wizard-form button.Next")
    self.WaitUntil(self.IsElementPresent,
                   "css=grr-wizard-form:contains('How to process results')")

    self.WaitUntilNot(self.IsElementPresent,
                      "css=grr-output-plugin-descriptor-form")

    # Nothing else to check, so finish the hunt.
    # Click on "Next" button
    self.Click("css=grr-new-hunt-wizard-form button.Next")
    self.WaitUntil(self.IsElementPresent,
                   "css=grr-wizard-form:contains('Where to run?')")
    self.Click("css=button:contains('Next')")
    self.WaitUntil(self.IsElementPresent,
                   "css=grr-wizard-form:contains('Review')")
    self.Click("css=button:contains('Create Hunt')")
    self.Click("css=button:contains('Done')")

    # Check that we get redirected to ManageHunts.
    self.WaitUntilEqual(1, self.GetCssCount,
                        "css=grr-hunts-list table tbody tr")
    self.WaitUntilEqual(1, self.GetCssCount,
                        "css=grr-hunts-list table tbody tr.row-selected")
    self.WaitUntil(self.IsTextPresent, "GenericHunt")
    self.WaitUntil(self.IsTextPresent, flows_processes.ListProcesses.__name__)