Пример #1
0
    def setUp(self):
        clear_temp_dir()
        create_temp_dir()

        test_helpers.patch_environ(self)
        afl_launcher_integration_test.dont_use_strategies(self)
        environment.set_value('BUILD_DIR', DATA_DIRECTORY)
Пример #2
0
    def setUp(self):
        """Set up test environment."""
        test_helpers.patch_environ(self)
        environment.set_value('FUZZ_TEST_TIMEOUT', '4800')

        self.build_dir = os.path.join(SCRIPT_DIR, 'run_data', 'build_dir')
        self.corpus_directory = 'data/corpus_with_some_files'
    def setUp(self):
        test_utils.set_up_pyfakefs(self)
        helpers.patch_environ(self)
        helpers.patch(self, [
            'clusterfuzz._internal.google_cloud_utils.storage.copy_file_to',
        ])

        os.environ['CORPUS_BUCKET'] = 'corpus'

        fuzz_target = data_types.FuzzTarget(
            id='libFuzzer_test_project_test_fuzzer')
        fuzz_target.binary = 'test_fuzzer'
        fuzz_target.project = 'test_project'
        fuzz_target.engine = 'libFuzzer'
        fuzz_target.put()

        self.testcase = data_types.Testcase()
        self.testcase.fuzzer_name = 'libFuzzer'
        self.testcase.overridden_fuzzer_name = 'libFuzzer_test_project_test_fuzzer'
        self.testcase.job_type = 'job'
        self.testcase.bug_information = '123'
        self.testcase.open = False
        self.testcase.put()

        self.testcase_file_path = '/testcase'
        self.fs.create_file(self.testcase_file_path, contents='A')
    def setUp(self):
        """Prepare test data and necessary env variables."""
        self.maxDiff = None  # pylint: disable=invalid-name

        test_helpers.patch_environ(self)
        self.data_directory = os.path.join(os.path.dirname(__file__),
                                           'libfuzzer_test_data')
Пример #5
0
    def setUp(self):
        test_helpers.patch_environ(self)
        test_utils.set_up_pyfakefs(self)
        environment.set_value('CACHE_DIR', '/tmp/test-cache')
        persistent_cache.initialize()

        self.cache = memoize.FifoOnDisk(5)
Пример #6
0
    def setUp(self):
        test_helpers.patch(self, [
            'clusterfuzz._internal.build_management.build_manager.set_environment_vars',
            'clusterfuzz._internal.bot.untrusted_runner.host.stub',
        ])

        test_helpers.patch_environ(self)
Пример #7
0
  def setUp(self):
    helpers.patch(self, [
        'clusterfuzz._internal.bot.untrusted_runner.host.stub',
    ])

    helpers.patch_environ(self)
    os.environ['WORKER_ROOT_DIR'] = '/worker'
Пример #8
0
    def setUp(self):
        self.maxDiff = None  # pylint: disable=invalid-name
        test_helpers.patch_environ(self)
        test_helpers.patch(self, [
            'clusterfuzz._internal.google_cloud_utils.blobs.get_blob_info',
            'clusterfuzz._internal.google_cloud_utils.blobs.write_blob',
            'libs.access.has_access',
            'libs.helpers.get_user_email',
            'clusterfuzz._internal.base.utils.current_date_time',
            'clusterfuzz._internal.base.utils.utcnow',
        ])

        self.mock.get_blob_info.return_value.filename = 'input'
        self.mock.get_blob_info.return_value.key.return_value = 'blob_key'
        self.mock.write_blob.return_value = 'blob_key'
        self.mock.has_access.return_value = True
        self.mock.current_date_time.return_value = '2021-01-01 00:00:00 UTC'
        self.mock.utcnow.return_value = datetime.datetime(2021, 1, 1)
        self.mock.get_user_email.return_value = 'uploader@email'

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

        data_types.Job(name='libfuzzer_proj_external',
                       environment_string='PROJECT_NAME = proj',
                       platform='LINUX',
                       external_reproduction_topic='topic',
                       external_updates_subscription='sub').put()

        self.app = flask.Flask('testflask')
        self.app.add_url_rule(
            '/', view_func=upload_testcase.UploadHandlerOAuth.as_view(''))
Пример #9
0
    def setUp(self):
        helpers.patch_environ(self)
        helpers.patch(self, [
            'clusterfuzz._internal.base.persistent_cache.get_value',
            'clusterfuzz._internal.base.persistent_cache.set_value',
            'clusterfuzz._internal.base.utils.utcnow',
            'time.sleep',
        ])

        self.mock.get_value.return_value = None
        self.mock.sleep.return_value = None
        data_types.Job(name='job').put()

        client = pubsub.PubSubClient()
        topic = pubsub.topic_name('test-clusterfuzz', 'jobs-linux')
        client.create_topic(topic)
        client.create_subscription(
            pubsub.subscription_name('test-clusterfuzz', 'jobs-linux'), topic)

        topic = pubsub.topic_name('test-clusterfuzz', 'high-end-jobs-linux')
        client.create_topic(topic)
        client.create_subscription(
            pubsub.subscription_name('test-clusterfuzz',
                                     'high-end-jobs-linux'), topic)

        self.mock.utcnow.return_value = test_utils.CURRENT_TIME.replace(
            microsecond=0)
  def setUp(self):
    """Setup for upload testcase output test."""
    test_helpers.patch_environ(self)
    test_utils.set_up_pyfakefs(self)
    self.testcase_path = '/test/fuzzer/testcase'
    self.fs.create_file(self.testcase_path, contents='')

    environment.set_value('FUZZ_LOGS_BUCKET', 'fake-gcs-logs')
    environment.set_value('FUZZER_NAME', 'fuzzer')
    environment.set_value('JOB_NAME', 'job')
    environment.set_value('APP_REVISION', '123')

    # To be used for generation of date and time when uploading a log.
    fake_utcnow = datetime.datetime(2017, 5, 15, 16, 10, 28, 374119)

    # Original utcfromtimestamp needs to be preserved, as test_helpres does not
    # allow to patch only datetime.datetime.utcnow.
    orig_utcfromtimestamp = datetime.datetime.utcfromtimestamp

    test_helpers.patch(self, [
        'clusterfuzz._internal.build_management.revisions.get_component_range_list',
        'clusterfuzz._internal.google_cloud_utils.storage.write_data',
        'datetime.datetime',
    ])

    self.mock.datetime.utcnow.return_value = fake_utcnow
    self.mock.datetime.utcfromtimestamp.side_effect = orig_utcfromtimestamp
    self.mock.get_component_range_list.return_value = [{
        'component': 'Component',
        'link_text': 'REVISION',
    }, {
        'component': 'Component2',
        'link_text': 'REVISION2',
    }]
Пример #11
0
    def setUp(self):
        """Put data in the local ndb table the tests to query from and set
    bandit selection environment variable."""
        test_helpers.patch_environ(self)

        data = []

        strategy1 = data_types.FuzzStrategyProbability()
        strategy1.strategy_name = 'fork,corpus_subset,recommended_dict,'
        strategy1.probability = 0.33
        strategy1.engine = 'libFuzzer'
        data.append(strategy1)

        strategy2 = data_types.FuzzStrategyProbability()
        strategy2.strategy_name = ('random_max_len,corpus_mutations_ml_rnn,'
                                   'value_profile,recommended_dict,')
        strategy2.probability = 0.34
        strategy2.engine = 'libFuzzer'
        data.append(strategy2)

        strategy3 = data_types.FuzzStrategyProbability()
        strategy3.strategy_name = ('corpus_mutations_radamsa,'
                                   'random_max_len,corpus_subset,')
        strategy3.probability = 0.33
        strategy3.engine = 'libFuzzer'
        data.append(strategy3)
        ndb.put_multi(data)

        distribution = fuzz_task.get_strategy_distribution_from_ndb()

        environment.set_value('USE_BANDIT_STRATEGY_SELECTION', True)
        environment.set_value('STRATEGY_SELECTION_DISTRIBUTION', distribution)
    def setUp(self):
        test_helpers.patch_environ(self)
        flaskapp = flask.Flask('testflask')
        flaskapp.add_url_rule(
            '/apply-ccs',
            view_func=oss_fuzz_apply_ccs.Handler.as_view('/apply-ccs'))
        self.app = webtest.TestApp(flaskapp)

        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=False,
            auto_cc=data_types.AutoCCType.ALL).put()

        test_helpers.patch(self, [
            'clusterfuzz._internal.base.utils.utcnow',
            'handlers.base_handler.Handler.is_cron',
            'libs.issue_management.issue_tracker.IssueTracker.get_original_issue',
            'libs.issue_management.issue_tracker_policy.get',
            'libs.issue_management.issue_tracker_utils.'
            'get_issue_tracker_for_testcase',
        ])

        self.itm = IssueTrackerManager('oss-fuzz')
        self.mock.get_issue_tracker_for_testcase.return_value = (
            monorail.IssueTracker(self.itm))
        self.mock.utcnow.return_value = datetime.datetime(2016, 1, 1)
        self.mock.get.return_value = OSS_FUZZ_POLICY
        self.mock.get_original_issue.side_effect = get_original_issue

        self.job = data_types.Job(name='job', environment_string='')
        self.job.put()

        data_types.Testcase(open=True,
                            status='Processed',
                            bug_information='1337',
                            job_type='job').put()

        data_types.Testcase(open=True,
                            status='Processed',
                            bug_information='1338',
                            job_type='job').put()

        data_types.Testcase(open=True,
                            status='Processed',
                            bug_information='1339',
                            job_type='job').put()

        data_types.Testcase(open=True,
                            status='Processed',
                            bug_information='1340',
                            job_type='job').put()
Пример #13
0
    def test_doesnt_mutate_options(self):
        """Test that calling get_memory_tool_options followed by
    set_memory_tool_options does not mutate sanitizer options unless we
    do so explicitly."""
        # Make environment module use the Windows symbolizer, since its path is
        # hard to get right.
        test_helpers.patch_environ(self)
        os.environ['JOB_NAME'] = 'windows_libfuzzer_chrome_asan'
        test_helpers.patch(self, [
            'clusterfuzz._internal.system.environment.platform',
            'clusterfuzz._internal.system.environment.get_llvm_symbolizer_path'
        ])
        self.mock.platform.return_value = 'WINDOWS'
        windows_symbolizer_path = (
            r'c:\clusterfuzz\resources\platform\windows\llvm-symbolizer.exe')

        self.mock.get_llvm_symbolizer_path.return_value = windows_symbolizer_path
        environment.reset_current_memory_tool_options()
        memory_tool_var = 'ASAN_OPTIONS'
        first_asan_options_dict = environment.get_memory_tool_options(
            memory_tool_var)
        environment.set_memory_tool_options(memory_tool_var,
                                            first_asan_options_dict)
        second_asan_options_dict = environment.get_memory_tool_options(
            memory_tool_var)
        self.assertDictEqual(first_asan_options_dict, second_asan_options_dict)
Пример #14
0
    def setUp(self):
        test_utils.set_up_pyfakefs(self)
        helpers.patch_environ(self)

        self.data_bundles_dir = '/data-bundles'
        os.mkdir(self.data_bundles_dir)
        environment.set_value('DATA_BUNDLES_DIR', self.data_bundles_dir)
Пример #15
0
 def setUp(self):
   test_helpers.patch(self, [
       'clusterfuzz._internal.base.utils.is_oss_fuzz',
       'libs.auth.is_current_user_admin',
   ])
   test_helpers.patch_environ(self)
   self.mock.is_oss_fuzz.return_value = False
Пример #16
0
 def setUp(self):
   test_helpers.patch(self, ['libs.handler.get_email_and_access_token'])
   flaskapp = flask.Flask('testflask')
   flaskapp.add_url_rule('/', view_func=OAuthHandler.as_view('/'))
   self.app = webtest.TestApp(flaskapp)
   test_helpers.patch_environ(self)
   os.environ['AUTH_DOMAIN'] = 'localhost'
Пример #17
0
    def setUp(self):
        test_helpers.patch_environ(self)
        test_helpers.patch(self, [
            'clusterfuzz._internal.base.utils.random_weighted_choice',
        ])

        self.mock.random_weighted_choice.side_effect = _mock_random_weighted_choice
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        os.environ['BOT_TMPDIR'] = os.path.join(self.tmp_dir, 'bot_tmpdir')

        test_helpers.patch(self, [
            'clusterfuzz._internal.datastore.data_handler.'
            'get_data_bundle_bucket_name',
            'clusterfuzz._internal.system.environment.'
            'set_environment_parameters_from_file',
        ])

        test_helpers.patch_environ(self)

        # Our tests write data/logs into subdirs of ROOT_DIR. Pivot the ROOT_DIR to
        # a temporary one.
        new_root = _create_test_root()

        os.environ['ROOT_DIR'] = new_root
        self.saved_cwd = os.getcwd()
        os.chdir(new_root)

        environment.set_bot_environment()

        fuzz_inputs = os.environ['FUZZ_INPUTS']
        shell.remove_directory(fuzz_inputs, recreate=True)

        worker_fuzz_inputs = file_host.rebase_to_worker_root(fuzz_inputs)
        shell.remove_directory(worker_fuzz_inputs, recreate=True)

        environment.set_value('GSUTIL_PATH', os.path.dirname(_which('gsutil')))

        test_utils.setup_pubsub('test-clusterfuzz')
        test_utils.create_pubsub_topic(pubsub.PubSubClient(),
                                       'test-clusterfuzz',
                                       'jobs-project-linux')
Пример #19
0
    def setUp(self):
        """Setup for upload tests to cloud storage test."""
        test_helpers.patch_environ(self)
        test_helpers.patch(self, [
            'clusterfuzz._internal.base.utils.utcnow',
            'clusterfuzz._internal.config.local_config.ProjectConfig.get',
            'clusterfuzz._internal.datastore.locks.acquire_lock',
            'clusterfuzz._internal.datastore.locks.release_lock',
            'clusterfuzz._internal.google_cloud_utils.gsutil.GSUtilRunner',
            'clusterfuzz._internal.google_cloud_utils.storage.list_blobs',
            'clusterfuzz._internal.google_cloud_utils.storage.read_data',
            'clusterfuzz._internal.google_cloud_utils.storage.write_data',
        ])

        test_utils.set_up_pyfakefs(self)

        self.mock.write_data.return_value = True
        self.mock.utcnow.side_effect = lambda: datetime.datetime(
            2018, 11, 1, 0, 0)

        FakeGSUtilRunner.rsync_calls = []
        self.mock.GSUtilRunner.side_effect = FakeGSUtilRunner
        self.mock.get.side_effect = _mock_config_get

        os.environ['BOT_NAME'] = 'test-bot'
        os.environ['BOT_TMPDIR'] = '/tmp'
        os.environ['FAIL_RETRIES'] = '1'
Пример #20
0
  def setUp(self):
    helpers.patch_environ(self)

    job = data_types.Job()
    job.name = 'job_with_help_format'
    job.environment_string = (
        'HELP_FORMAT = -%TESTCASE%\\n-%FUZZER_NAME%\\n-%FUZZ_TARGET%\\n'
        '-%PROJECT%\\n-%REVISION%\\n-%ENGINE%\\n-%SANITIZER%\\n%ARGS%\\n'
        '%SANITIZER_OPTIONS%\n'
        'PROJECT_NAME = test_project')
    job.put()

    job = data_types.Job()
    job.name = 'ubsan_job_without_help_format'
    job.environment_string = (
        'PROJECT_NAME = test_project\n'
        'APP_ARGS = '
        '--disable-logging --disable-experiments --testcase=%TESTCASE_HTTP_URL%'
    )
    job.put()

    fuzz_target = data_types.FuzzTarget(id='libFuzzer_test_project_test_fuzzer')
    fuzz_target.binary = 'test_fuzzer'
    fuzz_target.project = 'test_project'
    fuzz_target.engine = 'libFuzzer'
    fuzz_target.put()
Пример #21
0
 def setUp(self):
     """Set up method for strategy pool generator tests with patch."""
     test_helpers.patch_environ(self)
     test_helpers.patch(self, [
         'clusterfuzz._internal.bot.fuzzers.engine_common.decide_with_probability'
     ])
     self.mock.decide_with_probability.return_value = True
Пример #22
0
    def setUp(self):
        test_helpers.patch(self, [
            'clusterfuzz._internal.bot.untrusted_runner.host.stub',
        ])

        test_helpers.patch_environ(self)
        test_utils.set_up_pyfakefs(self)
Пример #23
0
    def setUp(self):
        test_helpers.patch(
            self, ['clusterfuzz._internal.platforms.android.adb.run_command'])
        test_helpers.patch_environ(self)

        output = _read_data_file('get_device_codename_output.txt')
        self.mock.run_command.return_value = output
Пример #24
0
    def setUp(self):
        os.environ['BUILD_DIR'] = DATA_DIRECTORY
        os.environ['FUZZ_INPUTS_DISK'] = TEMP_DIRECTORY
        os.environ['FAIL_RETRIES'] = '1'

        test_helpers.patch_environ(self)
        dont_use_strategies(self)

        # Make it easy to assert if things were logged.
        test_helpers.patch(self, [
            'clusterfuzz._internal.metrics.logs.log', 'os.getpid',
            'clusterfuzz._internal.bot.fuzzers.afl.launcher.rand_cmplog_level',
            'clusterfuzz._internal.bot.fuzzers.afl.launcher.rand_schedule'
        ])
        self.mock.rand_cmplog_level.return_value = '2'
        self.mock.rand_schedule.return_value = 'fast'
        self.logged_messages = []

        def mocked_log(message, **kwargs):  # pylint: disable=unused-argument
            self.logged_messages.append(message)

        self.mock.log.side_effect = mocked_log
        self.mock.getpid.return_value = 1337

        clear_temp_dir()
        create_temp_dir()
Пример #25
0
    def setUp(self):
        test_helpers.patch(self, [
            ('regular_build_setup',
             'clusterfuzz._internal.build_management.build_manager.RegularBuild.setup'
             ),
        ])

        test_helpers.patch_environ(self)
Пример #26
0
    def setUp(self):
        helpers.patch_environ(self)

        os.environ['TOOL_NAME'] = 'ASAN'
        os.environ['JOB_NAME'] = 'linux_asan_chrome'

        self.start_separator = '+' + '-' * 40
        self.end_separator = '-' * 40 + '+'
Пример #27
0
    def setUp(self):
        test_helpers.patch_environ(self)

        self.configs_directory = os.path.join(os.path.dirname(__file__),
                                              'local_config_data')
        environment.set_value('CONFIG_DIR_OVERRIDE', self.configs_directory)

        self.config = local_config.Config()
Пример #28
0
    def setUp(self):
        test_helpers.patch_environ(self)

        environment.remove_key('PROJECT_NAME')
        environment.remove_key('ISSUE_TRACKER')
        environment.remove_key('UPDATE_WEB_TESTS')

        self.config = local_config.ProjectConfig()
Пример #29
0
    def setUp(self):
        test_utils.set_up_pyfakefs(self)
        helpers.patch_environ(self)

        os.environ['ROOT_DIR'] = '/root'
        os.environ['FAIL_RETRIES'] = '1'

        monitor.metrics_store().reset_for_testing()
  def setUp(self):
    test_helpers.patch_environ(self)
    test_utils.set_up_pyfakefs(self)

    os.environ['FAIL_WAIT'] = '0'
    os.environ['FAIL_RETRIES'] = '1'

    self.fs.create_file('/fuzz-testcase')