use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithVerifyParametersThatDoNotMatchTheResponseValues_whenTheFuzzerRuns_thenAnErrorIsReported.
@Test
void givenACustomFuzzerFileWithVerifyParametersThatDoNotMatchTheResponseValues_whenTheFuzzerRuns_thenAnErrorIsReported() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer-verify.yml", "{\"name\": {\"first\": \"Cats\"}, \"id\": \"45\"}");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(testCaseListener, Mockito.times(3)).reportError(Mockito.any(), Mockito.eq("Parameter [id] with value [45] not matching [25]. "), Mockito.any());
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecuted.
@Test
void givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecuted() throws Exception {
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("field", "oldValue");
FuzzingData data = this.setupFuzzingData(catsResponse, jsonObject, "newValue", "newValue2");
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(3)).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 InvalidValuesInEnumsFieldsFuzzerTest method shouldHaveBoundaryDefined.
@Test
void shouldHaveBoundaryDefined() {
StringSchema stringSchema = new StringSchema();
stringSchema.setEnum(Collections.singletonList("TEST"));
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)).hasSizeLessThanOrEqualTo(4);
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.hasBoundaryDefined("test", data)).isTrue();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.description()).isNotNull();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.typeOfDataSentToTheService()).isNotNull();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class MaxLengthExactValuesInStringFieldsFuzzerTest 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(maxLengthExactValuesInStringFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo().stream().anyMatch(schema -> schema.isAssignableFrom(StringSchema.class))).isTrue();
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.description()).isNotNull();
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.typeOfDataSentToTheService()).isEqualTo("exact maxLength size values");
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.skipForHttpMethods()).containsOnly(HttpMethod.GET, HttpMethod.DELETE);
stringSchema.setMaxLength(2);
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.hasBoundaryDefined("test", data)).isTrue();
Assertions.assertThat(maxLengthExactValuesInStringFieldsFuzzer.getBoundaryValue(stringSchema)).isNotNull();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class NamingsContractInfoFuzzerTest method shouldReportInfo.
@ParameterizedTest
@CsvSource({ "/pets-paths", "/pets_paths", "/pets-path-links", "/pets/paths", "/pets/complex-paths", "/pets/{petId}", "/pets/{pet_id}", "/pets/{ped_id}/run", "/pets/run", "/admin/pets" })
void shouldReportInfo(String path) {
PathItem pathItem = new PathItem();
Operation operation = new Operation();
operation.setResponses(new ApiResponses());
pathItem.setPost(operation);
FuzzingData data = FuzzingData.builder().path(path).method(HttpMethod.POST).pathItem(pathItem).reqSchemaName("Cats").build();
namingsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path follows the RESTful API naming good practices."));
}
Aggregations