use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class OnlyWhitespacesInFieldsValidateTrimFuzzerTest method givenANewSpacesOnlyInFieldsValidateTrimFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheSpacesOnlyInFieldsValidateTrimFuzzer.
@Test
void givenANewSpacesOnlyInFieldsValidateTrimFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheSpacesOnlyInFieldsValidateTrimFuzzer() {
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> schemaMap = new HashMap<>();
StringSchema stringSchema = new StringSchema();
schemaMap.put("schema", stringSchema);
Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
FuzzingStrategy fuzzingStrategy = onlyWhitespacesInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(0);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).contains(" ");
stringSchema.setMinLength(5);
fuzzingStrategy = onlyWhitespacesInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(0);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat(" ", stringSchema.getMinLength() + 1));
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.getInvisibleChars()).contains(" ");
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method shouldReplaceRefData.
@Test
void shouldReplaceRefData() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
File refData = File.createTempFile("refData", ".yml");
String line = "this/is/custom/${resp}";
Files.write(refData.toPath(), line.getBytes());
ReflectionTestUtils.setField(filesArguments, "refDataFile", refData);
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
spyFunctionalFuzzer.replaceRefData();
File refDataReplaced = new File(refData.getAbsolutePath().substring(0, refData.getAbsolutePath().lastIndexOf(".")) + "_replaced.yml");
String replaced = Files.readString(refDataReplaced.toPath());
Assertions.assertThat(replaced).isEqualTo("this/is/custom/200\n");
refData.deleteOnExit();
refDataReplaced.deleteOnExit();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method shouldParseRequestFields.
@Test
void shouldParseRequestFields() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
filesArguments.loadCustomFuzzerFile();
functionalFuzzer.fuzz(data);
functionalFuzzer.executeCustomFuzzerTests();
Map<String, String> variables = customFuzzerUtil.getVariables();
Assertions.assertThat(variables).containsEntry("resp", "200").containsEntry("custId", "john");
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed.
@Test
void givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed() throws Exception {
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("field", "oldValue");
FuzzingData data = this.setupFuzzingData(catsResponse, jsonObject, "T(java.time.OffsetDateTime).now().plusDays(20)");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(spyFunctionalFuzzer, Mockito.times(1)).processCustomFuzzerFile(data);
Mockito.verify(testCaseListener, Mockito.times(2)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.TWOXX));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method shouldVerifyWithRequestVariables.
@Test
void shouldVerifyWithRequestVariables() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer-req-verify.yml", "{\"name\": {\"first\": \"Cats\"}, \"id\": \"25\", \"code\":\"150\",\"petName\":\"myPet\"}");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(PrettyLogger.class), Mockito.eq("Response matches all 'verify' parameters"), Mockito.any());
}
Aggregations