Exemplo n.º 1
0
 def test_infer_main_repo_from_name(self):
     """Tests that the main project repo can be inferred from a repo name."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         for test_repo in test_repos.TEST_REPOS:
             repo_manager.clone_repo_and_get_manager(
                 test_repo.git_url, tmp_dir)
             self.check_with_repo(test_repo.git_url,
                                  test_repo.git_repo_name, tmp_dir)
Exemplo n.º 2
0
    def test_infer_main_repo_from_commit(self):
        """Tests that the main repo can be inferred based on an example commit."""

        with tempfile.TemporaryDirectory() as tmp_dir:
            # Construct example repo's to check for commits.
            for test_repo in test_repos.TEST_REPOS:
                repo_manager.clone_repo_and_get_manager(
                    test_repo.git_url, tmp_dir)
                self.check_with_repo(test_repo.git_url,
                                     test_repo.git_repo_name,
                                     tmp_dir,
                                     commit=test_repo.old_commit)
Exemplo n.º 3
0
    def prepare_for_fuzzer_build(self):
        """Builds the project builder image for a non-OSS-Fuzz project on GitHub
    actions. Sets the repo manager. Does not checkout source code since external
    projects are expected to bring their own source code to CIFuzz. Returns True
    on success."""
        logging.info('Building external project.')
        os.makedirs(self.workspace.repo_storage, exist_ok=True)
        # Checkout before building, so we don't need to rely on copying the source
        # into the image.
        # TODO(metzman): Figure out if we want second copy at all.
        manager = repo_manager.clone_repo_and_get_manager(
            self.config.git_url,
            self.workspace.repo_storage,
            repo_name=self.config.project_repo_name)
        checkout_specified_commit(manager, self.config.pr_ref,
                                  self.config.commit_sha)

        build_integration_abs_path = os.path.join(
            manager.repo_dir, self.config.build_integration_path)
        if not build_external_project_docker_image(manager.repo_dir,
                                                   build_integration_abs_path):
            logging.error('Failed to build external project.')
            return BuildPreparationResult(success=False,
                                          image_repo_path=None,
                                          repo_manager=None)

        image_repo_path = os.path.join('/src', self.config.project_repo_name)
        return BuildPreparationResult(success=True,
                                      image_repo_path=image_repo_path,
                                      repo_manager=manager)
Exemplo n.º 4
0
    def prepare_for_fuzzer_build(self):
        """Builds the fuzzer builder image, checks out the pull request/commit and
    returns the BuildPreparationResult."""
        logging.info('Building OSS-Fuzz project on Github Actions.')
        assert self.config.pr_ref or self.config.commit_sha
        # detect_main_repo builds the image as a side effect.
        inferred_url, image_repo_path = (
            build_specified_commit.detect_main_repo(
                self.config.oss_fuzz_project_name,
                repo_name=self.config.project_repo_name))

        if not inferred_url or not image_repo_path:
            logging.error('Could not detect repo.')
            return BuildPreparationResult(success=False,
                                          image_repo_path=None,
                                          repo_manager=None)

        os.makedirs(self.workspace.repo_storage, exist_ok=True)

        # Use the same name used in the docker image so we can overwrite it.
        image_repo_name = os.path.basename(image_repo_path)

        # Checkout project's repo in the shared volume.
        manager = repo_manager.clone_repo_and_get_manager(
            inferred_url,
            self.workspace.repo_storage,
            repo_name=image_repo_name)
        checkout_specified_commit(manager, self.config.pr_ref,
                                  self.config.commit_sha)

        return BuildPreparationResult(success=True,
                                      image_repo_path=image_repo_path,
                                      repo_manager=manager)
Exemplo n.º 5
0
    def build_image_and_checkout_src(self):
        """Builds the project builder image for a non-OSS-Fuzz project. Sets the
    repo manager and host_repo_path. Checks out source code of project with
    patch under test. Returns True on success."""
        logging.info('Building OSS-Fuzz project on Github Actions.')
        # detect_main_repo builds the image as a side effect.
        inferred_url, self.image_repo_path = (
            build_specified_commit.detect_main_repo(
                self.project_name, repo_name=self.project_repo_name))

        if not inferred_url or not self.image_repo_path:
            logging.error('Could not detect repo from project %s.',
                          self.project_name)
            return False

        git_workspace = os.path.join(self.workspace, 'storage')
        os.makedirs(git_workspace, exist_ok=True)

        # Use the same name used in the docker image so we can overwrite it.
        image_repo_name = os.path.basename(self.image_repo_path)

        # Checkout project's repo in the shared volume.
        self.repo_manager = repo_manager.clone_repo_and_get_manager(
            inferred_url, git_workspace, repo_name=image_repo_name)

        self.host_repo_path = self.repo_manager.repo_dir

        checkout_specified_commit(self.repo_manager, self.pr_ref,
                                  self.commit_sha)
        return True
Exemplo n.º 6
0
  def test_build_fuzzers_from_commit(self):
    """Tests if the fuzzers can build at a specified commit.

    This is done by using a known regression range for a specific test case.
    The old commit should show the error when its fuzzers run and the new one
    should not.
    """
    with tempfile.TemporaryDirectory() as tmp_dir:
      test_case = test_repos.TEST_REPOS[1]
      self.assertTrue(helper.build_image_impl(test_case.project_name))
      host_src_dir = build_specified_commit.copy_src_from_docker(
          test_case.project_name, tmp_dir)

      test_repo_manager = repo_manager.clone_repo_and_get_manager(
          test_case.git_url, host_src_dir, test_case.oss_repo_name)
      build_data = build_specified_commit.BuildData(
          sanitizer='address',
          architecture='x86_64',
          engine='libfuzzer',
          project_name=test_case.project_name)

      build_specified_commit.build_fuzzers_from_commit(test_case.old_commit,
                                                       test_repo_manager,
                                                       host_src_dir, build_data)
      old_error_code = helper.reproduce_impl(test_case.project_name,
                                             test_case.fuzz_target, False, [],
                                             [], test_case.test_case_path)
      build_specified_commit.build_fuzzers_from_commit(test_case.new_commit,
                                                       test_repo_manager,
                                                       host_src_dir, build_data)
      new_error_code = helper.reproduce_impl(test_case.project_name,
                                             test_case.fuzz_target, False, [],
                                             [], test_case.test_case_path)
      self.assertNotEqual(new_error_code, old_error_code)
Exemplo n.º 7
0
    def prepare_for_fuzzer_build(self):
        """Builds the project builder image for a non-OSS-Fuzz project on GitHub
    actions. Sets the repo manager. Does not checkout source code since external
    projects are expected to bring their own source code to CIFuzz. Returns True
    on success."""
        logging.info('Building external project.')
        git_workspace = os.path.join(self.config.workspace, 'storage')
        os.makedirs(git_workspace, exist_ok=True)
        manager = repo_manager.clone_repo_and_get_manager(
            self.config.git_url,
            git_workspace,
            repo_name=self.config.project_repo_name)

        build_integration_path = os.path.join(
            manager.repo_dir, self.config.build_integration_path)
        if not build_external_project_docker_image(self.config.project_name,
                                                   manager.repo_dir,
                                                   build_integration_path):
            logging.error('Failed to build external project.')
            return BuildPreparationResult(False, None, None)

        checkout_specified_commit(manager, self.config.pr_ref,
                                  self.config.commit_sha)

        image_repo_path = os.path.join('/src', self.config.project_repo_name)
        return BuildPreparationResult(True, image_repo_path, manager)
Exemplo n.º 8
0
 def _clone_repo_and_checkout(self, repo_url, repo_name):
     """Helper for child classes that clones the git repo specified by |repo_url|
 to |repo_name|, checks out the specified commit, and returns the
 |manager|."""
     self._make_repo_storage_dir()
     # Checkout project's repo in the shared volume.
     manager = repo_manager.clone_repo_and_get_manager(
         repo_url,
         self.workspace.repo_storage,
         repo_name=repo_name,
         username=self.config.actor,
         password=self.config.token)
     self._checkout_specified_commit(manager)
     return manager
Exemplo n.º 9
0
 def test_external_generic_project(self):
     """Tests building fuzzers from an external project not on Github."""
     project_repo_name = 'cifuzz-external-example'
     git_url = 'https://github.com/jonathanmetzman/cifuzz-external-example.git'
     # This test is dependant on the state of
     # github.com/jonathanmetzman/cifuzz-external-example.
     manager = repo_manager.clone_repo_and_get_manager(
         'https://github.com/jonathanmetzman/cifuzz-external-example',
         self.temp_dir_obj.name)
     project_src_path = manager.repo_dir
     config = test_helpers.create_build_config(
         project_repo_name=project_repo_name,
         workspace=self.workspace,
         git_url=git_url,
         commit_sha='HEAD',
         project_src_path=project_src_path,
         base_commit='HEAD^1')
     self.assertTrue(build_fuzzers.build_fuzzers(config))
     self.assertTrue(
         os.path.exists(os.path.join(self.out_dir, EXAMPLE_BUILD_FUZZER)))