Пример #1
0
    def testDownloadCollection(self):
        """Check we can download files references in RDFValueCollection."""
        # Create a collection with URNs to some files.
        fd = aff4.FACTORY.Create("aff4:/testcoll",
                                 "RDFValueCollection",
                                 token=self.token)
        fd.Add(rdfvalue.RDFURN(self.out.Add("testfile1")))
        fd.Add(rdf_client.StatEntry(aff4path=self.out.Add("testfile2")))
        fd.Add(
            file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
                aff4path=self.out.Add("testfile5"))))
        fd.Add(
            collectors.ArtifactFilesDownloaderResult(
                downloaded_file=rdf_client.StatEntry(
                    aff4path=self.out.Add("testfile6"))))
        fd.Close()

        with utils.TempDirectory() as tmpdir:
            export_utils.DownloadCollection("aff4:/testcoll",
                                            tmpdir,
                                            overwrite=True,
                                            dump_client_info=True,
                                            token=self.token,
                                            max_threads=2)
            expected_outdir = os.path.join(tmpdir, self.out.Path()[1:])

            # Check we found both files.
            self.assertTrue("testfile1" in os.listdir(expected_outdir))
            self.assertTrue("testfile2" in os.listdir(expected_outdir))
            self.assertTrue("testfile5" in os.listdir(expected_outdir))
            self.assertTrue("testfile6" in os.listdir(expected_outdir))

            # Check we dumped a YAML file to the root of the client.
            expected_rootdir = os.path.join(tmpdir, self.client_id.Basename())
            self.assertTrue("client_info.yaml" in os.listdir(expected_rootdir))
Пример #2
0
 def _AddTestData(self, fd):
     fd.Add(rdfvalue.RDFURN(self.out.Add("testfile1")))
     fd.Add(
         rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile2", pathtype="OS")))
     fd.Add(
         rdf_file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile5", pathtype="OS"))))
     fd.Add(
         collectors.ArtifactFilesDownloaderResult(
             downloaded_file=rdf_client.StatEntry(
                 pathspec=rdf_paths.PathSpec(path="testfile6",
                                             pathtype="OS"))))
Пример #3
0
  def testShowsGenerateArchiveButtonForArtifactDownloaderHunt(self):
    stat_entry = rdf_client.StatEntry(aff4path="aff4:/foo/bar")
    values = [collectors.ArtifactFilesDownloaderResult(
        downloaded_file=stat_entry)]

    with self.ACLChecksDisabled():
      self.CreateGenericHuntWithCollection(values=values)

    self.Open("/")
    self.Click("css=a[grrtarget=ManageHunts]")
    self.Click("css=td:contains('GenericHunt')")
    self.Click("css=li[heading=Results]")

    self.WaitUntil(self.IsTextPresent,
                   "Files referenced in this collection can be downloaded")
Пример #4
0
 def testDownloadCollection(self):
   """Check we can download files references in RDFValueCollection."""
   # Create a collection with URNs to some files.
   fd = aff4.FACTORY.Create("aff4:/testcoll",
                            collects.RDFValueCollection,
                            token=self.token)
   fd.Add(rdfvalue.RDFURN(self.out.Add("testfile1")))
   fd.Add(rdf_client.StatEntry(aff4path=self.out.Add("testfile2")))
   fd.Add(file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
       aff4path=self.out.Add("testfile5"))))
   fd.Add(collectors.ArtifactFilesDownloaderResult(
       downloaded_file=rdf_client.StatEntry(aff4path=self.out.Add(
           "testfile6"))))
   fd.Close()
   self._VerifyDownload()
Пример #5
0
 def _testCollection(self, collection_type):
   # Create a collection with URNs to some files.
   fd = aff4.FACTORY.Create(
       "aff4:/testcoll", collection_type, token=self.token)
   fd.Add(rdfvalue.RDFURN(self.out.Add("testfile1")))
   fd.Add(rdf_client.StatEntry(aff4path=self.out.Add("testfile2")))
   fd.Add(
       rdf_file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
           aff4path=self.out.Add("testfile5"))))
   fd.Add(
       collectors.ArtifactFilesDownloaderResult(
           downloaded_file=rdf_client.StatEntry(aff4path=self.out.Add(
               "testfile6"))))
   fd.Close()
   self._VerifyDownload()
Пример #6
0
    def testDownloadCollectionIgnoresArtifactResultsWithoutFiles(self):
        # Create a collection with URNs to some files.
        fd = sequential_collection.GeneralIndexedCollection(
            self.collection_urn, token=self.token)
        fd.Add(collectors.ArtifactFilesDownloaderResult())

        with utils.TempDirectory() as tmpdir:
            export_utils.DownloadCollection(self.collection_urn,
                                            tmpdir,
                                            overwrite=True,
                                            dump_client_info=True,
                                            token=self.token,
                                            max_threads=2)
            expected_outdir = os.path.join(tmpdir, self.out.Path()[1:])
            self.assertFalse(os.path.exists(expected_outdir))
Пример #7
0
  def testShowsGenerateArchiveButtonForArtifactDownloaderHunt(self):
    stat_entry = rdf_client.StatEntry(pathspec=rdf_paths.PathSpec(
        path="/foo/bar", pathtype=rdf_paths.PathSpec.PathType.OS))
    values = [
        collectors.ArtifactFilesDownloaderResult(downloaded_file=stat_entry)
    ]

    self.CreateGenericHuntWithCollection(values=values)

    self.Open("/")
    self.Click("css=a[grrtarget=hunts]")
    self.Click("css=td:contains('GenericHunt')")
    self.Click("css=li[heading=Results]")

    self.WaitUntil(self.IsTextPresent,
                   "Files referenced in this collection can be downloaded")
Пример #8
0
  def testShowsPerFileDownloadButtonForArtifactDownloaderHunt(self):
    stat_entry = rdf_client.StatEntry(pathspec=rdf_paths.PathSpec(
        path="/foo/bar", pathtype=rdf_paths.PathSpec.PathType.OS))
    values = [
        collectors.ArtifactFilesDownloaderResult(downloaded_file=stat_entry)
    ]

    self.CreateGenericHuntWithCollection(values=values)

    self.Open("/")
    self.Click("css=a[grrtarget=hunts]")
    self.Click("css=td:contains('GenericHunt')")
    self.Click("css=li[heading=Results]")

    self.WaitUntil(
        self.IsElementPresent,
        "css=grr-results-collection button:has(span.glyphicon-download)")
Пример #9
0
  def testDownloadCollectionIgnoresArtifactResultsWithoutFiles(self):
    # Create a collection with URNs to some files.
    fd = aff4.FACTORY.Create("aff4:/testcoll",
                             collects.RDFValueCollection,
                             token=self.token)
    fd.Add(collectors.ArtifactFilesDownloaderResult())
    fd.Close()

    with utils.TempDirectory() as tmpdir:
      export_utils.DownloadCollection("aff4:/testcoll",
                                      tmpdir,
                                      overwrite=True,
                                      dump_client_info=True,
                                      token=self.token,
                                      max_threads=2)
      expected_outdir = os.path.join(tmpdir, self.out.Path()[1:])
      self.assertFalse(os.path.exists(expected_outdir))
Пример #10
0
  def testShowsPerFileDownloadButtonForArtifactDownloaderHunt(self):
    with self.ACLChecksDisabled():
      client_id = self.SetupClients(1)[0]
    stat_entry = rdf_client.StatEntry(aff4path=client_id.Add("fs/os/foo/bar"))
    values = [collectors.ArtifactFilesDownloaderResult(
        downloaded_file=stat_entry)]

    with self.ACLChecksDisabled():
      self.CreateGenericHuntWithCollection(values=values)

    self.Open("/")
    self.Click("css=a[grrtarget=hunts]")
    self.Click("css=td:contains('GenericHunt')")
    self.Click("css=li[heading=Results]")

    self.WaitUntil(self.IsElementPresent,
                   "css=grr-results-collection grr-downloadable-urn button")
Пример #11
0
 def _testCollection(self, collection_type):
     # Create a collection with URNs to some files.
     fd = aff4.FACTORY.Create(self.collection_urn,
                              collection_type,
                              token=self.token)
     fd.Add(rdfvalue.RDFURN(self.out.Add("testfile1")))
     fd.Add(
         rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile2", pathtype="OS")))
     fd.Add(
         rdf_file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile5", pathtype="OS"))))
     fd.Add(
         collectors.ArtifactFilesDownloaderResult(
             downloaded_file=rdf_client.StatEntry(
                 pathspec=rdf_paths.PathSpec(path="testfile6",
                                             pathtype="OS"))))
     fd.Close()
     self._VerifyDownload()
Пример #12
0
 def testDownloadHuntResultCollection(self):
     """Check we can download files references in HuntResultCollection."""
     # Create a collection with URNs to some files.
     fd = results.HuntResultCollection(self.collection_urn,
                                       token=self.token)
     fd.AddAsMessage(rdfvalue.RDFURN(self.out.Add("testfile1")),
                     self.client_id)
     fd.AddAsMessage(
         rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile2", pathtype="OS")),
         self.client_id)
     fd.AddAsMessage(
         rdf_file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(
             pathspec=rdf_paths.PathSpec(path="testfile5", pathtype="OS"))),
         self.client_id)
     fd.AddAsMessage(
         collectors.ArtifactFilesDownloaderResult(
             downloaded_file=rdf_client.StatEntry(
                 pathspec=rdf_paths.PathSpec(path="testfile6",
                                             pathtype="OS"))),
         self.client_id)
     self._VerifyDownload()