use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class WithinSingleCodePointEmojisInFieldsValidateTrimFuzzerTest method shouldProperlyOverrideSuperClassMethods.
@Test
void shouldProperlyOverrideSuperClassMethods() {
FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> reqTypes = new HashMap<>();
reqTypes.put("field", new StringSchema());
Mockito.when(data.getRequestPropertyTypes()).thenReturn(reqTypes);
FuzzingStrategy fuzzingStrategy = withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "field").get(1);
Assertions.assertThat(fuzzingStrategy.getData()).contains("\uD83D\uDC80");
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(withinSingleCodePointEmojisInFieldsValidateTrimFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class EmptyStringValuesInFieldsFuzzerTest method shouldNotRunFuzzerWhenGetButNoQueryParam.
@Test
void shouldNotRunFuzzerWhenGetButNoQueryParam() {
FuzzingData data = FuzzingData.builder().method(HttpMethod.GET).queryParams(Set.of("query1")).build();
Assertions.assertThat(emptyStringValuesInFieldsFuzzer.isFuzzingPossibleSpecificToFuzzer(data, "notQuery", FuzzingStrategy.replace())).isFalse();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class EmptyStringValuesInFieldsFuzzerTest method shouldRunFuzzerWhenGetAndQueryParam.
@Test
void shouldRunFuzzerWhenGetAndQueryParam() {
FuzzingData data = FuzzingData.builder().method(HttpMethod.GET).queryParams(Set.of("query1")).build();
Assertions.assertThat(emptyStringValuesInFieldsFuzzer.isFuzzingPossibleSpecificToFuzzer(data, "query1", FuzzingStrategy.replace())).isTrue();
}
use of com.endava.cats.model.FuzzingData 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());
}
}
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class HttpStatusCodeInValidRangeContractInfoFuzzerTest method shouldReportErrorWhenAllResponseCodesAreValid.
@ParameterizedTest
@CsvSource({ "99", "1", "600" })
void shouldReportErrorWhenAllResponseCodesAreValid(String responseCode) {
FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData("PetStore", responseCode);
httpStatusCodeInValidRangeContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("The following response codes are not valid: {}"), Mockito.any());
}
Aggregations