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