def setUp(self):
        test_helpers.patch_environ(self)

        self.fuzzer_name = 'fake_fuzzer'
        self.full_fuzzer_name = 'libFuzzer_fake_fuzzer'
        self.job_type = 'fake_job'
        self.temp_dir = tempfile.mkdtemp()

        data_types.FuzzTarget(engine='libFuzzer',
                              binary='fake_fuzzer',
                              project='test-project').put()

        os.environ['FUZZ_INPUTS_DISK'] = self.temp_dir

        test_helpers.patch(self, [
            'bot.tasks.ml_train_utils.get_corpus',
            'bot.tasks.train_rnn_generator_task.train_rnn',
            'bot.tasks.train_rnn_generator_task.upload_model_to_gcs',
        ])

        self.mock.get_corpus.return_value = True
        self.mock.train_rnn.return_value = new_process.ProcessResult(
            return_code=0)
        self.mock.upload_model_to_gcs.return_value = True
예제 #2
0
  def setUp(self):
    self.minimized_key = 'minimized'
    self.fuzzed_key = 'fuzzed'
    self.unused_key = 'unused'

    self.testcase = data_types.Testcase(
        minimized_keys=self.minimized_key,
        fuzzed_keys=self.fuzzed_key,
        bug_information='1337')
    self.testcase.put()

    test_helpers.patch(self, [
        'base.utils.is_oss_fuzz',
        'google_cloud_utils.blobs.get_blob_info',
        'libs.access.can_user_access_testcase',
        'libs.access.has_access',
        'libs.gcs.get_signed_url',
        'libs.helpers.get_user_email',
        'libs.issue_management.issue_tracker_utils.'
        'get_issue_tracker_for_testcase',
    ])
    self.mock.is_oss_fuzz.return_value = False
    self.mock.can_user_access_testcase.return_value = False
    self.mock.has_access.return_value = False
    self.mock.get_user_email.return_value = '*****@*****.**'
    self.mock.get_signed_url.side_effect = (
        lambda b, p: 'https://SIGNED_URL?path=' + p)

    self.mock.get_blob_info.side_effect = (
        lambda key: storage.GcsBlobInfo('blobs-bucket', key, 'file.ext', 1337))

    self.app = webtest.TestApp(
        webapp2.WSGIApplication(
            [
                ('/download/?([^/]+)?', download.Handler),
            ], debug=True))
예제 #3
0
    def test_exit_target_bug_not_logged(self, exit_code):
        """Test that we don't log when exit code indicates bug found in target."""
        test_helpers.patch(self, [
            'metrics.logs.log_error',
        ])

        def mocked_log_error(*args, **kwargs):  # pylint: disable=unused-argument
            self.assertNotIn(engine.ENGINE_ERROR_MESSAGE, args[0])

        self.mock.log_error.side_effect = mocked_log_error
        _, corpus_path = setup_testcase_and_corpus('empty',
                                                   'corpus_with_some_files')

        target_path = engine_common.find_fuzzer_path(DATA_DIR, 'exit_fuzzer')
        engine_impl = engine.LibFuzzerEngine()
        options = engine_impl.prepare(corpus_path, target_path, DATA_DIR)
        options.extra_env['EXIT_FUZZER_CODE'] = exit_code

        results = engine_impl.fuzz(target_path, options, TEMP_DIR, 10)

        self.assertEqual(1, len(results.crashes))
        self.assertEqual(fuzzer_utils.get_temp_dir(),
                         os.path.dirname(results.crashes[0].input_path))
        self.assertEqual(0, os.path.getsize(results.crashes[0].input_path))
예제 #4
0
    def setUp(self):
        helpers.patch(self, [
            'config.local_config.ProjectConfig',
        ])

        self.topic = 'projects/project/topics/issue-updates'
        self.subscription = 'projects/project/subscriptions/issue-updates'

        self.mock.ProjectConfig.return_value = mock_config.MockConfig({
            'issue_updates': {
                'pubsub_topic': self.topic,
            },
        })

        self.pubsub_client = pubsub.PubSubClient()
        self.pubsub_client.create_topic(self.topic)
        self.pubsub_client.create_subscription(self.subscription, self.topic)

        self.testcase = data_types.Testcase(crash_address='0xffff',
                                            security_flag=True,
                                            crash_type='CRASH TYPE',
                                            crash_state='CRASH STATE',
                                            bug_information='123')
        self.testcase.put()
예제 #5
0
    def setUp(self):
        helpers.patch(self, [
            'config.local_config.ProjectConfig',
            'local.butler.reproduce._download_testcase',
            'local.butler.reproduce._get_testcase',
            'local.butler.reproduce._setup_x',
            'local.butler.reproduce._verify_target_exists',
            'local.butler.reproduce_tool.config.ReproduceToolConfiguration',
            'local.butler.reproduce_tool.prompts.get_boolean',
            'system.process_handler.run_process',
            'system.process_handler.terminate_stale_application_instances',
        ])
        helpers.patch_environ(self)

        self.mock._download_testcase.return_value = '/tmp/testcase'
        self.mock._get_testcase.side_effect = _fake_get_testcase
        self.mock._setup_x.return_value = []
        self.mock.get_boolean.return_value = True
        self.mock.run_process.return_value = (0, 0, '/tmp/testcase')

        self.build_directory = tempfile.mkdtemp()
        self.binary_path = os.path.join(self.build_directory, 'echo')
        with open(self.binary_path, 'w') as f:
            f.write('test')
예제 #6
0
  def setUp(self):
    # Set up fake filesystem.
    test_helpers.patch_environ(self)
    test_utils.set_up_pyfakefs(self)

    self.fs.create_dir('/corpus')
    self.fs.create_dir('/fuzz-inputs')
    self.fs.create_dir('/fake')
    self.fs.create_file('/target')
    self.fs.add_real_directory(TEST_DIR)

    test_helpers.patch(self, [
        'bot.fuzzers.libFuzzer.engine._is_multistep_merge_supported',
        'bot.fuzzers.libfuzzer.LibFuzzerRunner.fuzz',
        'bot.fuzzers.libfuzzer.LibFuzzerRunner.merge',
        'os.getpid',
    ])

    os.environ['JOB_NAME'] = 'libfuzzer_asan_job'
    os.environ['FUZZ_INPUTS_DISK'] = '/fuzz-inputs'

    self.mock._is_multistep_merge_supported = True  # pylint: disable=protected-access
    self.mock.getpid.return_value = 9001
    self.maxDiff = None  # pylint: disable=invalid-name
    def setUp(self):
        helpers.patch(self, [
            'build_management.revisions.get_component_range_list',
            'config.local_config.ProjectConfig',
            'google_cloud_utils.blobs.read_key',
            'google_cloud_utils.pubsub.PubSubClient.publish',
        ])

        data_types.FuzzTarget(id='libFuzzer_proj_target',
                              engine='libFuzzer',
                              project='proj',
                              binary='target').put()

        self.testcase = data_types.Testcase(
            crash_type='crash-type',
            security_flag=True,
            bug_information='1337',
            job_type='libfuzzer_asan_proj',
            fuzzer_name='libFuzzer',
            overridden_fuzzer_name='libFuzzer_proj_target',
            regression='123:456',
            fixed='123:456')
        self.testcase.put()

        self.mock.read_key.return_value = b'reproducer'
        self.mock.get_component_range_list.return_value = [
            {
                'link_text': 'old:new',
            },
        ]

        self.mock.ProjectConfig.return_value = mock_config.MockConfig({
            'bisect_service': {
                'pubsub_topic': '/projects/project/topics/topic',
            }
        })
예제 #8
0
  def test_analyze_dict(self):
    """Tests recommended dictionary analysis."""
    test_helpers.patch(self, [
        'bot.fuzzers.dictionary_manager.DictionaryManager.'
        'parse_recommended_dictionary_from_log_lines',
        'bot.fuzzers.dictionary_manager.DictionaryManager.'
        'update_recommended_dictionary',
    ])

    self.mock.parse_recommended_dictionary_from_log_lines.return_value = set([
        '"USELESS_0"',
        '"APPLE"',
        '"USELESS_1"',
        '"GINGER"',
        '"USELESS_2"',
        '"BEET"',
        '"USELESS_3"',
    ])
    self.mock.get_fuzz_timeout.return_value = get_fuzz_timeout(5.0)

    _, corpus_path = setup_testcase_and_corpus('empty',
                                               'corpus_with_some_files')

    engine_impl = engine.LibFuzzerEngine()
    target_path = engine_common.find_fuzzer_path(DATA_DIR,
                                                 'analyze_dict_fuzzer')
    options = engine_impl.prepare(corpus_path, target_path, DATA_DIR)
    engine_impl.fuzz(target_path, options, TEMP_DIR, 10)
    expected_recommended_dictionary = set([
        '"APPLE"',
        '"GINGER"',
        '"BEET"',
    ])

    self.assertIn(expected_recommended_dictionary,
                  self.mock.update_recommended_dictionary.call_args[0])
예제 #9
0
  def setUp(self):
    test_helpers.patch_environ(self)
    flaskapp = flask.Flask('testflask')
    flaskapp.add_url_rule(
        '/schedule-ml-train-tasks',
        view_func=ml_train.Handler.as_view('/schedule-ml-train-tasks'))
    self.app = webtest.TestApp(flaskapp)

    test_helpers.patch(self, [
        'base.tasks.add_task', 'handlers.base_handler.Handler.is_cron',
        'metrics.logs.log_error'
    ])

    # Create fake jobs.
    data_types.Job(
        name='libfuzzer_asan',
        environment_string='ML_MODELS_TO_USE = rnn_generator').put()
    data_types.Job(name='libfuzzer_msan', environment_string='').put()
    data_types.Job(name='afl_asan', environment_string='').put()

    data_types.Job(
        name='libfuzzer_asan_invalid',
        environment_string='ML_MODELS_TO_USE = invalid_model\n').put()

    # Create fake fuzzers.
    data_types.Fuzzer(name='afl', jobs=['afl_asan']).put()

    # Create fake child fuzzers.
    data_types.FuzzTarget(
        engine='libFuzzer', binary='fake_fuzzer', project='test-project').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_fake_fuzzer', job='libfuzzer_asan').put()
    data_types.FuzzTarget(
        engine='afl', binary='fake_fuzzer', project='test-project').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='afl_fake_fuzzer', job='afl_asan').put()
예제 #10
0
  def setUp(self):
    """Setup for deploy test."""
    real_cwd = os.path.realpath(os.getcwd())
    test_utils.set_up_pyfakefs(self)
    self.fs.add_real_directory(
        os.path.join(real_cwd, 'src', 'appengine'), read_only=False)

    helpers.patch_environ(self)
    helpers.patch(self, [
        'local.butler.common.execute',
        'local.butler.common.Gcloud.run',
        'local.butler.common.has_file_in_path',
        'local.butler.deploy.now',
        'os.remove',
    ])
    self.mock.execute.side_effect = self._mock_execute
    self.mock.has_file_in_path.return_value = True
    self.deploy_failure_count = 0

    os.environ['ROOT_DIR'] = '.'
    self.mock.now.return_value = datetime.datetime(2017, 1, 3, 12, 1)
    self.manifest_target = 'clusterfuzz-source.manifest'
    if sys.version_info.major == 3:
      self.manifest_target += '.3'
 def setUp(self):
   BaseTest.setUp(self)
   helpers.patch(self, ["build_management.build_manager.setup_build"])
   self.mock.setup_build.side_effect = self._mock_setup_build
예제 #12
0
 def setUp(self):
     test_helpers.patch(self, ['config.local_config.AuthConfig.get'])
예제 #13
0
 def setUp(self):
   helpers.patch(self, ['local.butler.common.execute'])
 def setUp(self):
     test_helpers.patch(self, [
         'bot.testcase_manager.convert_dependency_url_to_local_path',
     ])
     self.mock.convert_dependency_url_to_local_path.side_effect = lambda x: x
    def setUp(self):
        """Setup."""
        helpers.patch_environ(self)
        helpers.patch(self, [
            'bot.fuzzers.engine.get',
            'bot.fuzzers.engine_common.unpack_seed_corpus_if_needed',
            'bot.tasks.corpus_pruning_task.choose_cross_pollination_strategy',
            'bot.tasks.task_creation.create_tasks',
            'bot.tasks.setup.update_fuzzer_and_data_bundles',
            'fuzzing.corpus_manager.backup_corpus',
            'fuzzing.corpus_manager.GcsCorpus.rsync_to_disk',
            'fuzzing.corpus_manager.FuzzTargetCorpus.rsync_from_disk',
            'google_cloud_utils.blobs.write_blob',
            'google_cloud_utils.storage.write_data',
        ])
        self.mock.get.return_value = libFuzzer_engine.LibFuzzerEngine()
        self.mock.rsync_to_disk.side_effect = self._mock_rsync_to_disk
        self.mock.rsync_from_disk.side_effect = self._mock_rsync_from_disk
        self.mock.update_fuzzer_and_data_bundles.return_value = True
        self.mock.write_blob.return_value = 'key'
        self.mock.backup_corpus.return_value = 'backup_link'
        self.mock.choose_cross_pollination_strategy.return_value = ('random',
                                                                    None)

        def mocked_unpack_seed_corpus_if_needed(*args, **kwargs):
            """Mock's assert called methods are not powerful enough to ensure that
      unpack_seed_corpus_if_needed was called once with force_unpack=True.
      Instead, just assert that it was called once and during the call assert
      that it was called correctly.
      """
            self.assertTrue(kwargs.get('force_unpack', False))

        self.mock.unpack_seed_corpus_if_needed.side_effect = (
            mocked_unpack_seed_corpus_if_needed)

        data_types.FuzzTarget(engine='libFuzzer',
                              binary='test_fuzzer',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job').put()

        self.fuzz_inputs_disk = tempfile.mkdtemp()
        self.bot_tmpdir = tempfile.mkdtemp()
        self.corpus_bucket = tempfile.mkdtemp()
        self.corpus_dir = os.path.join(self.corpus_bucket, 'corpus')
        self.quarantine_dir = os.path.join(self.corpus_bucket, 'quarantine')
        self.shared_corpus_dir = os.path.join(self.corpus_bucket, 'shared')

        shutil.copytree(os.path.join(TEST_DIR, 'corpus'), self.corpus_dir)
        shutil.copytree(os.path.join(TEST_DIR, 'quarantine'),
                        self.quarantine_dir)
        shutil.copytree(os.path.join(TEST_DIR, 'shared'),
                        self.shared_corpus_dir)

        os.environ['BOT_TMPDIR'] = self.bot_tmpdir
        os.environ['FUZZ_INPUTS'] = self.fuzz_inputs_disk
        os.environ['FUZZ_INPUTS_DISK'] = self.fuzz_inputs_disk
        os.environ['CORPUS_BUCKET'] = 'bucket'
        os.environ['QUARANTINE_BUCKET'] = 'bucket-quarantine'
        os.environ['SHARED_CORPUS_BUCKET'] = 'bucket-shared'
        os.environ['JOB_NAME'] = 'libfuzzer_asan_job'
        os.environ['FAIL_RETRIES'] = '1'
        os.environ['APP_REVISION'] = '1337'
예제 #16
0
 def setUp(self):
     """Set up method for strategy pool generator tests with patch."""
     test_helpers.patch_environ(self)
     test_helpers.patch(
         self, ['bot.fuzzers.engine_common.decide_with_probability'])
     self.mock.decide_with_probability.return_value = True
예제 #17
0
 def setUp(self):
     test_helpers.patch(self, [
         'config.local_config._search_key',
     ])
     self.mock._search_key.return_value = 'value'  # pylint: disable=protected-access
  def setUp(self):
    """Set up."""
    super(CorpusPruningTestUntrusted, self).setUp()
    environment.set_value("JOB_NAME", "libfuzzer_asan_job")

    helpers.patch(
        self,
        [
            "bot.fuzzers.engine.get",
            "bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.fuzzer_directory",
            "base.tasks.add_task",
            "datastore.data_handler.get_data_bundle_bucket_name",
        ],
    )

    self.mock.get.return_value = libFuzzer_engine.LibFuzzerEngine()
    self.mock.fuzzer_directory.return_value = os.path.join(
        environment.get_value("ROOT_DIR"),
        "src",
        "python",
        "bot",
        "fuzzers",
        "libFuzzer",
    )

    self.corpus_bucket = os.environ["CORPUS_BUCKET"]
    self.quarantine_bucket = os.environ["QUARANTINE_BUCKET"]
    self.backup_bucket = os.environ["BACKUP_BUCKET"]

    job = data_types.Job(
        name="libfuzzer_asan_job",
        environment_string=("APP_NAME = test_fuzzer\n"
                            "CORPUS_BUCKET = {corpus_bucket}\n"
                            "QUARANTINE_BUCKET = {quarantine_bucket}\n"
                            "BACKUP_BUCKET={backup_bucket}\n"
                            "RELEASE_BUILD_BUCKET_PATH = "
                            "gs://clusterfuzz-test-data/test_libfuzzer_builds/"
                            "test-libfuzzer-build-([0-9]+).zip\n"
                            "REVISION_VARS_URL = gs://clusterfuzz-test-data/"
                            "test_libfuzzer_builds/"
                            "test-libfuzzer-build-%s.srcmap.json\n".format(
                                corpus_bucket=self.corpus_bucket,
                                quarantine_bucket=self.quarantine_bucket,
                                backup_bucket=self.backup_bucket,
                            )),
    )
    job.put()

    job = data_types.Job(
        name="libfuzzer_asan_job2",
        environment_string=("APP_NAME = test2_fuzzer\n"
                            "BACKUP_BUCKET = {backup_bucket}\n"
                            "CORPUS_FUZZER_NAME_OVERRIDE = libfuzzer\n".format(
                                backup_bucket=self.backup_bucket)),
    )
    job.put()

    os.environ["PROJECT_NAME"] = "oss-fuzz"
    data_types.FuzzTarget(
        engine="libFuzzer", project="test", binary="test_fuzzer").put()
    data_types.FuzzTargetJob(
        fuzz_target_name="libFuzzer_test_fuzzer",
        engine="libFuzzer",
        job="libfuzzer_asan_job",
        last_run=datetime.datetime.now(),
    ).put()

    data_types.FuzzTarget(
        engine="libFuzzer", project="test2", binary="fuzzer").put()
    data_types.FuzzTargetJob(
        fuzz_target_name="libFuzzer_test2_fuzzer",
        engine="libFuzzer",
        job="libfuzzer_asan_job2",
        last_run=datetime.datetime.now(),
    ).put()

    environment.set_value("USE_MINIJAIL", True)
    environment.set_value("SHARED_CORPUS_BUCKET", TEST_SHARED_BUCKET)

    # Set up remote corpora.
    self.corpus = corpus_manager.FuzzTargetCorpus("libFuzzer", "test_fuzzer")
    self.corpus.rsync_from_disk(os.path.join(TEST_DIR, "corpus"), delete=True)

    self.quarantine_corpus = corpus_manager.FuzzTargetCorpus(
        "libFuzzer", "test_fuzzer", quarantine=True)
    self.quarantine_corpus.rsync_from_disk(
        os.path.join(TEST_DIR, "quarantine"), delete=True)

    self.mock.get_data_bundle_bucket_name.return_value = TEST_GLOBAL_BUCKET
    data_types.DataBundle(
        name="bundle", is_local=True, sync_to_worker=True).put()

    data_types.Fuzzer(
        revision=1,
        file_size="builtin",
        source="builtin",
        name="libFuzzer",
        max_testcases=4,
        builtin=True,
        data_bundle_name="bundle",
    ).put()

    self.temp_dir = tempfile.mkdtemp()

    # Copy corpus backup in the older date format.
    corpus_backup_date = datetime.datetime.utcnow().date() - datetime.timedelta(
        days=data_types.CORPUS_BACKUP_PUBLIC_LOOKBACK_DAYS)
    corpus_backup_dir = "gs://{bucket}/corpus/libfuzzer/test2_fuzzer/"
    gsutil.GSUtilRunner().run_gsutil([
        "cp",
        (corpus_backup_dir + "backup.zip").format(bucket=TEST2_BACKUP_BUCKET),
        (corpus_backup_dir +
         "%s.zip" % corpus_backup_date).format(bucket=self.backup_bucket),
    ])
  def setUp(self):
    """Setup."""
    helpers.patch_environ(self)
    helpers.patch(
        self,
        [
            "bot.fuzzers.engine.get",
            "bot.fuzzers.engine_common.unpack_seed_corpus_if_needed",
            "bot.tasks.task_creation.create_tasks",
            "bot.tasks.setup.update_fuzzer_and_data_bundles",
            "fuzzing.corpus_manager.backup_corpus",
            "fuzzing.corpus_manager.GcsCorpus.rsync_to_disk",
            "fuzzing.corpus_manager.FuzzTargetCorpus.rsync_from_disk",
            "datastore.ndb.transaction",
            "google_cloud_utils.blobs.write_blob",
            "google_cloud_utils.storage.write_data",
        ],
    )
    self.mock.get.return_value = libFuzzer_engine.LibFuzzerEngine()
    self.mock.rsync_to_disk.side_effect = self._mock_rsync_to_disk
    self.mock.rsync_from_disk.side_effect = self._mock_rsync_from_disk
    self.mock.update_fuzzer_and_data_bundles.return_value = True
    self.mock.write_blob.return_value = "key"
    self.mock.backup_corpus.return_value = "backup_link"

    def mocked_unpack_seed_corpus_if_needed(*args, **kwargs):
      """Mock's assert called methods are not powerful enough to ensure that
            unpack_seed_corpus_if_needed was called once with force_unpack=True.
            Instead, just assert that it was called once and during the call assert
            that it was called correctly.
            """
      self.assertTrue(kwargs.get("force_unpack", False))

    self.mock.unpack_seed_corpus_if_needed.side_effect = (
        mocked_unpack_seed_corpus_if_needed)

    data_types.FuzzTarget(
        engine="libFuzzer", binary="test_fuzzer", project="test-project").put()
    data_types.FuzzTargetJob(
        fuzz_target_name="libFuzzer_test_fuzzer",
        engine="libFuzzer",
        job="libfuzzer_asan_job",
    ).put()

    self.fuzz_inputs_disk = tempfile.mkdtemp()
    self.bot_tmpdir = tempfile.mkdtemp()
    self.corpus_bucket = tempfile.mkdtemp()
    self.corpus_dir = os.path.join(self.corpus_bucket, "corpus")
    self.quarantine_dir = os.path.join(self.corpus_bucket, "quarantine")
    self.shared_corpus_dir = os.path.join(self.corpus_bucket, "shared")

    shutil.copytree(os.path.join(TEST_DIR, "corpus"), self.corpus_dir)
    shutil.copytree(os.path.join(TEST_DIR, "quarantine"), self.quarantine_dir)
    shutil.copytree(os.path.join(TEST_DIR, "shared"), self.shared_corpus_dir)

    os.environ["BOT_TMPDIR"] = self.bot_tmpdir
    os.environ["FUZZ_INPUTS"] = self.fuzz_inputs_disk
    os.environ["FUZZ_INPUTS_DISK"] = self.fuzz_inputs_disk
    os.environ["CORPUS_BUCKET"] = "bucket"
    os.environ["QUARANTINE_BUCKET"] = "bucket-quarantine"
    os.environ["SHARED_CORPUS_BUCKET"] = "bucket-shared"
    os.environ["JOB_NAME"] = "libfuzzer_asan_job"
    os.environ["FAIL_RETRIES"] = "1"
    os.environ["APP_REVISION"] = "1337"

    # ndb.transaction seems to cause hangs with testbed when run after another
    # test that uses testbed.
    self.mock.transaction.side_effect = lambda f, **_: f()
예제 #20
0
    def setUp(self):
        helpers.patch_environ(self)
        project_config_get = local_config.ProjectConfig.get
        helpers.patch(self, [
            'base.utils.default_project_name',
            'config.db_config.get',
            ('project_config_get', 'config.local_config.ProjectConfig.get'),
        ])

        self.job = data_types.Job(
            name='linux_asan_chrome',
            environment_string=('SUMMARY_PREFIX = project\n'
                                'PROJECT_NAME = project\n'
                                'HELP_URL = help_url\n'))
        self.job2 = data_types.Job(
            name='windows_asan_chrome',
            environment_string=('SUMMARY_PREFIX = project\n'
                                'PROJECT_NAME = project\n'
                                'HELP_URL = help_url\n'))
        self.testcase = data_types.Testcase(
            job_type='linux_asan_chrome',
            fuzzer_name='libfuzzer_binary_name',
            crash_type='Crash-type',
            crash_address='0x1337',
            crash_state='A\nB\nC\n')
        self.testcase.set_metadata('fuzzer_binary_name',
                                   'binary_name',
                                   update_testcase=False)

        self.testcase_assert = data_types.Testcase(
            job_type='linux_asan_chrome',
            fuzzer_name='libfuzzer_binary_name',
            crash_type='ASSERT',
            crash_address='0x1337',
            crash_state='foo != bar\nB\nC\n')
        self.testcase_assert.set_metadata('fuzzer_binary_name',
                                          'binary_name',
                                          update_testcase=False)

        self.testcase_null = data_types.Testcase(
            job_type='linux_asan_chrome',
            fuzzer_name='libfuzzer_binary_name',
            crash_type='UNKNOWN',
            crash_address='0x1337',
            crash_state='NULL')

        self.testcase_bad_cast = data_types.Testcase(
            job_type='linux_asan_chrome',
            fuzzer_name='libfuzzer_binary_name',
            crash_type='Bad-cast',
            crash_address='0x1337',
            crash_state=
            ('Bad-cast to blink::LayoutBlock from blink::LayoutTableSection\n'
             'blink::LayoutObject::ContainerForFixedPosition\n'
             'blink::LayoutObject::Container\n'))

        self.testcase_bad_cast_without_crash_function = data_types.Testcase(
            job_type='linux_asan_chrome',
            fuzzer_name='libfuzzer_binary_name',
            crash_type='Bad-cast',
            crash_address='0x1337',
            crash_state=
            ('Bad-cast to blink::LayoutBlock from blink::LayoutTableSection\n'
             ))

        self.local_data_bundle = data_types.DataBundle(
            name='local_data_bundle')
        self.cloud_data_bundle = data_types.DataBundle(
            name='cloud_data_bundle')

        self.fuzzer1 = data_types.Fuzzer(name='fuzzer1',
                                         data_bundle_name=None,
                                         jobs=['linux_asan_chrome'])
        self.fuzzer2 = data_types.Fuzzer(name='fuzzer2',
                                         data_bundle_name='local_data_bundle',
                                         jobs=['linux_asan_chrome'])
        self.fuzzer3 = data_types.Fuzzer(name='fuzzer3',
                                         data_bundle_name='cloud_data_bundle',
                                         jobs=['linux_asan_chrome'])

        entities_to_put = [
            self.testcase, self.testcase_assert, self.testcase_null,
            self.testcase_bad_cast,
            self.testcase_bad_cast_without_crash_function, self.job, self.job2,
            self.local_data_bundle, self.cloud_data_bundle, self.fuzzer1,
            self.fuzzer2, self.fuzzer3
        ]
        for entity in entities_to_put:
            entity.put()

        environment.set_value('FUZZ_DATA',
                              '/tmp/inputs/fuzzer-common-data-bundles')
        environment.set_value('FUZZERS_DIR', '/tmp/inputs/fuzzers')
        self.mock.default_project_name.return_value = 'project'
        self.mock.project_config_get.side_effect = project_config_get
예제 #21
0
 def setUp(self):
     helpers.patch(self, [
         'build_management.build_manager.setup_regular_build',
         'bot.testcase_manager.test_for_crash_with_retries',
         'bot.testcase_manager.check_for_bad_build',
     ])
예제 #22
0
  def setUp(self):
    data_types.Job(
        name='job1',
        environment_string='ISSUE_VIEW_RESTRICTIONS = all',
        platform='linux').put()

    data_types.Job(
        name='job2',
        environment_string='ISSUE_VIEW_RESTRICTIONS = security',
        platform='linux').put()

    data_types.Job(
        name='job3',
        environment_string='ISSUE_VIEW_RESTRICTIONS = none',
        platform='linux').put()

    data_types.Job(
        name='chromeos_job4', environment_string='', platform='linux').put()

    testcase_args = {
        'crash_type': 'Heap-use-after-free',
        'crash_address': '0x1337',
        'crash_state': '1\n2\n3\n',
        'crash_stacktrace': 'stack\n',
        'fuzzer_name': 'fuzzer',
    }

    self.testcase1 = data_types.Testcase(job_type='job1', **testcase_args)
    self.testcase1.put()

    self.testcase1_security = data_types.Testcase(
        security_flag=True, job_type='job1', **testcase_args)
    self.testcase1_security.put()

    self.testcase2 = data_types.Testcase(job_type='job2', **testcase_args)
    self.testcase2.put()

    self.testcase2_security = data_types.Testcase(
        security_flag=True, job_type='job2', **testcase_args)
    self.testcase2_security.put()

    self.testcase3 = data_types.Testcase(job_type='job3', **testcase_args)
    self.testcase3.put()

    self.testcase3_security = data_types.Testcase(
        job_type='job3', security_flag=True, **testcase_args)
    self.testcase3_security.put()

    self.testcase4 = data_types.Testcase(
        job_type='chromeos_job4', **testcase_args)
    self.testcase4.put()

    self.testcase5 = data_types.Testcase(
        job_type='job',
        additional_metadata='{"issue_labels": "label1 , label2,,"}',
        **testcase_args)
    self.testcase5.put()

    self.testcase6 = data_types.Testcase(
        job_type='job', additional_metadata='invalid', **testcase_args)
    self.testcase5.put()

    data_types.ExternalUserPermission(
        email='*****@*****.**',
        entity_name='job2',
        entity_kind=data_types.PermissionEntityKind.JOB,
        is_prefix=False,
        auto_cc=data_types.AutoCCType.ALL).put()

    data_types.ExternalUserPermission(
        email='*****@*****.**',
        entity_name='job3',
        entity_kind=data_types.PermissionEntityKind.JOB,
        is_prefix=False,
        auto_cc=data_types.AutoCCType.SECURITY).put()

    helpers.patch(self, [
        'base.utils.utcnow',
        'datastore.data_handler.get_issue_description',
    ])

    self.mock.get_issue_description.return_value = 'Issue'
    self.mock.utcnow.return_value = datetime.datetime(2016, 1, 1)
    def setUp(self):
        """Set up."""
        super(CorpusPruningTestUntrusted, self).setUp()
        environment.set_value('JOB_NAME', 'libfuzzer_asan_job')

        helpers.patch(self, [
            'bot.fuzzers.engine.get', 'bot.tasks.setup.get_fuzzer_directory',
            'base.tasks.add_task',
            'bot.tasks.corpus_pruning_task._record_cross_pollination_stats'
        ])

        self.mock.get.return_value = libFuzzer_engine.LibFuzzerEngine()
        self.mock.get_fuzzer_directory.return_value = os.path.join(
            environment.get_value('ROOT_DIR'), 'src', 'python', 'bot',
            'fuzzers', 'libFuzzer')
        self.corpus_bucket = os.environ['CORPUS_BUCKET']
        self.quarantine_bucket = os.environ['QUARANTINE_BUCKET']
        self.backup_bucket = os.environ['BACKUP_BUCKET']

        job = data_types.Job(
            name='libfuzzer_asan_job',
            environment_string=(
                'APP_NAME = test_fuzzer\n'
                'CORPUS_BUCKET = {corpus_bucket}\n'
                'QUARANTINE_BUCKET = {quarantine_bucket}\n'
                'BACKUP_BUCKET={backup_bucket}\n'
                'RELEASE_BUILD_BUCKET_PATH = '
                'gs://clusterfuzz-test-data/test_libfuzzer_builds/'
                'test-libfuzzer-build-([0-9]+).zip\n'
                'REVISION_VARS_URL = gs://clusterfuzz-test-data/'
                'test_libfuzzer_builds/'
                'test-libfuzzer-build-%s.srcmap.json\n'.format(
                    corpus_bucket=self.corpus_bucket,
                    quarantine_bucket=self.quarantine_bucket,
                    backup_bucket=self.backup_bucket)))
        job.put()

        job = data_types.Job(
            name='libfuzzer_asan_job2',
            environment_string=(
                'APP_NAME = test2_fuzzer\n'
                'BACKUP_BUCKET = {backup_bucket}\n'
                'CORPUS_FUZZER_NAME_OVERRIDE = libfuzzer\n'.format(
                    backup_bucket=self.backup_bucket)))
        job.put()

        os.environ['PROJECT_NAME'] = 'oss-fuzz'
        data_types.FuzzTarget(engine='libFuzzer',
                              project='test',
                              binary='test_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job',
                                 last_run=datetime.datetime.now()).put()

        data_types.FuzzTarget(engine='libFuzzer',
                              project='test2',
                              binary='fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test2_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job2',
                                 last_run=datetime.datetime.now()).put()

        environment.set_value('USE_MINIJAIL', True)
        environment.set_value('SHARED_CORPUS_BUCKET', TEST_SHARED_BUCKET)

        # Set up remote corpora.
        self.corpus = corpus_manager.FuzzTargetCorpus('libFuzzer',
                                                      'test_fuzzer')
        self.corpus.rsync_from_disk(os.path.join(TEST_DIR, 'corpus'),
                                    delete=True)

        self.quarantine_corpus = corpus_manager.FuzzTargetCorpus(
            'libFuzzer', 'test_fuzzer', quarantine=True)
        self.quarantine_corpus.rsync_from_disk(os.path.join(
            TEST_DIR, 'quarantine'),
                                               delete=True)

        self.mock.get_data_bundle_bucket_name.return_value = TEST_GLOBAL_BUCKET
        data_types.DataBundle(name='bundle',
                              is_local=True,
                              sync_to_worker=True).put()

        data_types.Fuzzer(revision=1,
                          file_size='builtin',
                          source='builtin',
                          name='libFuzzer',
                          max_testcases=4,
                          builtin=True,
                          data_bundle_name='bundle').put()

        self.temp_dir = tempfile.mkdtemp()

        # Copy corpus backup in the older date format.
        corpus_backup_date = (
            datetime.datetime.utcnow().date() - datetime.timedelta(
                days=data_types.CORPUS_BACKUP_PUBLIC_LOOKBACK_DAYS))
        corpus_backup_dir = ('gs://{bucket}/corpus/libfuzzer/test2_fuzzer/')
        gsutil.GSUtilRunner().run_gsutil([
            'cp', (corpus_backup_dir +
                   'backup.zip').format(bucket=TEST2_BACKUP_BUCKET),
            (corpus_backup_dir +
             '%s.zip' % corpus_backup_date).format(bucket=self.backup_bucket)
        ])
예제 #24
0
 def setUp(self):
     test_helpers.patch(self, [
         'fuzzing.corpus_manager._count_corpus_files',
         'google_cloud_utils.gsutil.GSUtilRunner.run_gsutil',
     ])
예제 #25
0
 def setUp(self):
   super(ResetUsbTest, self).setUp()
   test_helpers.patch(self, ['fcntl.ioctl'])
예제 #26
0
 def setUp(self):
     test_helpers.patch(self, [
         'libs.access.get_access',
     ])
예제 #27
0
 def setUp(self):
     test_helpers.patch(self, [
         'base.utils.utcnow',
     ])
     self.mock.utcnow.return_value = datetime.datetime(2018, 1, 1)
예제 #28
0
 def setUp(self):
     test_helpers.patch(
         self,
         ['config.db_config.get_value', 'libs.helpers.get_user_email'])
예제 #29
0
 def setUp(self):
     helpers.patch(self, ['local.butler.common.execute'])
     self.mock.execute.return_value = (0, 'ok')
예제 #30
0
 def setUp(self):
     test_helpers.patch(self, ['config.db_config.get_value'])