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)));
}
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"));
}
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"));
}
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));
}
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"));
}
Aggregations