Пример #1
0
def _validate_individual_experiment_requests(experiment_requests):
    """Returns True if all requests in |experiment_request| are valid in
    isolation. Does not account for PAUSE_SERVICE_KEYWORD or duplicates."""
    valid = True
    # Validate format.
    for request in experiment_requests:
        if not isinstance(request, dict):
            logger.error('Request: %s is not a dict.', request)
            experiment_requests.remove(request)
            valid = False
            continue

        if 'experiment' not in request:
            logger.error('Request: %s does not have field "experiment".',
                         request)
            valid = False
            continue

        experiment = _get_experiment_name(request)
        if not validate_experiment_name(experiment):
            valid = False
            # Request isn't so malformed that we can find other issues, if
            # present.

        fuzzers = request.get('fuzzers')
        if not fuzzers:
            logger.error('Request: %s does not specify any fuzzers.', request)
            valid = False
            continue

        for fuzzer in fuzzers:
            try:
                run_experiment.validate_fuzzer(fuzzer)
            except run_experiment.ValidationError:
                logger.error('Fuzzer: %s is invalid.', fuzzer)
                valid = False

        description = request.get('description')
        if description is not None and not isinstance(description, str):
            logger.error(
                'Request: %s "description" attribute is not a valid string.',
                request)
            valid = False

        oss_fuzz_corpus = request.get('oss_fuzz_corpus')
        if oss_fuzz_corpus is not None and not isinstance(
                oss_fuzz_corpus, bool):
            logger.error(
                'Request: %s "oss_fuzz_corpus" attribute is not a valid bool.',
                request)
            valid = False

        experiment_type = request.get('type',
                                      benchmark_utils.BenchmarkType.CODE.value)
        if experiment_type not in benchmark_utils.BENCHMARK_TYPE_STRS:
            logger.error('Type: %s is invalid, must be one of %s',
                         experiment_type, benchmark_utils.BENCHMARK_TYPE_STRS)
            valid = False

    return valid
Пример #2
0
def test_validate_fuzzer():
    """Tests that validate_fuzzer says that a valid fuzzer name is valid and
    that an invalid one is not."""
    run_experiment.validate_fuzzer('afl')

    with pytest.raises(Exception) as exception:
        run_experiment.validate_fuzzer('afl:')
    assert 'may only contain' in str(exception.value)

    with pytest.raises(Exception) as exception:
        run_experiment.validate_fuzzer('not_exist')
    assert 'does not exist' in str(exception.value)
Пример #3
0
def test_validate_fuzzer():
    """Tests that validate_fuzzer says that a valid fuzzer name is valid and
    that an invalid one is not."""
    run_experiment.validate_fuzzer('afl')

    with pytest.raises(run_experiment.ValidationError) as exception:
        run_experiment.validate_fuzzer('afl:')
    assert 'is invalid' in str(exception.value)

    with pytest.raises(run_experiment.ValidationError) as exception:
        run_experiment.validate_fuzzer('not_exist')
    assert 'is invalid' in str(exception.value)