Example #1
0
    def GetFlowFilesArchive(self, args, token=None):
        if not self.params.get_flow_files_archive.enabled:
            raise access_control.UnauthorizedAccess(
                "GetFlowFilesArchive is not allowed by the configuration.")

        fd = self._CheckFlowRobotId(args.client_id, args.flow_id, token=token)

        options = self.params.get_flow_files_archive

        if (options.skip_glob_checks_for_artifact_collector
                and fd.Name() == self.artifact_collector_flow_name):
            return api_flow.ApiGetFlowFilesArchiveHandler()
        else:
            return api_flow.ApiGetFlowFilesArchiveHandler(
                path_globs_blacklist=options.path_globs_blacklist,
                path_globs_whitelist=options.path_globs_whitelist)
Example #2
0
  def GetFlowFilesArchive(self, args, context=None):
    if not self.params.get_flow_files_archive.enabled:
      raise access_control.UnauthorizedAccess(
          "GetFlowFilesArchive is not allowed by the configuration.")

    flow_name = self._CheckFlowRobotId(
        args.client_id, args.flow_id, context=context)

    options = self.params.get_flow_files_archive

    if (options.skip_glob_checks_for_artifact_collector and
        flow_name == self.effective_artifact_collector_flow_name):
      return api_flow.ApiGetFlowFilesArchiveHandler()
    else:
      return api_flow.ApiGetFlowFilesArchiveHandler(
          exclude_path_globs=options.exclude_path_globs,
          include_only_path_globs=options.include_only_path_globs)
Example #3
0
 def testArchivesFileMatchingPathGlobsWhitelist(self):
   handler = flow_plugin.ApiGetFlowFilesArchiveHandler(
       path_globs_blacklist=[],
       path_globs_whitelist=[rdf_paths.GlobExpression("/**/*/test.plist")])
   result = handler.Handle(
       flow_plugin.ApiGetFlowFilesArchiveArgs(
           client_id=self.client_id,
           flow_id=self.flow_urn.Basename(),
           archive_format="ZIP"),
       token=self.token)
   manifest = self._GetZipManifest(result)
   self.assertEqual(manifest["archived_files"], 1)
   self.assertEqual(manifest["failed_files"], 0)
   self.assertEqual(manifest["processed_files"], 1)
   self.assertEqual(manifest["ignored_files"], 0)
Example #4
0
 def testArchivesFileMatchingPathGlobsInclusionList(self):
   handler = flow_plugin.ApiGetFlowFilesArchiveHandler(
       exclude_path_globs=[],
       include_only_path_globs=[rdf_paths.GlobExpression("/**/*/test.plist")])
   result = handler.Handle(
       flow_plugin.ApiGetFlowFilesArchiveArgs(
           client_id=self.client_id,
           flow_id=self.flow_id,
           archive_format="ZIP"),
       context=self.context)
   manifest = self._GetZipManifest(result)
   self.assertEqual(manifest["archived_files"], 1)
   self.assertEqual(manifest["failed_files"], 0)
   self.assertEqual(manifest["processed_files"], 1)
   self.assertEqual(manifest["ignored_files"], 0)
Example #5
0
  def setUp(self):
    super(ApiGetFlowFilesArchiveHandlerTest, self).setUp()

    self.handler = flow_plugin.ApiGetFlowFilesArchiveHandler()

    self.client_id = self.SetupClient(0)

    self.flow_urn = flow.StartAFF4Flow(
        flow_name=file_finder.FileFinder.__name__,
        client_id=self.client_id,
        paths=[os.path.join(self.base_path, "test.plist")],
        action=rdf_file_finder.FileFinderAction(action_type="DOWNLOAD"),
        token=self.token)
    action_mock = action_mocks.FileFinderClientMock()
    flow_test_lib.TestFlowHelper(
        self.flow_urn, action_mock, client_id=self.client_id, token=self.token)
Example #6
0
 def testIgnoresFileNotMatchingPathGlobsInclusionList(self):
     handler = flow_plugin.ApiGetFlowFilesArchiveHandler(
         exclude_path_globs=[],
         include_only_path_globs=[rdf_paths.GlobExpression("/**/foo.bar")])
     result = handler.Handle(flow_plugin.ApiGetFlowFilesArchiveArgs(
         client_id=self.client_id,
         flow_id=self.flow_id,
         archive_format="ZIP"),
                             token=self.token)
     manifest = self._GetZipManifest(result)
     self.assertEqual(manifest["archived_files"], 0)
     self.assertEqual(manifest["failed_files"], 0)
     self.assertEqual(manifest["processed_files"], 1)
     self.assertEqual(manifest["ignored_files"], 1)
     self.assertEqual(
         manifest["ignored_files_list"],
         ["aff4:/%s/fs/os%s/test.plist" % (self.client_id, self.base_path)])
Example #7
0
    def setUp(self):
        super(ApiGetFlowFilesArchiveHandlerTest, self).setUp()

        self.handler = flow_plugin.ApiGetFlowFilesArchiveHandler()

        self.client_id = self.SetupClient(0)

        action_mock = action_mocks.FileFinderClientMock()
        self.flow_id = flow_test_lib.TestFlowHelper(
            file_finder.FileFinder.__name__,
            action_mock,
            client_id=self.client_id,
            token=self.token,
            paths=[os.path.join(self.base_path, "test.plist")],
            action=rdf_file_finder.FileFinderAction(action_type="DOWNLOAD"))

        if isinstance(self.flow_id, rdfvalue.SessionID):
            self.flow_id = self.flow_id.Basename()
Example #8
0
 def testIgnoresFileNotMatchingPathGlobsWhitelist(self):
     handler = flow_plugin.ApiGetFlowFilesArchiveHandler(
         path_globs_blacklist=[],
         path_globs_whitelist=[rdf_paths.GlobExpression("/**/foo.bar")])
     result = handler.Handle(flow_plugin.ApiGetFlowFilesArchiveArgs(
         client_id=self.client_id,
         flow_id=self.flow_id,
         archive_format="ZIP"),
                             token=self.token)
     manifest = self._GetZipManifest(result)
     self.assertEqual(manifest["archived_files"], 0)
     self.assertEqual(manifest["failed_files"], 0)
     self.assertEqual(manifest["processed_files"], 1)
     self.assertEqual(manifest["ignored_files"], 1)
     self.assertEqual(manifest["ignored_files_list"], [
         utils.SmartUnicode(
             self.client_id.Add("fs/os").Add(
                 self.base_path).Add("test.plist"))
     ])
 def GetFlowFilesArchive(self, args, context=None):
     return api_flow.ApiGetFlowFilesArchiveHandler()