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)
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)
def setUp(self): super(ApiGetFlowFilesArchiveHandlerTest, self).setUp() self.handler = flow_plugin.ApiGetFlowFilesArchiveHandler() self.client_id = self.SetupClient(0) self.flow_urn = flow.GRRFlow.StartFlow( 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)
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_urn.Basename(), 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, token=None): return api_flow.ApiGetFlowFilesArchiveHandler()