Ejemplo n.º 1
0
    def setUp(self):
        test_helpers.patch(self, [
            'redis.Redis',
            'clusterfuzz._internal.system.environment.is_running_on_app_engine',
        ])
        self.mock.Redis.return_value = _MockRedis()
        self.mock.is_running_on_app_engine.return_value = True

        self.cache = memoize.Memcache(100)

        def fn():
            pass

        self.key = self.cache.get_key(fn, ('a', 'b'), {'c': 'd'})
        self.value = 'b'
Ejemplo n.º 2
0
class FuzzerRunLogsContext(BuiltinFieldContext):
    """Fuzzer logs context."""

    MEMCACHE_TTL = 30 * 60

    def __init__(self, fuzzer=None, jobs=None):
        super(FuzzerRunLogsContext, self).__init__(fuzzer=fuzzer, jobs=jobs)

    @memoize.wrap(memoize.FifoInMemory(1024))
    def _get_logs_bucket_from_job(self, job_type):
        """Get logs bucket from job."""
        return data_handler.get_value_from_job_definition_or_environment(
            job_type, 'FUZZ_LOGS_BUCKET')

    @memoize.wrap(memoize.Memcache(MEMCACHE_TTL, key_fn=_logs_bucket_key_fn))
    def _get_logs_bucket_from_fuzzer(self, fuzzer_name):
        """Get logs bucket from fuzzer (child fuzzers only)."""
        jobs = [
            mapping.job for mapping in fuzz_target_utils.get_fuzz_target_jobs(
                fuzz_target_name=fuzzer_name)
        ]
        if not jobs:
            return None

        # Check that the logs bucket is same for all of them.
        bucket = self._get_logs_bucket_from_job(jobs[0])
        if all(bucket == self._get_logs_bucket_from_job(job)
               for job in jobs[1:]):
            return bucket

        return None

    def get_logs_bucket(self, fuzzer_name=None, job_type=None):
        """Return logs bucket for the job."""
        if job_type:
            return self._get_logs_bucket_from_job(job_type)

        if fuzzer_name:
            return self._get_logs_bucket_from_fuzzer(fuzzer_name)

        return None
Ejemplo n.º 3
0

def get_gcs_path(blob_key):
    """Return GCS path for the blob."""
    if _is_gcs_key(blob_key):
        return _get_gcs_blob_path(blob_key)

    # Legacy blobstore key.
    blob_info = get_legacy_blob_info(blob_key)
    if not blob_info:
        return None

    return blob_info.gs_object_name


@memoize.wrap(memoize.Memcache(60 * 60 * 24 * 30))  # 30 day TTL
@retry.wrap(retries=FAIL_NUM_RETRIES,
            delay=FAIL_WAIT,
            function='google_cloud_utils.blobs.get_blob_size')
def get_blob_size(blob_key):
    """Returns blob size for a given blob key."""
    if not blob_key or blob_key == 'NA':
        return None

    blob_info = get_blob_info(blob_key)
    if not blob_info:
        return None

    return blob_info.size

Ejemplo n.º 4
0
    """Sort key function."""
    return item['name']


def _get_engine_names(job_name):
    """Return the (engine display name, engine name) for the job."""
    if job_name.startswith('afl_'):
        return 'AFL', 'afl'

    if job_name.startswith('libfuzzer_'):
        return 'libFuzzer', 'libFuzzer'

    return 'Unknown', 'Unknown'


@memoize.wrap(memoize.Memcache(MEMCACHE_TTL_IN_SECONDS))
def get_single_fuzz_target_or_none(project, engine_name):
    """Return the name of the single child fuzzer for the project, or None."""
    fuzz_targets = data_handler.get_fuzz_targets(engine=engine_name,
                                                 project=project)
    fuzz_target_name = None

    for fuzz_target in fuzz_targets:
        if fuzz_target_name:
            # More than 1 child fuzzer.
            return None

        fuzz_target_name = fuzz_target.fully_qualified_name()

    return fuzz_target_name