Search in sources :

Example 96 with FuzzingData

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

the class NamingsContractInfoFuzzerTest method shouldReportError.

@ParameterizedTest
@CsvSource({ "/petsPath", "/pets_path", "/pets-path-link", "/pets/Paths", "/pets/complex-Paths", "/pets/{petid10}", "/pets/{pet-id}", "/admin/admin/pets/admin" })
void shouldReportError(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)).reportError(Mockito.any(), Mockito.eq("Path does not follow RESTful API naming good practices: {}"), Mockito.contains(path.substring(path.lastIndexOf("/") + 1)));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) FuzzingData(com.endava.cats.model.FuzzingData) Operation(io.swagger.v3.oas.models.Operation) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 97 with FuzzingData

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

the class PathTagsContractInfoFuzzerTest method shouldReportErrorWhenMissingPathTags.

@Test
void shouldReportErrorWhenMissingPathTags() throws Exception {
    OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/contract-no-path-tags.yml"))), null, null).getOpenAPI();
    FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").build();
    pathTagsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.contains("The current path does not contain any [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 98 with FuzzingData

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

the class PathTagsContractInfoFuzzerTest 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")).build();
    pathTagsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.contains("The current path's [tags] are correctly defined at 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 99 with FuzzingData

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

the class RecommendedHeadersContractInfoFuzzerTest method shouldReportError.

@ParameterizedTest
@CsvSource({ "X-Trac-Id", "XTracing", "X-Correlation", "X-APP-Correlation*Id" })
void shouldReportError(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)).reportError(Mockito.any(), Mockito.eq("Path does not contain 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 100 with FuzzingData

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

the class SecuritySchemesContractInfoFuzzerTest method shouldReportError.

@Test
void shouldReportError() throws Exception {
    OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/contract-no-security.yml"))), null, null).getOpenAPI();
    FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").tags(Collections.singletonList("pet")).method(HttpMethod.PUT).pathItem(openAPI.getPaths().get("/pet")).build();
    securitySchemesContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("The current path does not have security scheme(s) defined and there are none defined globally"));
}
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)

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