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());
}
}
}
Aggregations