Search in sources :

Example 31 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class VersionsContractInfoFuzzerTest method shouldNotRunOnSecondAttempt.

@Test
void shouldNotRunOnSecondAttempt() {
    FuzzingData data = FuzzingData.builder().path("/path/user").build();
    versionsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path does not contain versioning information"));
    Mockito.reset(testCaseListener);
    versionsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(0)).reportInfo(Mockito.any(), Mockito.eq("Path does not contain versioning information"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class PathTagsContractInfoFuzzerTest method shouldReportErrorWhenTagsMismatch.

@Test
void shouldReportErrorWhenTagsMismatch() 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").tags(Collections.singletonList("petsCats")).build();
    pathTagsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.contains("The following [tags] are not present in the top level [tags] element: {}"), Mockito.eq(data.getTags()));
}
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 33 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class PathTagsContractInfoFuzzerTest method shouldNotRunOnSecondAttempt.

@Test
void shouldNotRunOnSecondAttempt() 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")).build();
    pathTagsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("The current path's [tags] are correctly defined at the top level [tags] element"));
    Mockito.reset(testCaseListener);
    pathTagsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(0)).reportInfo(Mockito.any(), Mockito.eq("The current path's [tags] are correctly defined in the top level [tags] element"));
}
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 34 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class RecommendedHeadersContractInfoFuzzerTest method shouldReportInfo.

@ParameterizedTest
@CsvSource({ "X-Trace-Id", "XTraceid", "X-CorrelationId", "X-APP-Correlation_Id" })
void shouldReportInfo(String header) {
    CatsHeader catsHeader = CatsHeader.builder().name(header).build();
    FuzzingData data = FuzzingData.builder().headers(Sets.newHashSet(catsHeader)).method(HttpMethod.POST).build();
    recommendedHeadersContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path contains the recommended [TracedId/CorrelationId] headers for HTTP method {}"), Mockito.eq(HttpMethod.POST));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CatsHeader(com.endava.cats.model.CatsHeader) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class RecommendedHttpCodesContractInfoFuzzerTest method shouldReportErrorWhenAllResponseCodesAreValid.

@ParameterizedTest
@CsvSource(value = { "400,500;POST;200|201|202|204", "400,500;POST;200|201|202|204", "400,202;POST;500", "500,204;POST;400", "404,500,201;PUT;400", "400,500,202;GET;404", "200;HEAD;404", "404;HEAD;200|202", "404,500,200;DELETE;400", "400,500,201;DELETE;404", "400,404,202;DELETE;500", "400,404,500;DELETE;200|201|202|204", "404,500,200;PATCH;400", "400,500,201;PATCH;404", "400,404,202;PATCH;500", "400,404,500;PATCH;200|201|202|204", "500,200;TRACE;400", "400,200;TRACE;500" }, delimiter = ';')
void shouldReportErrorWhenAllResponseCodesAreValid(String responseCode, HttpMethod method, String missing) {
    FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData("PetStore", method, responseCode.split(","));
    recommendedHttpCodesContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("The following recommended HTTP response codes are missing: {}"), Mockito.eq(Collections.singletonList(missing)));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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