Search in sources :

Example 81 with FuzzingData

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());
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) HashMap(java.util.HashMap) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 82 with FuzzingData

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();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 83 with FuzzingData

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();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 84 with FuzzingData

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

Example 85 with FuzzingData

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());
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FuzzingData (com.endava.cats.model.FuzzingData)167 QuarkusTest (io.quarkus.test.junit.QuarkusTest)139 Test (org.junit.jupiter.api.Test)139 StringSchema (io.swagger.v3.oas.models.media.StringSchema)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)47 CatsResponse (com.endava.cats.model.CatsResponse)43 HashMap (java.util.HashMap)43 Schema (io.swagger.v3.oas.models.media.Schema)36 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)35 CsvSource (org.junit.jupiter.params.provider.CsvSource)19 List (java.util.List)17 OpenAPI (io.swagger.v3.oas.models.OpenAPI)14 OpenAPIParser (io.swagger.parser.OpenAPIParser)12 PathItem (io.swagger.v3.oas.models.PathItem)12 HashSet (java.util.HashSet)8 File (java.io.File)7 CatsHeader (com.endava.cats.model.CatsHeader)6 Set (java.util.Set)6 CatsUtil (com.endava.cats.util.CatsUtil)5 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)5