use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class RecommendedHttpCodesContractInfoFuzzerTest method shouldReportInfoWhenAllResponseCodesAreValid.
@ParameterizedTest
@CsvSource(value = { "400,500,200;POST", "400,500,201;POST", "400,500,202;POST", "400,500,204;POST", "400,404,500,201;PUT", "400,404,500,202;GET", "404,200;HEAD", "404,202;HEAD", "400,404,500,200;DELETE", "400,404,500,201;DELETE", "400,404,500,202;DELETE", "400,404,500,204;DELETE", "400,404,500,200;PATCH", "400,404,500,201;PATCH", "400,404,500,202;PATCH", "400,404,500,204;PATCH", "400,500,200;TRACE" }, delimiter = ';')
void shouldReportInfoWhenAllResponseCodesAreValid(String responseCode, HttpMethod method) {
FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData("PetStore", method, responseCode.split(","));
recommendedHttpCodesContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("All recommended HTTP codes are defined!"));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class SecuritySchemesContractInfoFuzzerTest method shouldNotReportAnyError.
@Test
void shouldNotReportAnyError() throws Exception {
OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/openapi.yml"))), null, null).getOpenAPI();
FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").tags(Collections.singletonList("pet")).method(HttpMethod.POST).pathItem(openAPI.getPaths().get("/pet")).build();
securitySchemesContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("The current path has security scheme(s) properly defined"));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class SecuritySchemesContractInfoFuzzerTest method shouldNotReportErrorWithSecurityGlobal.
@Test
void shouldNotReportErrorWithSecurityGlobal() throws Exception {
OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/contract-path-tags-mismatch.yml"))), null, null).getOpenAPI();
FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").method(HttpMethod.PUT).tags(Collections.singletonList("petsCats")).pathItem(openAPI.getPaths().get("/pet")).build();
securitySchemesContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("The current path has security scheme(s) properly defined"));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class MinLengthExactValuesInStringFieldsFuzzerTest 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(minLengthExactValuesInStringFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo().stream().anyMatch(schema -> schema.isAssignableFrom(StringSchema.class))).isTrue();
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.description()).isNotNull();
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.typeOfDataSentToTheService()).isEqualTo("exact minLength size values");
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.skipForHttpMethods()).containsOnly(HttpMethod.GET, HttpMethod.DELETE);
stringSchema.setMinLength(2);
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.hasBoundaryDefined("test", data)).isTrue();
Assertions.assertThat(minLengthExactValuesInStringFieldsFuzzer.getBoundaryValue(stringSchema)).isNotNull();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class NullValuesInFieldsFuzzerTest method shouldNotRunFuzzerWhenGetButNoQueryParam.
@Test
void shouldNotRunFuzzerWhenGetButNoQueryParam() {
FuzzingData data = FuzzingData.builder().method(HttpMethod.GET).queryParams(Set.of("query1")).build();
Assertions.assertThat(nullValuesInFieldsFuzzer.isFuzzingPossibleSpecificToFuzzer(data, "notQuery", FuzzingStrategy.replace())).isFalse();
}
Aggregations