Beispiel #1
0
    def _ReadBytesWithGetFile(self,
                              path,
                              stat_available=False,
                              offset=None,
                              file_size_override=None,
                              read_length=None):
        if stat_available:
            client_mock = action_mocks.GetFileClientMock()
        else:
            client_mock = action_mocks.GetFileWithFailingStatClientMock()

        pathspec = rdf_paths.PathSpec(
            pathtype=rdf_paths.PathSpec.PathType.OS,
            path=path,
        )
        if offset is not None:
            pathspec.offset = offset
        if file_size_override is not None:
            pathspec.file_size_override = file_size_override

        args = transfer.GetFileArgs(
            pathspec=pathspec,
            ignore_stat_failure=not stat_available,
        )
        if read_length is not None:
            args.read_length = read_length

        flow_id = flow_test_lib.TestFlowHelper(transfer.GetFile.__name__,
                                               client_mock,
                                               token=self.token,
                                               client_id=self.client_id,
                                               args=args)

        results = flow_test_lib.GetFlowResults(self.client_id, flow_id)
        self.assertLen(
            results, 1, f"Expected 1 result for offset={offset}, "
            f"file_size_override={file_size_override}, "
            f"read_length={read_length}, ")
        res_pathspec = results[0].pathspec
        cp = db.ClientPath.FromPathSpec(self.client_id, res_pathspec)

        return file_store.OpenFile(cp).Read()
Beispiel #2
0
    def testWorksIfStatFailsAndIgnoreStatFailureFlagIsSet(self):
        with temp.AutoTempFilePath() as test_path:
            with open(test_path, "wb") as fd:
                fd.write(b"foo")

            pathspec = rdf_paths.PathSpec(
                pathtype=rdf_paths.PathSpec.PathType.OS,
                path=test_path,
            )
            args = transfer.GetFileArgs(
                pathspec=pathspec,
                read_length=1,
                ignore_stat_failure=True,
            )
            client_mock = action_mocks.GetFileWithFailingStatClientMock()
            flow_test_lib.TestFlowHelper(transfer.GetFile.__name__,
                                         client_mock,
                                         token=self.token,
                                         client_id=self.client_id,
                                         args=args)
Beispiel #3
0
    def testFailsIfStatFailsAndIgnoreStatFailureFlagNotSet(self):
        with temp.AutoTempFilePath() as test_path:
            with open(test_path, "wb") as fd:
                fd.write(b"foo")

            pathspec = rdf_paths.PathSpec(
                pathtype=rdf_paths.PathSpec.PathType.OS,
                path=test_path,
            )
            args = transfer.GetFileArgs(
                pathspec=pathspec,
                read_length=1,
            )
            client_mock = action_mocks.GetFileWithFailingStatClientMock()
            with self.assertRaises(RuntimeError):
                flow_test_lib.TestFlowHelper(transfer.GetFile.__name__,
                                             client_mock,
                                             creator=self.test_username,
                                             client_id=self.client_id,
                                             args=args)