Example #1
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)
Example #2
0
def create_pubsub_topic(client, project, name):
    """Create topic if it doesn't exist."""
    full_name = pubsub.topic_name(project, name)
    if client.get_topic(full_name):
        return

    client.create_topic(full_name)
Example #3
0
def add_task(command, argument, job_type, queue=None, wait_time=None):
    """Add a new task to the job queue."""
    # Old testcases may pass in queue=None explicitly,
    # so we must check this here.
    if not queue:
        queue = default_queue()

    if wait_time is None:
        wait_time = random.randint(1, TASK_CREATION_WAIT_INTERVAL)

    if job_type != 'none':
        job = data_types.Job.query(data_types.Job.name == job_type).get()
        if not job:
            raise Error(f'Job {job_type} not found.')

        if job.is_external():
            external_tasks.add_external_task(command, argument, job)
            return

    # Add the task.
    eta = utils.utcnow() + datetime.timedelta(seconds=wait_time)
    task = Task(command, argument, job_type, eta=eta)
    pubsub_client = pubsub.PubSubClient()
    pubsub_client.publish(pubsub.topic_name(utils.get_application_id(), queue),
                          [task.to_pubsub_message()])
Example #4
0
def create_pubsub_subscription(client, project, topic, name):
    """Create subscription if it doesn't exist."""
    topic_name = pubsub.topic_name(project, topic)
    full_name = pubsub.subscription_name(project, name)
    if client.get_subscription(full_name):
        return

    client.create_subscription(full_name, topic_name)
Example #5
0
    def setUp(self):
        helpers.patch_environ(self)
        self.topic = pubsub.topic_name(PROJECT_NAME, 'test-topic')
        self.subscription = pubsub.subscription_name(PROJECT_NAME,
                                                     'subscription')

        self.client = pubsub.PubSubClient()
        self.client.create_topic(self.topic)
        self.client.create_subscription(self.subscription,
                                        self.topic,
                                        ack_deadline=ACK_DEADLINE)
Example #6
0
    def setUp(self):
        helpers.patch_environ(self)
        helpers.patch(self, [
            'clusterfuzz._internal.google_cloud_utils.blobs.read_key',
        ])

        self.mock.read_key.return_value = b'reproducer'

        self.client = pubsub.PubSubClient()
        self.topic = pubsub.topic_name('proj', 'repro')
        self.client.create_topic(self.topic)
        self.subscription = pubsub.subscription_name('proj', 'repro')
        self.client.create_subscription(self.subscription, self.topic)

        data_types.Job(
            name='libfuzzer_asan_blah_external',
            platform='LINUX',
            environment_string=
            ('RELEASE_BUILD_BUCKET_PATH = gs://bucket/a/b/release-([0-9]+).zip\n'
             'PROJECT_NAME = proj\n'),
            external_reproduction_topic=self.topic,
            external_updates_subscription='projects/proj/subscriptions/updates'
        ).put()

        data_types.Job(
            name='libfuzzer_msan_blah_external',
            platform='LINUX',
            environment_string=(
                'FUZZ_TARGET_BUILD_BUCKET_PATH = '
                'gs://bucket/a/b/%TARGET%/release-([0-9]+).zip\n'
                'PROJECT_NAME = proj\n'),
            external_reproduction_topic=self.topic,
            external_updates_subscription='projects/proj/subscriptions/updates'
        ).put()

        data_types.FuzzTarget(id='libFuzzer_abc',
                              engine='libFuzzer',
                              binary='abc').put()

        self.testcase_0 = data_types.Testcase(
            fuzzer_name='libFuzzer',
            overridden_fuzzer_name='libFuzzer_abc',
            crash_revision=1336,
            minimized_keys='key')
        self.testcase_0.set_metadata('last_tested_revision', 1337)
        self.testcase_0.put()

        self.testcase_1 = data_types.Testcase(
            fuzzer_name='libFuzzer',
            overridden_fuzzer_name='libFuzzer_abc',
            crash_revision=1336,
            fuzzed_keys='key')
        self.testcase_1.put()
Example #7
0
def create_pubsub_topics(project):
    """Create pubsub topics for tasks."""
    for platform in PUBSUB_PLATFORMS:
        name = untrusted.queue_name(project, platform)
        client = pubsub.PubSubClient()
        application_id = utils.get_application_id()

        topic_name = pubsub.topic_name(application_id, name)
        if client.get_topic(topic_name) is None:
            client.create_topic(topic_name)

        subscription_name = pubsub.subscription_name(application_id, name)
        if client.get_subscription(subscription_name) is None:
            client.create_subscription(subscription_name, topic_name)
Example #8
0
    def test_list_topics(self):
        """Test listing topics."""
        expected = []
        for i in range(5):
            topic = pubsub.topic_name(PROJECT_NAME, 'topic-{}'.format(i))
            expected.append(topic)
            self.client.create_topic(topic)

        expected.append('projects/fake-project/topics/test-topic')

        topics = list(self.client.list_topics('projects/' + PROJECT_NAME))
        six.assertCountEqual(self, expected, topics)

        # Note: Page size appears to be ignored by the emulator. Even when creating
        # large amounts of topics to force paging, the nextPageToken returned is
        # buggy and results in infinite loops.
        topics = list(
            self.client.list_topics('projects/' + PROJECT_NAME, page_size=1))
        six.assertCountEqual(self, expected, topics)