def testGetValuesRaisesForBadType(self): fd = aff4.FACTORY.Create("aff4:/bad", "AFF4Volume", token=self.token) fd.Flush() plugin = collection_plugin.CollectionExportPlugin() mock_args = mock.Mock() mock_args.path = rdfvalue.RDFURN("aff4:/bad") with self.assertRaises(aff4.InstantiationError): plugin.GetValuesForExport(mock_args)
def testGetValuesForExportHuntResultCollection(self): fd = results.HuntResultCollection("aff4:/huntcoll", token=self.token) fd.Add( rdf_flows.GrrMessage(payload=rdf_client.StatEntry( pathspec=rdf_paths.PathSpec(path="testfile", pathtype="OS")), source=self.client_id)) plugin = collection_plugin.CollectionExportPlugin() mock_args = mock.Mock() mock_args.path = rdfvalue.RDFURN("aff4:/huntcoll") mock_args.no_legacy_warning_pause = True self.assertEqual(len(plugin.GetValuesForExport(mock_args)), 1)
def testGetValuesForExportHuntResultCollection(self): with aff4.FACTORY.Create("aff4:/huntcoll", "HuntResultCollection", token=self.token) as fd: fd.Add( rdf_flows.GrrMessage(payload=rdf_client.StatEntry( aff4path=self.out.Add("testfile")), source=self.client_id)) plugin = collection_plugin.CollectionExportPlugin() mock_args = mock.Mock() mock_args.path = rdfvalue.RDFURN("aff4:/huntcoll") self.assertEqual(len(plugin.GetValuesForExport(mock_args)), 1)
def testExportCollectionWithEmailPlugin(self): # Create a collection with URNs to some files. fd = aff4.FACTORY.Create("aff4:/testcoll", collects.RDFValueCollection, token=self.token) fd.Add( rdf_flows.GrrMessage(payload=rdf_client.StatEntry( aff4path=self.out.Add("testfile")), source=self.client_id)) fd.Close() plugin = collection_plugin.CollectionExportPlugin() parser = argparse.ArgumentParser() plugin.ConfigureArgParser(parser) def SendEmail(address, sender, title, message, **_): self.email_messages.append( dict(address=address, sender=sender, title=title, message=message)) email_address = "notify@%s" % config_lib.CONFIG["Logging.domain"] with utils.Stubber(email_alerts.EMAIL_ALERTER, "SendEmail", SendEmail): self.email_messages = [] plugin.Run( parser.parse_args(args=[ "--no_legacy_warning_pause", "--path", "aff4:/testcoll", email_plugin.EmailOutputPlugin.name, "--email_address", email_address, "--emails_limit", "100", ])) self.assertEqual(len(self.email_messages), 1) for msg in self.email_messages: self.assertEqual(msg["address"], email_address) self.assertEqual("GRR got a new result in aff4:/testcoll.", msg["title"]) self.assertTrue( "GRR got a new result in aff4:/testcoll" in msg["message"]) self.assertTrue("(Host-0)" in msg["message"])
def testExportCollectionWithEmailPlugin(self): # Create a collection with URNs to some files. fd = aff4.FACTORY.Create("aff4:/testcoll", "RDFValueCollection", token=self.token) fd.Add( rdfvalue.GrrMessage( payload=rdfvalue.StatEntry(aff4path=self.out.Add("testfile")), source=self.client_id)) fd.Close() plugin = collection_plugin.CollectionExportPlugin() parser = argparse.ArgumentParser() plugin.ConfigureArgParser(parser) def SendEmail(address, sender, title, message, **_): self.email_messages.append( dict(address=address, sender=sender, title=title, message=message)) email_address = "notify@%s" % config_lib.CONFIG["Logging.domain"] with utils.Stubber(email_alerts, "SendEmail", SendEmail): self.email_messages = [] plugin.Run( parser.parse_args(args=[ "--path", "aff4:/testcoll", "email", "--email", email_address, "--email_limit", "100" ])) self.assertEqual(len(self.email_messages), 1) for msg in self.email_messages: self.assertEqual(msg["address"], email_address) self.assertEqual( "GRR Hunt results collection aff4:/testcoll got a new " "result.", msg["title"]) self.assertTrue("testfile" in msg["message"])