Search in sources :

Example 41 with CatsResponse

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);
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) CatsHeader(com.endava.cats.model.CatsHeader)

Example 42 with CatsResponse

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);
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) CatsHeader(com.endava.cats.model.CatsHeader) HashSet(java.util.HashSet)

Example 43 with CatsResponse

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);
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) CatsHeader(com.endava.cats.model.CatsHeader) IOException(java.io.IOException) CatsRequest(com.endava.cats.model.CatsRequest) DryRun(com.endava.cats.annotations.DryRun)

Example 44 with CatsResponse

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);
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse)

Example 45 with CatsResponse

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;
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) HashMap(java.util.HashMap) FuzzingData(com.endava.cats.model.FuzzingData) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) File(java.io.File)

Aggregations

CatsResponse (com.endava.cats.model.CatsResponse)67 FuzzingData (com.endava.cats.model.FuzzingData)44 QuarkusTest (io.quarkus.test.junit.QuarkusTest)42 Test (org.junit.jupiter.api.Test)42 StringSchema (io.swagger.v3.oas.models.media.StringSchema)23 List (java.util.List)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 HashMap (java.util.HashMap)14 CatsHeader (com.endava.cats.model.CatsHeader)7 PathItem (io.swagger.v3.oas.models.PathItem)7 ServiceData (com.endava.cats.io.ServiceData)6 CatsTestCase (com.endava.cats.model.report.CatsTestCase)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ResponseCodeFamily (com.endava.cats.http.ResponseCodeFamily)4 ArrayList (java.util.ArrayList)4 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)3 TestCaseListener (com.endava.cats.report.TestCaseListener)3 JsonObject (com.google.gson.JsonObject)3 PrettyLogger (io.github.ludovicianul.prettylogger.PrettyLogger)3 PrettyLoggerFactory (io.github.ludovicianul.prettylogger.PrettyLoggerFactory)3