def setUp(self): test_helpers.patch_environ(self) self.app = webtest.TestApp( webapp2.WSGIApplication([('/schedule-ml-train-tasks', ml_train.Handler)])) test_helpers.patch( self, ['base.tasks.add_task', 'handlers.base_handler.Handler.is_cron']) # Create fake jobs. data_types.Job(name='libfuzzer_asan', environment_string='USE_CORPUS_FOR_ML = True\n').put() data_types.Job(name='libfuzzer_msan', environment_string='USE_CORPUS_FOR_ML = True\n').put() data_types.Job(name='afl_asan', environment_string='USE_CORPUS_FOR_ML = False\n').put() # Create fake fuzzers. data_types.Fuzzer(name='libFuzzer', jobs=['libfuzzer_asan']).put() 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()
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']) # Create fake jobs. data_types.Job(name='libfuzzer_asan', environment_string='USE_CORPUS_FOR_ML = True\n').put() data_types.Job(name='libfuzzer_msan', environment_string='USE_CORPUS_FOR_ML = True\n').put() data_types.Job(name='afl_asan', environment_string='USE_CORPUS_FOR_ML = False\n').put() # Create fake fuzzers. data_types.Fuzzer(name='libFuzzer', jobs=['libfuzzer_asan']).put() 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()
def setUp(self): self.fuzzer_1 = data_types.Fuzzer() self.fuzzer_1.name = 'fuzzer_1' self.fuzzer_1.put() self.fuzzer_2 = data_types.Fuzzer() self.fuzzer_2.name = 'fuzzer_2' self.fuzzer_2.put()
def post(self): """Handle a post request.""" name = self.request.get('name') if not name: raise helpers.EarlyExitException('Please give the fuzzer a name!', 400) if not data_types.Fuzzer.VALID_NAME_REGEX.match(name): raise helpers.EarlyExitException( 'Fuzzer name can only contain letters, numbers, dashes and ' 'underscores.', 400) existing_fuzzer = data_types.Fuzzer.query( data_types.Fuzzer.name == name) if existing_fuzzer.get(): raise helpers.EarlyExitException( 'Fuzzer already exists. Please use the EDIT button for changes.', 400) upload_info = self.get_upload() if not upload_info: raise helpers.EarlyExitException('Need to upload an archive.', 400) fuzzer = data_types.Fuzzer() fuzzer.name = name fuzzer.revision = 0 self.apply_fuzzer_changes(fuzzer, upload_info)
def setUp(self): """Set up.""" super(UntrustedRunnerIntegrationTest, self).setUp() test_helpers.patch(self, [ 'datastore.data_handler.get_data_bundle_bucket_name', ]) data_types.Config().put() environment_string = ('APP_NAME = app\n' 'RELEASE_BUILD_BUCKET_PATH = ' 'gs://clusterfuzz-test-data/test_builds/' 'test-build-([0-9]+).zip\n') data_types.Job(name='job', environment_string=environment_string).put() environment_string = ('APP_NAME = launcher.py\n' 'RELEASE_BUILD_BUCKET_PATH = ' 'gs://clusterfuzz-test-data/test_libfuzzer_builds/' 'test-libfuzzer-build-([0-9]+).zip\n' 'UNPACK_ALL_FUZZ_TARGETS_AND_FILES = True') data_types.Job( name='libfuzzer_asan_job', environment_string=environment_string).put() data_types.Fuzzer(name='fuzzer', data_bundle_name='bundle').put() data_types.DataBundle( name='bundle', is_local=True, sync_to_worker=True).put()
def setUp(self): helpers.patch_environ(self) test_utils.set_up_pyfakefs(self) self.fs.create_dir('/input') self.fs.create_dir('/output') helpers.patch(self, [ 'bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.run', 'metrics.fuzzer_logs.get_bucket', 'google_cloud_utils.blobs.write_blob', ]) self.fuzzer = data_types.Fuzzer(revision=1, file_size='builtin', source='builtin', name='libFuzzer', max_testcases=4, builtin=True) self.fuzzer.put() self.fuzzer_directory = os.path.join(environment.get_value('ROOT_DIR'), 'src', 'python', 'bot', 'fuzzers', 'libFuzzer') # Needed since local config is not available with fakefs. self.mock.get_bucket.return_value = None self.mock.write_blob.return_value = 'sample' environment.set_value('JOB_NAME', 'job') environment.set_value('INPUT_DIR', '/input')
def setUp(self): """Set up.""" super(MinimizeTaskTestUntrusted, self).setUp() environment.set_value("JOB_NAME", "libfuzzer_asan_job") helpers.patch(self, ["datastore.data_handler.get_data_bundle_bucket_name"]) patcher = mock.patch( "bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.fuzzer_directory", new_callable=mock.PropertyMock, ) mock_fuzzer_directory = patcher.start() self.addCleanup(patcher.stop) mock_fuzzer_directory.return_value = os.path.join( environment.get_value("ROOT_DIR"), "src", "python", "bot", "fuzzers", "libFuzzer", ) job = data_types.Job( name="libfuzzer_asan_job", environment_string=( "RELEASE_BUILD_BUCKET_PATH = " "gs://clusterfuzz-test-data/test_libfuzzer_builds/" "test-libfuzzer-build-([0-9]+).zip\n" "REVISION_VARS_URL = https://commondatastorage.googleapis.com/" "clusterfuzz-test-data/test_libfuzzer_builds/" "test-libfuzzer-build-%s.srcmap.json\n"), ) job.put() 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() environment.set_value("USE_MINIJAIL", True) data_types.Fuzzer( revision=1, file_size="builtin", source="builtin", name="libFuzzer", max_testcases=4, builtin=True, ).put() self.temp_dir = tempfile.mkdtemp( dir=environment.get_value("FUZZ_INPUTS"))
def test_no_mappings(self): """Ensure that we do nothing if a fuzzer has no mappings.""" fuzzer = data_types.Fuzzer() fuzzer.name = 'no_mappings' fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer) self.assertEqual(_get_job_list_for_fuzzer(fuzzer), [])
def test_mapping_removed(self): """Ensure that mappings are removed properly.""" fuzzer = data_types.Fuzzer() fuzzer.name = 'adding_jobs' fuzzer.jobs = ['job_1'] fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer, []) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertEqual([], mappings)
def test_new_addition(self): """Ensure that we add mappings for a new fuzzer.""" fuzzer = data_types.Fuzzer() fuzzer.name = 'new_addition' fuzzer.jobs = ['job_1', 'job_2'] fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertIn('job_1', mappings) self.assertIn('job_2', mappings)
def create_fuzzer(self): """Create a Fuzzer data_type with columns set to the defaults specified by this object.""" assert self.name is not None return data_types.Fuzzer( id=self.key_id, revision=self.revision, file_size=self.file_size, source=self.source, name=self.name, builtin=self.builtin, stats_column_descriptions=self.stats_column_descriptions, stats_columns=self.stats_columns)
def test_fuzzers_result(self): """Test fuzzers result obtained in post method.""" self.mock.has_access.return_value = True job = self._create_job('test_job', 'APP_NAME = launcher.py\n') fuzzer = data_types.Fuzzer() fuzzer.name = 'fuzzer' fuzzer.jobs = ['test_job'] fuzzer.put() resp = self.app.post_json('/', {'page': 1}) self.assertListEqual([job.key.id()], [item['id'] for item in resp.json['items']]) self.assertIn('fuzzer', resp.json['items'][0]['fuzzers'])
def setUp(self): """Set up.""" super(MinimizeTaskTestUntrusted, self).setUp() environment.set_value('JOB_NAME', 'libfuzzer_asan_job') helpers.patch(self, [ 'datastore.data_handler.get_data_bundle_bucket_name', ]) patcher = mock.patch( 'bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.fuzzer_directory', new_callable=mock.PropertyMock) mock_fuzzer_directory = patcher.start() self.addCleanup(patcher.stop) mock_fuzzer_directory.return_value = os.path.join( environment.get_value('ROOT_DIR'), 'src', 'python', 'bot', 'fuzzers', 'libFuzzer') job = data_types.Job( name='libfuzzer_asan_job', environment_string=( 'APP_NAME = launcher.py\n' 'RELEASE_BUILD_BUCKET_PATH = ' 'gs://clusterfuzz-test-data/test_libfuzzer_builds/' 'test-libfuzzer-build-([0-9]+).zip\n' 'REVISION_VARS_URL = https://commondatastorage.googleapis.com/' 'clusterfuzz-test-data/test_libfuzzer_builds/' 'test-libfuzzer-build-%s.srcmap.json\n')) job.put() 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() environment.set_value('USE_MINIJAIL', True) data_types.Fuzzer(revision=1, file_size='builtin', source='builtin', name='libFuzzer', max_testcases=4, builtin=True).put() self.temp_dir = tempfile.mkdtemp( dir=environment.get_value('FUZZ_INPUTS'))
def setUp(self): self.app = webtest.TestApp( webapp2.WSGIApplication([('/load-bigquery-stats', load_bigquery_stats.Handler)])) data_types.Fuzzer(name='fuzzer', jobs=['job']).put() data_types.Job(name='job').put() test_helpers.patch(self, [ 'google_cloud_utils.big_query.get_api_client', 'handlers.base_handler.Handler.is_cron', 'handlers.cron.load_bigquery_stats.Handler._utc_now', ]) self.mock._utc_now.return_value = datetime.datetime(2016, 9, 8) # pylint: disable=protected-access self.mock_bigquery = mock.MagicMock() self.mock.get_api_client.return_value = self.mock_bigquery
def setUp(self): flaskapp = flask.Flask('testflask') flaskapp.add_url_rule( '/load-bigquery-stats', view_func=load_bigquery_stats.Handler.as_view('/load-bigquery-stats')) self.app = webtest.TestApp(flaskapp) data_types.Fuzzer(name='fuzzer', jobs=['job']).put() data_types.Job(name='job').put() test_helpers.patch(self, [ 'google_cloud_utils.big_query.get_api_client', 'handlers.base_handler.Handler.is_cron', 'handlers.cron.load_bigquery_stats.Handler._utc_now', ]) self.mock._utc_now.return_value = datetime.datetime(2016, 9, 8) # pylint: disable=protected-access self.mock_bigquery = mock.MagicMock() self.mock.get_api_client.return_value = self.mock_bigquery
def test_mapping_subsituted(self): """Ensure that mappings are subsituted properly.""" fuzzer = data_types.Fuzzer() fuzzer.name = 'adding_jobs' fuzzer.jobs = ['job_1'] fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertIn('job_1', mappings) self.assertNotIn('job_2', mappings) fuzzer.jobs = ['job_2'] fuzzer_selection.update_mappings_for_fuzzer(fuzzer) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertNotIn('job_1', mappings) self.assertIn('job_2', mappings)
def test_mapping_added(self): """Ensure that we properly add mappings for existing fuzzers.""" fuzzer = data_types.Fuzzer() fuzzer.name = 'adding_jobs' fuzzer.jobs = ['job_1'] fuzzer.put() fuzzer_selection.update_mappings_for_fuzzer(fuzzer) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertIn('job_1', mappings) self.assertNotIn('job_2', mappings) fuzzer.jobs += ['job_2'] fuzzer_selection.update_mappings_for_fuzzer(fuzzer) mappings = _get_job_list_for_fuzzer(fuzzer) self.assertIn('job_1', mappings) self.assertIn('job_2', mappings)
def setUp(self): helpers.patch_environ(self) test_utils.set_up_pyfakefs(self) self.fs.create_dir("/input") self.fs.create_dir("/output") helpers.patch( self, [ "bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.run", "metrics.fuzzer_logs.get_bucket", "google_cloud_utils.blobs.write_blob", ], ) self.fuzzer = data_types.Fuzzer( revision=1, file_size="builtin", source="builtin", name="libFuzzer", max_testcases=4, builtin=True, ) self.fuzzer.put() self.fuzzer_directory = os.path.join( environment.get_value("ROOT_DIR"), "src", "python", "bot", "fuzzers", "libFuzzer", ) # Needed since local config is not available with fakefs. self.mock.get_bucket.return_value = None self.mock.write_blob.return_value = "sample" environment.set_value("JOB_NAME", "job") environment.set_value("INPUT_DIR", "/input")
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()
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): """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) ])
def setUp(self): test_helpers.patch_environ(self) # Set up a Fuzzer. data_types.Fuzzer( revision=1, additional_environment_string= 'FUCHSIA_RESOURCES_URL = gs://fuchsia-on-clusterfuzz-v2/*', builtin=True, differential=False, file_size='builtin', jobs=['libfuzzer_asan_test_fuzzer'], name='libFuzzer', source='builtin', max_testcases=4).put() # Set up a FuzzerJob. data_types.FuzzerJob(fuzzer='libFuzzer', job='libfuzzer_asan_test_fuzzer', platform='FUCHSIA', weight=1.0).put() # Set up a FuzzTarget data_types.FuzzTarget(binary='libfuzzer_asan_test_fuzzer', engine='libFuzzer', project='test-project').put() # Set up a FuzzTargetJob data_types.FuzzTargetJob( engine='libFuzzer', fuzz_target_name='libFuzzer_libfuzzer_asan_test_fuzzer', job='libfuzzer_asan_test_fuzzer', weight=1.0).put() # Set up a Job data_types.Job(environment_string=( 'CUSTOM_BINARY = True\n' 'FUCHSIA_RESOURCES_URL = gs://fuchsia-on-clusterfuzz-v2/*\n' 'QUEUE_OVERRIDE=FUCHSIA\n' 'OS_OVERRIDE=FUCHSIA'), name='libfuzzer_asan_test_fuzzer', platform='FUCHSIA', templates=['libfuzzer', 'engine_asan']).put() # Set up a JobTemplate data_types.JobTemplate( name='libfuzzer', environment_string=('APP_NAME = launcher.py\n' 'MAX_FUZZ_THREADS = 1\n' 'MAX_TESTCASES = 4\n' 'FUZZ_TEST_TIMEOUT = 4800\n' 'TEST_TIMEOUT = 30\n' 'WARMUP_TIMEOUT = 30\n' 'BAD_BUILD_CHECK = False\n' 'THREAD_ALIVE_CHECK_INTERVAL = 1\n' 'REPORT_OOMS_AND_HANGS = True\n' 'CORPUS_FUZZER_NAME_OVERRIDE = libFuzzer\n' 'ENABLE_GESTURES = False\n' 'THREAD_DELAY = 30.0')).put() # Set up another JobTemplate data_types.JobTemplate( name='engine_asan', environment_string= ('LSAN = True\n' 'ADDITIONAL_ASAN_OPTIONS = quarantine_size_mb=64:strict_memcmp=1' ':symbolize=0:fast_unwind_on_fatal=0' ':allocator_release_to_os_interval_ms=500\n')).put() environment.set_value('QUEUE_OVERRIDE', 'FUCHSIA') environment.set_value('OS_OVERRIDE', 'FUCHSIA') environment.set_value('FUCHSIA_RESOURCES_URL', 'gs://fuchsia-on-clusterfuzz-v2/*') # set_bot_environment gives us access to RESOURCES_DIR environment.set_bot_environment() # Cannot simply call super(TestLauncherFuchsia).setUp, because the # with_cloud_emulators decorator modifies what the parent class would be. # Just explicitly call BaseLauncherTest's setUp. BaseLauncherTest.setUp(self)
def setUp(self): BaseIntegrationTest.setUp(self) # Set up a Fuzzer. data_types.Fuzzer( revision=1, additional_environment_string= 'FUCHSIA_BUILD_URL = gs://fuchsia-clusterfuzz-test-august-12-2019/*\n', builtin=True, differential=False, file_size='builtin', jobs=['libfuzzer_asan_test_fuzzer'], name='libFuzzer', source='builtin', max_testcases=4).put() # Set up a FuzzerJob. data_types.FuzzerJob( fuzzer='libFuzzer', job='libfuzzer_asan_test_fuzzer', platform='FUCHSIA', weight=1.0).put() # Set up a FuzzTarget data_types.FuzzTarget( binary='libfuzzer_asan_test_fuzzer', engine='libFuzzer', project='test-project').put() # Set up a FuzzTargetJob data_types.FuzzTargetJob( engine='libFuzzer', fuzz_target_name='libFuzzer_libfuzzer_asan_test_fuzzer', job='libfuzzer_asan_test_fuzzer', weight=1.0).put() # Set up a Job data_types.Job( environment_string=( 'CUSTOM_BINARY = True\n' 'FUCHSIA_BUILD_URL = gs://fuchsia-clusterfuzz-test-august-12-2019/*' '\n' 'QUEUE_OVERRIDE=FUCHSIA\n' 'OS_OVERRIDE=FUCHSIA'), name='libfuzzer_asan_test_fuzzer', platform='FUCHSIA', templates=['libfuzzer', 'engine_asan']).put() # Set up a JobTemplate data_types.JobTemplate( name='libfuzzer', environment_string=('MAX_FUZZ_THREADS = 1\n' 'MAX_TESTCASES = 4\n' 'FUZZ_TEST_TIMEOUT = 4800\n' 'TEST_TIMEOUT = 30\n' 'WARMUP_TIMEOUT = 30\n' 'BAD_BUILD_CHECK = False\n' 'THREAD_ALIVE_CHECK_INTERVAL = 1\n' 'REPORT_OOMS_AND_HANGS = True\n' 'CORPUS_FUZZER_NAME_OVERRIDE = libFuzzer\n' 'ENABLE_GESTURES = False\n' 'THREAD_DELAY = 30.0')).put() # Set up another JobTemplate data_types.JobTemplate( name='engine_asan', environment_string=( 'LSAN = True\n' 'ADDITIONAL_ASAN_OPTIONS = quarantine_size_mb=64:strict_memcmp=1' ':symbolize=0:fast_unwind_on_fatal=0' ':allocator_release_to_os_interval_ms=500\n')).put() environment.set_value('QUEUE_OVERRIDE', 'FUCHSIA') environment.set_value('OS_OVERRIDE', 'FUCHSIA') environment.set_value('FUCHSIA_BUILD_URL', 'gs://fuchsia-clusterfuzz-test-august-12-2019/*') self.tmp_resources_dir = tempfile.mkdtemp() environment.set_value('RESOURCES_DIR', self.tmp_resources_dir)
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
def setUp(self): helpers.patch_environ(self) # Fake permissions. data_types.ExternalUserPermission( email='*****@*****.**', entity_name='fuzzer', entity_kind=data_types.PermissionEntityKind.FUZZER, auto_cc=data_types.AutoCCType.ALL).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='fuzz', entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.SECURITY).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='parent_', entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='parent', entity_kind=data_types.PermissionEntityKind.FUZZER, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='parent_cg', entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='parens', entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='parent', entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.ALL).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=True, auto_cc=data_types.AutoCCType.ALL).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='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job2', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job3', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name=None, entity_kind=data_types.PermissionEntityKind.UPLOADER, is_prefix=False, auto_cc=data_types.AutoCCType.NONE).put() # Fake fuzzers. data_types.Fuzzer(name='fuzzer').put() data_types.Fuzzer(name='parent', jobs=['job', 'job2', 'job3']).put() data_types.Job(name='job').put() data_types.Job(name='job2').put() data_types.Job(name='job3').put() data_types.FuzzTarget(engine='parent', binary='child', project='test-project').put() data_types.FuzzTargetJob(fuzz_target_name='parent_child', job='job', last_run=datetime.datetime.utcnow()).put() data_types.FuzzTarget(engine='parent', binary='child2', project='test-project').put() data_types.FuzzTargetJob(fuzz_target_name='parent_child2', job='job', last_run=datetime.datetime.utcnow()).put() data_types.FuzzTarget(engine='parent', binary='child', project='test-project').put() data_types.FuzzTargetJob(fuzz_target_name='parent_child', job='job3', last_run=datetime.datetime.utcnow()).put()
def setUp(self): self.app = webtest.TestApp( webapp2.WSGIApplication([('/setup', oss_fuzz_setup.Handler)])) helpers.patch_environ(self) data_types.Config( revision_vars_url=('libfuzzer_asan_lib2;url\n' 'blah;url2\n')).put() data_types.Job( name='libfuzzer_asan_old_job', environment_string=('MANAGED = True\n' 'PROJECT_NAME = old\n')).put() data_types.Job( name='libfuzzer_msan_old_job', environment_string=('MANAGED = True\n' 'PROJECT_NAME = old\n')).put() data_types.Job(name='unmanaged_job', environment_string='').put() # Will be removed. data_types.ExternalUserPermission( entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL, entity_name='libfuzzer_asan_lib1', email='*****@*****.**').put() # Existing CC. Makes sure no duplicates are created. data_types.ExternalUserPermission( entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL, entity_name='libfuzzer_asan_lib1', email='*****@*****.**').put() # Existing project settings. Should not get modified. data_types.OssFuzzProject(id='lib1', name='lib1', cpu_weight=1.5).put() # Should get deleted. data_types.OssFuzzProject(id='old_lib', name='old_lib').put() self.libfuzzer = data_types.Fuzzer(name='libFuzzer', jobs=[]) self.libfuzzer.data_bundle_name = 'global' self.libfuzzer.jobs = ['libfuzzer_asan_old_job', 'libfuzzer_msan_old_job'] self.libfuzzer.put() self.afl = data_types.Fuzzer(name='afl', jobs=[]) self.afl.data_bundle_name = 'global' self.afl.jobs = ['afl_asan_old_job', 'afl_msan_old_job'] self.afl.put() helpers.patch(self, [ 'base.utils.is_oss_fuzz', ('get_application_id_1', 'google.appengine.api.app_identity.get_application_id'), ('get_application_id_2', 'base.utils.get_application_id'), 'google_cloud_utils.storage.build', 'time.sleep', 'handlers.base_handler.Handler.is_cron', 'handlers.cron.oss_fuzz_setup.get_projects', 'handlers.cron.service_accounts.get_or_create_service_account', 'handlers.cron.service_accounts.set_service_account_roles', ]) self.mock.get_or_create_service_account.side_effect = ( _mock_get_or_create_service_account) self.mock.is_oss_fuzz.return_value = True
def setUp(self): helpers.patch_environ(self) # Fake permissions. data_types.ExternalUserPermission( email="*****@*****.**", entity_name="fuzzer", entity_kind=data_types.PermissionEntityKind.FUZZER, auto_cc=data_types.AutoCCType.ALL, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="fuzz", entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.SECURITY, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="parent_", entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="parent", entity_kind=data_types.PermissionEntityKind.FUZZER, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="parent_cg", entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="parens", entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="parent", entity_kind=data_types.PermissionEntityKind.FUZZER, is_prefix=True, auto_cc=data_types.AutoCCType.ALL, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="job", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="job", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=True, auto_cc=data_types.AutoCCType.ALL, ).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="job", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="job2", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="job", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name="job3", entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.NONE, ).put() data_types.ExternalUserPermission( email="*****@*****.**", entity_name=None, entity_kind=data_types.PermissionEntityKind.UPLOADER, is_prefix=False, auto_cc=data_types.AutoCCType.NONE, ).put() # Fake fuzzers. data_types.Fuzzer(name="fuzzer").put() data_types.Fuzzer(name="parent", jobs=["job", "job2", "job3"]).put() data_types.Job(name="job").put() data_types.Job(name="job2").put() data_types.Job(name="job3").put() data_types.FuzzTarget(engine="parent", binary="child", project="test-project").put() data_types.FuzzTargetJob( fuzz_target_name="parent_child", job="job", last_run=datetime.datetime.utcnow(), ).put() data_types.FuzzTarget(engine="parent", binary="child2", project="test-project").put() data_types.FuzzTargetJob( fuzz_target_name="parent_child2", job="job", last_run=datetime.datetime.utcnow(), ).put() data_types.FuzzTarget(engine="parent", binary="child", project="test-project").put() data_types.FuzzTargetJob( fuzz_target_name="parent_child", job="job3", last_run=datetime.datetime.utcnow(), ).put()
def setUp(self): test_helpers.patch_environ(self) self.maxDiff = None # pylint: disable=invalid-name data_types.Fuzzer( name='testFuzzer', stats_columns=('sum(t.blah) as blah, custom(j.new_crashes) ' 'as new_crashes, _EDGE_COV as edge_coverage, ' '_FUNC_COV as func_coverage, ' '_CORPUS_SIZE as corpus_size, ' '_CORPUS_BACKUP as corpus_backup, ' '_QUARANTINE_SIZE as quarantine_size, ' '_COV_REPORT as coverage_report, ' '_FUZZER_RUN_LOGS as fuzzer_logs,' '_PERFORMANCE_REPORT as performance_report'), stats_column_descriptions=( 'blah: "blah description"\n' 'func_coverage: "func coverage description"\n')).put() data_types.Fuzzer( name='testFuzzer2', stats_columns=('sum(t.blah) as blah, custom(j.new_crashes) ' 'as new_crashes, _EDGE_COV as edge_coverage, ' '_FUNC_COV as func_coverage, ' '_CORPUS_SIZE as corpus_size, ' '_CORPUS_BACKUP as corpus_backup, ' '_QUARANTINE_SIZE as quarantine_size, ' '_COV_REPORT as coverage_report, ' '_FUZZER_RUN_LOGS as fuzzer_logs,' '_PERFORMANCE_REPORT as performance_report'), stats_column_descriptions=( 'blah: "blah description"\n' 'func_coverage: "func coverage description"\n')).put() data_types.Job( name='job', environment_string='FUZZ_LOGS_BUCKET = bucket').put() now = datetime.datetime.utcnow() data_types.FuzzTarget( engine='testFuzzer', project='test-project', binary='1_fuzzer').put() data_types.FuzzTargetJob( fuzz_target_name='testFuzzer_1_fuzzer', job='job', last_run=now).put() data_types.FuzzTarget( engine='testFuzzer', project='test-project', binary='2_fuzzer').put() data_types.FuzzTargetJob( fuzz_target_name='testFuzzer_2_fuzzer', job='job', last_run=now).put() data_types.FuzzTarget( engine='testFuzzer', project='test-project', binary='3_fuzzer').put() data_types.FuzzTargetJob( fuzz_target_name='testFuzzer_3_fuzzer', job='job', last_run=now).put() data_types.FuzzTarget( engine='testFuzzer2', project='test-project', binary='1_fuzzer').put() data_types.FuzzTargetJob( fuzz_target_name='testFuzzer2_1_fuzzer', job='job', last_run=now).put() cov_info = data_types.CoverageInformation( fuzzer='2_fuzzer', date=datetime.date(2016, 10, 19)) cov_info.edges_covered = 11 cov_info.edges_total = 30 cov_info.functions_covered = 10 cov_info.functions_total = 15 cov_info.html_report_url = 'https://report_for_2_fuzzer/20161019' cov_info.corpus_size_units = 20 cov_info.corpus_size_bytes = 200 cov_info.quarantine_size_units = 0 cov_info.quarantine_size_bytes = 0 cov_info.corpus_location = 'gs://corpus' cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip' cov_info.quarantine_location = 'gs://quarantine' cov_info.put() cov_info = data_types.CoverageInformation( fuzzer='2_fuzzer', date=datetime.date(2016, 10, 21)) cov_info.edges_covered = 15 cov_info.edges_total = 30 cov_info.functions_covered = 11 cov_info.functions_total = 15 cov_info.html_report_url = 'https://report_for_2_fuzzer/20161021' cov_info.corpus_size_units = 40 cov_info.corpus_size_bytes = 400 cov_info.quarantine_size_units = 8 cov_info.quarantine_size_bytes = 80 cov_info.corpus_location = 'gs://corpus' cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip' cov_info.quarantine_location = 'gs://quarantine' cov_info.put() cov_info = data_types.CoverageInformation( fuzzer='1_fuzzer', date=datetime.date(2016, 10, 20)) cov_info.edges_covered = 17 cov_info.edges_total = 38 cov_info.functions_covered = 12 cov_info.functions_total = 19 cov_info.html_report_url = 'https://report_for_1_fuzzer/20161020' cov_info.corpus_size_units = 47 cov_info.corpus_size_bytes = 480 cov_info.quarantine_size_units = 3 cov_info.quarantine_size_bytes = 8 cov_info.corpus_location = 'gs://corpus' cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip' cov_info.quarantine_location = 'gs://quarantine' cov_info.put() self.client = mock.Mock(spec_set=big_query.Client) test_helpers.patch(self, [ 'google_cloud_utils.big_query.Client', ]) self.mock.Client.return_value = self.client