Exemple #1
0
    def testDisplaysFailedResult(self):
        flow_args = rdf_file_finder.CollectFilesByKnownPathArgs(
            paths=["/file0", "/file1"])
        flow_id = flow_test_lib.StartFlow(file.CollectFilesByKnownPath,
                                          creator=self.test_username,
                                          client_id=self.client_id,
                                          flow_args=flow_args)

        flow_test_lib.AddResultsToFlow(
            self.client_id, flow_id,
            [self._GenFailedResult(i) for i in range(2)])

        with flow_test_lib.FlowProgressOverride(
                file.CollectFilesByKnownPath,
                rdf_file_finder.CollectFilesByKnownPathProgress(num_failed=2)):
            self.Open(f"/v2/clients/{self.client_id}")
            self.Click(
                "css=collect-files-by-known-path-details result-accordion:contains('/file0 + 1 more')"
            )

            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .mat-tab-label-content:contains('2 errors')"
            )
            for i in range(2):
                self.WaitUntil(
                    self.IsElementPresent,
                    f"css=collect-files-by-known-path-details .results:contains('errormsg{i}')"
                )
Exemple #2
0
    def testFailsAfterRetryOnFailedFetchOnWindows(self):
        temp_bar_file = self.create_tempfile()
        temp_bar_file.write_bytes(b"bar")
        file_bar_path = temp_bar_file.full_path

        with mock.patch.object(flow_base.FlowBase, "client_os", "Windows"):
            with mock.patch.object(vfs,
                                   "VFSOpen",
                                   side_effect=IOError("mock err")):
                flow_id = flow_test_lib.TestFlowHelper(
                    file.CollectFilesByKnownPath.__name__,
                    self.client_mock,
                    client_id=self.client_id,
                    paths=[file_bar_path],
                    creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectFilesByKnownPathProgress(
                num_in_progress=0,
                num_raw_fs_access_retries=1,
                num_collected=0,
                num_failed=1,
            ), progress)

        results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
        self.assertLen(results, 1)
        self.assertEqual(results[0].stat.pathspec.path, file_bar_path)
        self.assertEqual(
            results[0].stat.pathspec.pathtype,
            config.CONFIG["Server.raw_filesystem_access_pathtype"])
        self.assertIsNone(results[0].hash.sha1)
        self.assertEqual(
            results[0].status,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.FAILED)
Exemple #3
0
    def testDisplaysOnlyWhenCollected(self):
        flow_args = rdf_file_finder.CollectFilesByKnownPathArgs(
            paths=["/file0"])
        flow_test_lib.StartFlow(file.CollectFilesByKnownPath,
                                creator=self.test_username,
                                client_id=self.client_id,
                                flow_args=flow_args)

        with flow_test_lib.FlowProgressOverride(
                file.CollectFilesByKnownPath,
                rdf_file_finder.CollectFilesByKnownPathProgress(
                    num_in_progress=1)):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(
                self.IsElementPresent,
                "css=.flow-title:contains('File contents by exact path')")
            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details result-accordion:contains('/file0')"
            )
            self.Click(
                "css=collect-files-by-known-path-details result-accordion:contains('/file0')"
            )
            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .results:contains('No data')"
            )
Exemple #4
0
    def testFileNotFound(self):
        temp_dir = self.create_tempdir()
        non_existent_file_path = os.path.join(temp_dir.full_path,
                                              "/non_existent")

        flow_id = flow_test_lib.TestFlowHelper(
            file.CollectFilesByKnownPath.__name__,
            self.client_mock,
            client_id=self.client_id,
            paths=[non_existent_file_path],
            creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectFilesByKnownPathProgress(
                num_in_progress=0,
                num_raw_fs_access_retries=0,
                num_collected=0,
                num_failed=1,
            ), progress)

        results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
        self.assertLen(results, 1)
        self.assertEqual(results[0].stat.pathspec.path, non_existent_file_path)
        self.assertEqual(results[0].stat.pathspec.pathtype,
                         rdf_paths.PathSpec.PathType.OS)
        self.assertEqual(
            results[0].status,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.NOT_FOUND)
Exemple #5
0
    def testFetchIsRetriedWithRawOnWindows(self):
        temp_bar_file = self.create_tempfile()
        temp_bar_file.write_bytes(b"bar")
        file_bar_path = temp_bar_file.full_path
        file_bar_hash = hashlib.sha1(b"bar").hexdigest()

        with mock.patch.object(flow_base.FlowBase, "client_os", "Windows"):
            with _PatchVfs():
                flow_id = flow_test_lib.TestFlowHelper(
                    file.CollectFilesByKnownPath.__name__,
                    self.client_mock,
                    client_id=self.client_id,
                    paths=[file_bar_path],
                    creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectFilesByKnownPathProgress(
                num_in_progress=0,
                num_raw_fs_access_retries=1,
                num_collected=1,
                num_failed=0,
            ), progress)

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

        for result in results:
            self.assertEqual(result.stat.pathspec.path, file_bar_path)

        expected_pathtypes = [
            # First attempt (failure)
            rdf_paths.PathSpec.PathType.OS,
            # Second attempt (success)
            config.CONFIG["Server.raw_filesystem_access_pathtype"],
            config.CONFIG["Server.raw_filesystem_access_pathtype"],
            config.CONFIG["Server.raw_filesystem_access_pathtype"]
        ]
        self.assertCountEqual(expected_pathtypes,
                              self._getResultsPathType(results))

        expected_statuses = [
            # First attempt  (failure)
            rdf_file_finder.CollectFilesByKnownPathResult.Status.IN_PROGRESS,
            # Second attempt (success)
            rdf_file_finder.CollectFilesByKnownPathResult.Status.IN_PROGRESS,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.IN_PROGRESS,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.COLLECTED
        ]
        self.assertCountEqual(expected_statuses,
                              self._getResultsStatus(results))

        expected_hashes = ["None", "None", file_bar_hash, file_bar_hash]
        self.assertCountEqual(expected_hashes, self._getResultsHashes(results))
Exemple #6
0
    def testDisplaysSuccessAndFailedResultAndWarning(self):
        flow_args = rdf_file_finder.CollectFilesByKnownPathArgs(
            paths=["/file0", "/file1"])
        flow_id = flow_test_lib.StartFlow(file.CollectFilesByKnownPath,
                                          creator=self.test_username,
                                          client_id=self.client_id,
                                          flow_args=flow_args)

        flow_test_lib.AddResultsToFlow(self.client_id, flow_id, [
            self._GenFailedResult(0),
            self._GenCollectedResult(1),
        ])

        with flow_test_lib.FlowProgressOverride(
                file.CollectFilesByKnownPath,
                rdf_file_finder.CollectFilesByKnownPathProgress(
                    num_collected=1, num_raw_fs_access_retries=1,
                    num_failed=1)):
            self.Open(f"/v2/clients/{self.client_id}")
            self.Click(
                "css=collect-files-by-known-path-details result-accordion:contains('/file0 + 1 more')"
            )

            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .results:contains('1 file fetched by parsing the raw disk image with libtsk or libfsntfs.')"
            )

            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .mat-tab-label-content:contains('1 successful file collection')"
            )
            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .results:contains('1 B')"
            )

            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .mat-tab-label-content:contains('1 error')"
            )
            self.Click(
                "css=collect-files-by-known-path-details .mat-tab-label-content:contains('1 error')"
            )
            self.WaitUntil(
                self.IsElementPresent,
                "css=collect-files-by-known-path-details .results:contains('errormsg0')"
            )
Exemple #7
0
    def testReturnsMultipleFilesStat(self):
        temp_bar_file = self.create_tempfile()
        temp_bar_file.write_bytes(b"bar")
        file_bar_path = temp_bar_file.full_path

        temp_foo_file = self.create_tempfile()
        temp_foo_file.write_bytes(b"foo")
        file_foo_path = temp_foo_file.full_path

        flow_id = flow_test_lib.TestFlowHelper(
            file.CollectFilesByKnownPath.__name__,
            self.client_mock,
            client_id=self.client_id,
            paths=[file_bar_path, file_foo_path],
            collection_level=rdf_file_finder.CollectFilesByKnownPathArgs.
            CollectionLevel.STAT,
            creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectFilesByKnownPathProgress(
                num_in_progress=0,
                num_raw_fs_access_retries=0,
                num_collected=2,
                num_failed=0,
            ), progress)

        results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
        self.assertLen(results, 2)
        self.assertEqual(results[0].stat.pathspec.path, file_bar_path)
        self.assertEqual(results[0].stat.pathspec.pathtype,
                         rdf_paths.PathSpec.PathType.OS)
        self.assertFalse(results[0].hash)
        self.assertEqual(
            results[0].status,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.COLLECTED)
        self.assertEqual(results[1].stat.pathspec.path, file_foo_path)
        self.assertEqual(results[1].stat.pathspec.pathtype,
                         rdf_paths.PathSpec.PathType.OS)
        self.assertFalse(results[1].hash)
        self.assertEqual(
            results[1].status,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.COLLECTED)
Exemple #8
0
    def testReturnsSingleFile(self):
        temp_bar_file = self.create_tempfile()
        temp_bar_file.write_bytes(b"bar")
        file_bar_path = temp_bar_file.full_path
        file_bar_hash = hashlib.sha1(b"bar").hexdigest()

        flow_id = flow_test_lib.TestFlowHelper(
            file.CollectFilesByKnownPath.__name__,
            self.client_mock,
            client_id=self.client_id,
            paths=[file_bar_path],
            creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectFilesByKnownPathProgress(
                num_in_progress=0,
                num_raw_fs_access_retries=0,
                num_collected=1,
                num_failed=0,
            ), progress)

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

        for result in results:
            self.assertEqual(result.stat.pathspec.pathtype,
                             rdf_paths.PathSpec.PathType.OS)

        expected_paths = [file_bar_path, file_bar_path, file_bar_path]
        self.assertCountEqual(expected_paths, self._getResultsPaths(results))

        expected_hashes = ["None", file_bar_hash, file_bar_hash]
        self.assertCountEqual(expected_hashes, self._getResultsHashes(results))

        expected_statuses = [
            rdf_file_finder.CollectFilesByKnownPathResult.Status.IN_PROGRESS,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.IN_PROGRESS,
            rdf_file_finder.CollectFilesByKnownPathResult.Status.COLLECTED
        ]
        self.assertCountEqual(expected_statuses,
                              self._getResultsStatus(results))
Exemple #9
0
Fichier : file.py Projet : avmi/grr
  def Start(self):
    super().Start(file_size=_MAX_FILE_SIZE)

    self.state.progress = rdf_file_finder.CollectFilesByKnownPathProgress(
        num_in_progress=0,
        num_raw_fs_access_retries=0,
        num_collected=0,
        num_failed=0,
    )

    if self.args.collection_level == rdf_file_finder.CollectFilesByKnownPathArgs.CollectionLevel.STAT:
      self.state.stop_at_stat = True
    elif self.args.collection_level == rdf_file_finder.CollectFilesByKnownPathArgs.CollectionLevel.HASH:
      self.state.stop_at_hash = True

    for path in self.args.paths:
      pathspec = rdf_paths.PathSpec.OS(path=path)
      self.StartFileFetch(
          pathspec, request_data=dict(requested_pathspec=pathspec))
      self.state.progress.num_in_progress += 1