use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class CheckSecurityHeadersFuzzer method process.
private void process(FuzzingData data) {
testCaseListener.addScenario(log, "Send a happy flow request and check the following Security Headers: {}", SECURITY_HEADERS_AS_STRING);
testCaseListener.addExpectedResult(log, "Should get a 2XX response code and all the above security headers within the response");
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(data.getPayload()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
List<CatsHeader> missingSecurityHeaders = getMissingSecurityHeaders(response);
if (!missingSecurityHeaders.isEmpty()) {
testCaseListener.reportError(log, "Missing recommended Security Headers: {}", missingSecurityHeaders.stream().map(CatsHeader::nameAndValue).collect(Collectors.toSet()));
} else {
testCaseListener.reportResult(log, data, response, ResponseCodeFamily.TWOXX);
}
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class ExtraHeaderFuzzer method process.
private void process(FuzzingData data) {
Set<CatsHeader> headerSet = new HashSet<>(data.getHeaders());
headerSet.add(CatsHeader.builder().name(CATS_FUZZY_HEADER).required(false).value(CATS_FUZZY_HEADER).build());
testCaseListener.addScenario(LOGGER, "Add extra header inside the request: name [{}], value [{}]. All other details are similar to a happy flow", CATS_FUZZY_HEADER, CATS_FUZZY_HEADER);
testCaseListener.addExpectedResult(LOGGER, "Should get a 2XX response code");
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).httpMethod(data.getMethod()).headers(headerSet).payload(data.getPayload()).queryParams(data.getQueryParams()).build());
testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.TWOXX);
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class ServiceCaller method call.
/**
* When in dryRun mode ServiceCaller won't do any actual calls.
*
* @param data the current context data
* @return the result of service invocation
*/
@DryRun
public CatsResponse call(ServiceData data) {
LOGGER.note("Proxy configuration to be used: {}", authArguments.getProxy());
rateLimiter.acquire();
String processedPayload = this.replacePayloadWithRefData(data);
List<CatsRequest.Header> headers = this.buildHeaders(data);
CatsRequest catsRequest = new CatsRequest();
catsRequest.setHeaders(headers);
catsRequest.setPayload(processedPayload);
catsRequest.setHttpMethod(data.getHttpMethod().name());
try {
String url = this.getPathWithRefDataReplacedForHttpEntityRequests(data, apiArguments.getServer() + data.getRelativePath());
if (!HttpMethod.requiresBody(data.getHttpMethod())) {
url = this.getPathWithRefDataReplacedForNonHttpEntityRequests(data, apiArguments.getServer() + data.getRelativePath());
url = this.addUriParams(processedPayload, data, url);
}
catsRequest.setUrl(url);
LOGGER.note("Final list of request headers: {}", headers);
LOGGER.note("Final payload: {}", processedPayload);
CatsResponse response = this.callService(catsRequest, data.getFuzzedFields());
this.recordRequestAndResponse(catsRequest, response, data);
return response;
} catch (IOException e) {
this.recordRequestAndResponse(catsRequest, CatsResponse.empty(), data);
throw new CatsIOException(e);
}
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class HttpMethodFuzzerUtil method process.
public void process(FuzzingData data, Function<ServiceData, CatsResponse> f, HttpMethod httpMethod) {
testCaseListener.addScenario(LOGGER, "Send a happy flow request with undocumented HTTP method: {}", httpMethod);
testCaseListener.addExpectedResult(LOGGER, "Should get a 405 response code");
String payload = HttpMethod.requiresBody(httpMethod) ? data.getPayload() : "";
CatsResponse response = f.apply(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(payload).httpMethod(httpMethod).build());
this.checkResponse(response);
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class FunctionalFuzzerTest method setContext.
private FuzzingData setContext(String fuzzerFile, String responsePayload) throws Exception {
ReflectionTestUtils.setField(filesArguments, "customFuzzerFile", new File(fuzzerFile));
Map<String, List<String>> responses = new HashMap<>();
responses.put("200", Collections.singletonList("response"));
CatsResponse catsResponse = CatsResponse.from(200, responsePayload, "POST", 2);
FuzzingData data = FuzzingData.builder().path("/pets/{id}/move").payload("{\"pet\":\"oldValue\", \"name\":\"dodo\"}").responses(responses).responseCodes(Collections.singleton("200")).reqSchema(new StringSchema()).method(HttpMethod.POST).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
return data;
}
Aggregations