Search in sources :

Example 1 with Fuzzer

use of com.endava.cats.Fuzzer in project cats by Endava.

the class CatsCommand method fuzzPath.

public void fuzzPath(Map.Entry<String, PathItem> pathItemEntry, OpenAPI openAPI) {
    /* WE NEED TO ITERATE THROUGH EACH HTTP OPERATION CORRESPONDING TO THE CURRENT PATH ENTRY*/
    LOGGER.info(" ");
    LOGGER.start("Start fuzzing path {}", pathItemEntry.getKey());
    List<FuzzingData> fuzzingDataList = fuzzingDataFactory.fromPathItem(pathItemEntry.getKey(), pathItemEntry.getValue(), openAPI);
    if (fuzzingDataList.isEmpty()) {
        LOGGER.warning("Skipping path {}. HTTP method not supported yet!", pathItemEntry.getKey());
        return;
    }
    List<FuzzingData> fuzzingDataListWithHttpMethodsFiltered = fuzzingDataList.stream().filter(fuzzingData -> filterArguments.getHttpMethods().contains(fuzzingData.getMethod())).collect(Collectors.toList());
    List<HttpMethod> excludedHttpMethods = fuzzingDataList.stream().map(FuzzingData::getMethod).filter(method -> !filterArguments.getHttpMethods().contains(method)).collect(Collectors.toList());
    List<Fuzzer> allFuzzersSorted = filterArguments.getAllRegisteredFuzzers();
    List<String> configuredFuzzers = filterArguments.getFuzzersForPath();
    LOGGER.info("The following HTTP methods won't be executed for path {}: {}", pathItemEntry.getKey(), excludedHttpMethods);
    LOGGER.info("{} configured fuzzers out of {} total fuzzers: {}", configuredFuzzers.size(), (long) allFuzzersSorted.size(), configuredFuzzers);
    /*We only run the fuzzers supplied and exclude those that do not apply for certain HTTP methods*/
    for (Fuzzer fuzzer : allFuzzersSorted) {
        if (configuredFuzzers.contains(fuzzer.toString())) {
            CatsUtil.filterAndPrintNotMatching(fuzzingDataListWithHttpMethodsFiltered, data -> !fuzzer.skipForHttpMethods().contains(data.getMethod()), LOGGER, "HTTP method {} is not supported by {}", t -> t.getMethod().toString(), fuzzer.toString()).forEach(data -> {
                LOGGER.info("Fuzzer {} and payload: {}", ansi().fgGreen().a(fuzzer.toString()).reset(), data.getPayload());
                testCaseListener.beforeFuzz(fuzzer.getClass());
                fuzzer.fuzz(data);
                testCaseListener.afterFuzz();
            });
        } else {
            LOGGER.debug("Skipping fuzzer {} for path {} as configured!", fuzzer, pathItemEntry.getKey());
        }
    }
}
Also used : ExecutionStatisticsListener(com.endava.cats.report.ExecutionStatisticsListener) CatsGlobalContext(com.endava.cats.model.CatsGlobalContext) PrettyLoggerFactory(io.github.ludovicianul.prettylogger.PrettyLoggerFactory) OpenApiUtils(com.endava.cats.util.OpenApiUtils) VersionProvider(com.endava.cats.util.VersionProvider) PrettyLogger(io.github.ludovicianul.prettylogger.PrettyLogger) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Fuzzer(com.endava.cats.Fuzzer) CheckArguments(com.endava.cats.args.CheckArguments) FilesArguments(com.endava.cats.args.FilesArguments) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) FuzzingData(com.endava.cats.model.FuzzingData) Schema(io.swagger.v3.oas.models.media.Schema) CommandLine(picocli.CommandLine) LinkedHashSet(java.util.LinkedHashSet) Ansi.ansi(org.fusesource.jansi.Ansi.ansi) CatsUtil(com.endava.cats.util.CatsUtil) ProcessingArguments(com.endava.cats.args.ProcessingArguments) ApiArguments(com.endava.cats.args.ApiArguments) TestCaseListener(com.endava.cats.report.TestCaseListener) PathItem(io.swagger.v3.oas.models.PathItem) AutoComplete(picocli.AutoComplete) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AuthArguments(com.endava.cats.args.AuthArguments) IgnoreArguments(com.endava.cats.args.IgnoreArguments) List(java.util.List) FilterArguments(com.endava.cats.args.FilterArguments) FuzzingDataFactory(com.endava.cats.factory.FuzzingDataFactory) HttpMethod(com.endava.cats.http.HttpMethod) Dependent(javax.enterprise.context.Dependent) FunctionalFuzzer(com.endava.cats.fuzzer.fields.FunctionalFuzzer) ReportingArguments(com.endava.cats.args.ReportingArguments) Fuzzer(com.endava.cats.Fuzzer) FunctionalFuzzer(com.endava.cats.fuzzer.fields.FunctionalFuzzer) FuzzingData(com.endava.cats.model.FuzzingData) HttpMethod(com.endava.cats.http.HttpMethod)

Aggregations

Fuzzer (com.endava.cats.Fuzzer)1 ApiArguments (com.endava.cats.args.ApiArguments)1 AuthArguments (com.endava.cats.args.AuthArguments)1 CheckArguments (com.endava.cats.args.CheckArguments)1 FilesArguments (com.endava.cats.args.FilesArguments)1 FilterArguments (com.endava.cats.args.FilterArguments)1 IgnoreArguments (com.endava.cats.args.IgnoreArguments)1 ProcessingArguments (com.endava.cats.args.ProcessingArguments)1 ReportingArguments (com.endava.cats.args.ReportingArguments)1 FuzzingDataFactory (com.endava.cats.factory.FuzzingDataFactory)1 FunctionalFuzzer (com.endava.cats.fuzzer.fields.FunctionalFuzzer)1 HttpMethod (com.endava.cats.http.HttpMethod)1 CatsGlobalContext (com.endava.cats.model.CatsGlobalContext)1 FuzzingData (com.endava.cats.model.FuzzingData)1 ExecutionStatisticsListener (com.endava.cats.report.ExecutionStatisticsListener)1 TestCaseListener (com.endava.cats.report.TestCaseListener)1 CatsUtil (com.endava.cats.util.CatsUtil)1 OpenApiUtils (com.endava.cats.util.OpenApiUtils)1 VersionProvider (com.endava.cats.util.VersionProvider)1 PrettyLogger (io.github.ludovicianul.prettylogger.PrettyLogger)1