Search in sources :

Example 71 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class FunctionalFuzzerTest method shouldWriteRefData.

@Test
void shouldWriteRefData() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
    ReflectionTestUtils.setField(filesArguments, "createRefData", true);
    ReflectionTestUtils.setField(filesArguments, "refDataFile", null);
    filesArguments.loadCustomFuzzerFile();
    functionalFuzzer.fuzz(data);
    functionalFuzzer.executeCustomFuzzerTests();
    functionalFuzzer.replaceRefData();
    File refDataCustom = new File("refData_custom.yml");
    List<String> lines = Files.readAllLines(refDataCustom.toPath());
    Assertions.assertThat(lines).contains("/pets/{id}/move:", "  pet: \"200\"");
    refDataCustom.deleteOnExit();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) File(java.io.File) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 72 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class FunctionalFuzzerTest method givenACustomFuzzerFileWithVerifyParameters_whenTheFuzzerRuns_thenVerifyParameterAreProperlyChecked.

@Test
void givenACustomFuzzerFileWithVerifyParameters_whenTheFuzzerRuns_thenVerifyParameterAreProperlyChecked() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer-verify.yml", "{\"name\": {\"first\": \"Cats\"}, \"id\": \"25\"}");
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(testCaseListener, Mockito.times(3)).reportInfo(Mockito.any(), Mockito.eq("Response matches all 'verify' parameters"), Mockito.any());
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 73 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class InvalidValuesInEnumsFieldsFuzzerTest method shouldNotHaveBoundaryDefined.

@Test
void shouldNotHaveBoundaryDefined() {
    StringSchema stringSchema = new StringSchema();
    FuzzingData data = FuzzingData.builder().requestPropertyTypes(Collections.singletonMap("test", stringSchema)).build();
    Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo().stream().anyMatch(schema -> schema.isAssignableFrom(StringSchema.class))).isTrue();
    Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.getBoundaryValue(stringSchema)).isEmpty();
    Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
    Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.description()).isNotNull();
    Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.typeOfDataSentToTheService()).isNotNull();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 74 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class MaximumExactValuesInNumericFieldsFuzzerTest method givenANewStringFieldsRightBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsRightBoundaryFuzzer.

@Test
void givenANewStringFieldsRightBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsRightBoundaryFuzzer() {
    StringSchema stringSchema = new StringSchema();
    FuzzingData data = FuzzingData.builder().requestPropertyTypes(Collections.singletonMap("test", stringSchema)).build();
    Mockito.when(filesArguments.getRefData(Mockito.anyString())).thenReturn(Collections.emptyMap());
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo()).containsOnly(IntegerSchema.class, NumberSchema.class);
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.description()).isNotNull();
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.typeOfDataSentToTheService()).isEqualTo("exact maximum size values");
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.skipForHttpMethods()).containsOnly(HttpMethod.GET, HttpMethod.DELETE);
    stringSchema.setMaximum(BigDecimal.TEN);
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.hasBoundaryDefined("test", data)).isTrue();
    Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getBoundaryValue(stringSchema)).isNotNull();
}
Also used : 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 75 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class CommonWithinMethodsTest method shouldInsertWithoutReplaceWhenNotMaintainSize.

@Test
void shouldInsertWithoutReplaceWhenNotMaintainSize() {
    StringSchema schema = new StringSchema();
    int length = 10;
    schema.setMinLength(length);
    schema.setMaxLength(length);
    FuzzingData fuzzingData = Mockito.mock(FuzzingData.class);
    Map<String, Schema> reqPropTypes = Map.of("test1", schema);
    Mockito.when(fuzzingData.getRequestPropertyTypes()).thenReturn(reqPropTypes);
    List<FuzzingStrategy> fuzzingStrategyList = CommonWithinMethods.getFuzzingStrategies(fuzzingData, "test1", List.of(YY), false);
    Assertions.assertThat(fuzzingStrategyList).hasSize(1);
    Assertions.assertThat(fuzzingStrategyList.get(0).getData()).contains(YY).doesNotStartWith(YY).doesNotEndWith(YY).hasSize(length + YY.length());
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) 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) 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