Exemplo n.º 1
0
    def _RunClientFileFinder(self,
                             paths,
                             action,
                             network_bytes_limit=None,
                             client_id=None):
        client_id = client_id or self.SetupClients(1)[0]
        with test_lib.ConfigOverrider({"Client.server_urls": [self.base_url]}):
            client = comms.GRRHTTPClient(
                ca_cert=config.CONFIG["CA.certificate"],
                private_key=config.CONFIG.Get("Client.private_key",
                                              default=None))
            client.client_worker = worker_mocks.FakeThreadedWorker(
                client=client)
            client.server_certificate = config.CONFIG["Frontend.certificate"]

            for s in flow_test_lib.TestFlowHelper(
                    file_finder.ClientFileFinder.__name__,
                    action_mocks.ClientFileFinderClientMock(
                        client_worker=client.client_worker),
                    client_id=client_id,
                    paths=paths,
                    pathtype=rdf_paths.PathSpec.PathType.OS,
                    action=action,
                    process_non_regular_files=True,
                    network_bytes_limit=network_bytes_limit,
                    token=self.token):
                session_id = s

            return session_id
Exemplo n.º 2
0
    def testClientFileFinder(self):
        paths = [os.path.join(self.base_path, "**/*.plist")]
        action = rdf_file_finder.FileFinderAction.Action.STAT
        for s in flow_test_lib.TestFlowHelper(
                file_finder.ClientFileFinder.__name__,
                action_mocks.ClientFileFinderClientMock(),
                client_id=self.client_id,
                paths=paths,
                pathtype=rdf_paths.PathSpec.PathType.OS,
                action=rdf_file_finder.FileFinderAction(action_type=action),
                process_non_regular_files=True,
                token=self.token):
            session_id = s

        collection = flow.GRRFlow.ResultCollectionForFID(session_id,
                                                         token=self.token)
        results = list(collection)
        self.assertEqual(len(results), 4)
        relpaths = [
            os.path.relpath(p.stat_entry.pathspec.path, self.base_path)
            for p in results
        ]
        self.assertItemsEqual(relpaths, [
            "History.plist", "History.xml.plist", "test.plist",
            "parser_test/com.google.code.grr.plist"
        ])
Exemplo n.º 3
0
  def testUseExternalStores(self):
    if not data_store.RelationalDBEnabled():
      self.skipTest("Test uses relational filestore.")

    paths = [os.path.join(self.base_path, "test.plist")]
    action = rdf_file_finder.FileFinderAction(
        action_type=rdf_file_finder.FileFinderAction.Action.DOWNLOAD)

    action.download.use_external_stores = False

    with mock.patch.object(file_store.EXTERNAL_FILE_STORE, "AddFiles") as efs:
      flow_id = flow_test_lib.TestFlowHelper(
          compatibility.GetName(file_finder.ClientFileFinder),
          action_mocks.ClientFileFinderClientMock(),
          client_id=self.client_id,
          paths=paths,
          pathtype=rdf_paths.PathSpec.PathType.OS,
          action=action,
          process_non_regular_files=True,
          token=self.token)

    results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
    self.assertLen(results, 1)

    self.assertEqual(efs.call_count, 0)

    action.download.use_external_stores = True

    with mock.patch.object(file_store.EXTERNAL_FILE_STORE, "AddFiles") as efs:
      flow_id = flow_test_lib.TestFlowHelper(
          compatibility.GetName(file_finder.ClientFileFinder),
          action_mocks.ClientFileFinderClientMock(),
          client_id=self.client_id,
          paths=paths,
          pathtype=rdf_paths.PathSpec.PathType.OS,
          action=action,
          process_non_regular_files=True,
          token=self.token)

    results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
    self.assertLen(results, 1)

    self.assertEqual(efs.call_count, 1)
Exemplo n.º 4
0
  def _RunCFF(self, paths, action):
    session_id = flow_test_lib.TestFlowHelper(
        file_finder.ClientFileFinder.__name__,
        action_mocks.ClientFileFinderClientMock(),
        client_id=self.client_id,
        paths=paths,
        pathtype=rdf_paths.PathSpec.PathType.OS,
        action=rdf_file_finder.FileFinderAction(action_type=action),
        process_non_regular_files=True,
        token=self.token)

    return flow_test_lib.GetFlowResults(self.client_id, session_id)
Exemplo n.º 5
0
 def _RunCFF(self, paths, action):
     for s in flow_test_lib.TestFlowHelper(
             file_finder.ClientFileFinder.__name__,
             action_mocks.ClientFileFinderClientMock(),
             client_id=self.client_id,
             paths=paths,
             pathtype=rdf_paths.PathSpec.PathType.OS,
             action=rdf_file_finder.FileFinderAction(action_type=action),
             process_non_regular_files=True,
             token=self.token):
         session_id = s
     collection = flow.GRRFlow.ResultCollectionForFID(session_id)
     results = list(collection)
     return results
Exemplo n.º 6
0
  def testClientFileFinderIndicatesCollectedSizeAfterCollection(self):
    client_ref = self.api.Client(client_id=self.client_id)
    args = rdf_file_finder.FileFinderArgs(
        paths=[os.path.join(self.base_path, "numbers.txt")],
        action=rdf_file_finder.FileFinderAction.Download(),
        follow_links=True).AsPrimitiveProto()
    client_ref.CreateFlow(name=file_finder.ClientFileFinder.__name__, args=args)

    flow_test_lib.FinishAllFlowsOnClient(
        self.client_id, client_mock=action_mocks.ClientFileFinderClientMock())

    f = client_ref.File("fs/os" +
                        os.path.join(self.base_path, "numbers.txt")).Get()
    self.assertNotEqual(f.data.hash.sha256, b"")
    self.assertGreater(f.data.hash.num_bytes, 0)
    self.assertGreater(f.data.last_collected, 0)
    self.assertGreater(f.data.last_collected_size, 0)
Exemplo n.º 7
0
  def testFileWithExactlyThanOneChunk(self):
    path = os.path.join(self.base_path, "History.plist")
    s = os.stat(path).st_size
    action = rdf_file_finder.FileFinderAction.Download(chunk_size=s * 2)

    flow_id = flow_test_lib.TestFlowHelper(
        file_finder.ClientFileFinder.__name__,
        action_mocks.ClientFileFinderClientMock(),
        client_id=self.client_id,
        paths=[path],
        pathtype=rdf_paths.PathSpec.PathType.OS,
        action=action,
        process_non_regular_files=True,
        creator=self.test_username)

    results = flow_test_lib.GetFlowResults(self.client_id, flow_id)

    self.assertLen(results, 1)

    self._VerifyDownloadedFiles(results)
Exemplo n.º 8
0
    def _RunClientFileFinder(self,
                             paths,
                             action,
                             network_bytes_limit=None,
                             client_id=None):
        client_id = client_id or self.SetupClient(0)
        with test_lib.ConfigOverrider({"Client.server_urls": [self.base_url]}):
            session_id = flow_test_lib.TestFlowHelper(
                file_finder.ClientFileFinder.__name__,
                action_mocks.ClientFileFinderClientMock(
                    client_worker=worker_mocks.FakeClientWorker()),
                client_id=client_id,
                paths=paths,
                pathtype=rdf_paths.PathSpec.PathType.OS,
                action=action,
                process_non_regular_files=True,
                network_bytes_limit=network_bytes_limit,
                token=self.token)

            return session_id