Пример #1
0
def check_fuzzer_build(config):
    """Checks the integrity of the built fuzzers.

  Args:
    config: The config object.

  Returns:
    True if fuzzers pass OSS-Fuzz's build check.
  """
    workspace = workspace_utils.Workspace(config)
    if not os.path.exists(workspace.out):
        logging.error('Invalid out directory: %s.', workspace.out)
        return False
    if not os.listdir(workspace.out):
        logging.error('No fuzzers found in out directory: %s.', workspace.out)
        return False

    env = base_runner_utils.get_env(config, workspace)
    if config.allowed_broken_targets_percentage is not None:
        env['ALLOWED_BROKEN_TARGETS_PERCENTAGE'] = (
            config.allowed_broken_targets_percentage)

    stdout, stderr, retcode = utils.execute('test_all.py', env=env)
    print(f'Build check: stdout: {stdout}\nstderr: {stderr}')
    if retcode == 0:
        logging.info('Build check passed.')
        return True
    logging.error('Build check failed.')
    return False
Пример #2
0
    def test_remove_unaffected_fuzz_targets(self, side_effect,
                                            expected_dir_len):
        """Tests that remove_unaffected_fuzzers has the intended effect."""
        config = test_helpers.create_run_config(
            is_github=True,
            oss_fuzz_project_name=EXAMPLE_PROJECT,
            workspace='/workspace')
        workspace = workspace_utils.Workspace(config)
        deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
            config, workspace)
        # We can't use fakefs in this test because this test executes
        # utils.is_fuzz_target_local. This function relies on the executable bit
        # being set, which doesn't work properly in fakefs.
        with tempfile.TemporaryDirectory() as tmp_dir, mock.patch(
                'get_coverage.OSSFuzzCoverage.get_files_covered_by_target'
        ) as mocked_get_files:
            with mock.patch('get_coverage._get_oss_fuzz_fuzzer_stats_dir_url',
                            return_value=1):
                mocked_get_files.side_effect = side_effect
                shutil.copy(self.TEST_FUZZER_1, tmp_dir)
                shutil.copy(self.TEST_FUZZER_2, tmp_dir)

                affected_fuzz_targets.remove_unaffected_fuzz_targets(
                    deployment, tmp_dir, [EXAMPLE_FILE_CHANGED], '')
                self.assertEqual(expected_dir_len, len(os.listdir(tmp_dir)))
 def setUp(self):
     self.setUpPyfakefs()
     config = test_helpers.create_run_config(workspace=WORKSPACE,
                                             is_github=False)
     workspace = workspace_utils.Workspace(config)
     self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
         config, workspace)
Пример #4
0
 def setUp(self):
     self.setUpPyfakefs()
     config = test_helpers.create_run_config(workspace=WORKSPACE,
                                             is_github=False)
     workspace = workspace_utils.Workspace(config)
     self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
         config, workspace)
     self.corpus_dir = os.path.join(workspace.corpora, EXAMPLE_FUZZER)
Пример #5
0
    def __init__(self, config):
        self.config = config
        self.workspace = workspace_utils.Workspace(config)
        self.clusterfuzz_deployment = (
            clusterfuzz_deployment.get_clusterfuzz_deployment(
                self.config, self.workspace))

        # Set by the initialize method.
        self.fuzz_target_paths = None
Пример #6
0
    def setUp(self):
        self.setUpPyfakefs()
        config = test_helpers.create_run_config(workspace=WORKSPACE,
                                                cfl_platform='other',
                                                filestore='no_filestore',
                                                no_clusterfuzz_deployment=True)
        workspace = workspace_utils.Workspace(config)
        self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
            config, workspace)

        self.corpus_dir = os.path.join(workspace.corpora, EXAMPLE_FUZZER)
Пример #7
0
 def __init__(self, config, ci_system):
     self.config = config
     self.ci_system = ci_system
     self.workspace = workspace_utils.Workspace(config)
     self.workspace.initialize_dir(self.workspace.out)
     self.workspace.initialize_dir(self.workspace.work)
     self.clusterfuzz_deployment = (
         clusterfuzz_deployment.get_clusterfuzz_deployment(
             self.config, self.workspace))
     self.image_repo_path = None
     self.host_repo_path = None
     self.repo_manager = None
Пример #8
0
  def test_get_clusterfuzz_deployment(self, platform, expected_deployment_cls):
    """Tests that get_clusterfuzz_deployment returns the correct value."""
    with mock.patch('config_utils.BaseConfig.platform',
                    return_value=platform,
                    new_callable=mock.PropertyMock):
      with mock.patch('filestore_utils.get_filestore', return_value=None):
        config = _create_config()
        workspace = workspace_utils.Workspace(config)

        self.assertIsInstance(
            clusterfuzz_deployment.get_clusterfuzz_deployment(
                config, workspace), expected_deployment_cls)
Пример #9
0
 def __init__(self, config):
     self.config = config
     self.workspace = workspace_utils.Workspace(config)
Пример #10
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests the functionality of the docker module."""
import unittest
from unittest import mock

import docker
import test_helpers
import workspace_utils

CONTAINER_NAME = 'example-container'
config = test_helpers.create_run_config(oss_fuzz_project_name='project',
                                        workspace='/workspace')
config.workspace = '/workspace'
WORKSPACE = workspace_utils.Workspace(config)
SANITIZER = 'example-sanitizer'
LANGUAGE = 'example-language'


class GetProjectImageTest(unittest.TestCase):
    """Tests for get_project_image."""
    def test_get_project_image(self):
        """Tests that get_project_image_name works as intended."""
        project = 'my-project'
        self.assertEqual(docker.get_project_image_name(project),
                         'gcr.io/oss-fuzz/my-project')


class GetDeleteImagesTest(unittest.TestCase):
    """Tests for delete_images."""
Пример #11
0
def _create_deployment(**kwargs):
    config = _create_config(**kwargs)
    workspace = workspace_utils.Workspace(config)
    return clusterfuzz_deployment.get_clusterfuzz_deployment(config, workspace)
Пример #12
0
def create_workspace(workspace_path='/workspace'):
    """Returns a workspace located at |workspace_path| ('/workspace' by
  default)."""
    config = create_run_config(workspace=workspace_path)
    return workspace_utils.Workspace(config)
Пример #13
0
 def __init__(self, config):
     self.config = config
     self.workspace = workspace_utils.Workspace(config)
     self._repo_dir = None