Search in sources :

Example 86 with FuzzingData

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

the class FunctionalFuzzerTest method givenAnEmptyCustomFuzzerFile_whenTheFuzzerRuns_thenNothingHappens.

@Test
void givenAnEmptyCustomFuzzerFile_whenTheFuzzerRuns_thenNothingHappens() {
    FuzzingData data = FuzzingData.builder().build();
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(spyFunctionalFuzzer, Mockito.never()).processCustomFuzzerFile(data);
    Assertions.assertThat(functionalFuzzer.description()).isNotNull();
    Assertions.assertThat(functionalFuzzer).hasToString(functionalFuzzer.getClass().getSimpleName());
    Assertions.assertThat(functionalFuzzer.reservedWords()).containsOnly(CatsDSLWords.EXPECTED_RESPONSE_CODE, CatsDSLWords.DESCRIPTION, CatsDSLWords.OUTPUT, CatsDSLWords.VERIFY, CatsDSLWords.MAP_VALUES, CatsDSLWords.ONE_OF_SELECTION, CatsDSLWords.ADDITIONAL_PROPERTIES, CatsDSLWords.ELEMENT, CatsDSLWords.HTTP_METHOD);
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 87 with FuzzingData

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

the class FunctionalFuzzerTest method givenACompleteCustomFuzzerFileWithDescriptionAndOutputVariables_whenTheFuzzerRuns_thenTheTestCasesAreCorrectlyExecuted.

@Test
void givenACompleteCustomFuzzerFileWithDescriptionAndOutputVariables_whenTheFuzzerRuns_thenTheTestCasesAreCorrectlyExecuted() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(testCaseListener, Mockito.times(4)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 88 with FuzzingData

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

the class FunctionalFuzzerTest method setupFuzzingData.

private FuzzingData setupFuzzingData(CatsResponse catsResponse, JsonObject jsonObject, String... customFieldValues) throws IOException {
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    FuzzingData data = FuzzingData.builder().path("path1").payload("{\"field\":\"oldValue\"}").responses(responses).responseCodes(Collections.singleton("200")).reqSchema(new StringSchema()).method(HttpMethod.POST).build();
    CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
    Mockito.when(mockCatsUtil.parseYaml(any())).thenReturn(createCustomFuzzerFile(customFieldValues));
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    filesArguments = new FilesArguments(mockCatsUtil);
    customFuzzerUtil = new CustomFuzzerUtil(serviceCaller, mockCatsUtil, testCaseListener, catsDSLParser);
    functionalFuzzer = new FunctionalFuzzer(filesArguments, customFuzzerUtil);
    ReflectionTestUtils.setField(filesArguments, "customFuzzerFile", new File("custom"));
    return data;
}
Also used : FilesArguments(com.endava.cats.args.FilesArguments) HashMap(java.util.HashMap) CatsUtil(com.endava.cats.util.CatsUtil) FuzzingData(com.endava.cats.model.FuzzingData) CustomFuzzerUtil(com.endava.cats.fuzzer.CustomFuzzerUtil) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) File(java.io.File)

Example 89 with FuzzingData

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

the class FunctionalFuzzerTest method setContext.

private FuzzingData setContext(String fuzzerFile, String responsePayload) throws Exception {
    ReflectionTestUtils.setField(filesArguments, "customFuzzerFile", new File(fuzzerFile));
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    CatsResponse catsResponse = CatsResponse.from(200, responsePayload, "POST", 2);
    FuzzingData data = FuzzingData.builder().path("/pets/{id}/move").payload("{\"pet\":\"oldValue\", \"name\":\"dodo\"}").responses(responses).responseCodes(Collections.singleton("200")).reqSchema(new StringSchema()).method(HttpMethod.POST).build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    return data;
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) HashMap(java.util.HashMap) FuzzingData(com.endava.cats.model.FuzzingData) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) File(java.io.File)

Example 90 with FuzzingData

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

the class FunctionalFuzzerTest method givenACustomFuzzerFileWithAdditionalProperties_whenTheFuzzerRuns_thenPropertiesAreProperlyAddedToThePayload.

@Test
void givenACustomFuzzerFileWithAdditionalProperties_whenTheFuzzerRuns_thenPropertiesAreProperlyAddedToThePayload() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer-additional.yml", "{\"code\": \"200\"}");
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

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