Search in sources :

Example 36 with FuzzingData

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!"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with FuzzingData

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"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) OpenAPIParser(io.swagger.parser.OpenAPIParser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 38 with FuzzingData

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"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) OpenAPIParser(io.swagger.parser.OpenAPIParser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 39 with FuzzingData

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();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 40 with FuzzingData

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