Search in sources :

Example 1 with CatsResponse

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

the class DuplicateHeaderFuzzer method process.

private void process(FuzzingData data, List<CatsHeader> headers, CatsHeader targetHeader) {
    testCaseListener.addScenario(LOGGER, "Add a duplicate header inside the request: name [{}], value [{}]. All other details are similar to a happy flow", targetHeader.getName(), targetHeader.getTruncatedValue());
    testCaseListener.addExpectedResult(LOGGER, "Should get a 4XX response code");
    CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(headers).payload(data.getPayload()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
    testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.FOURXX);
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse)

Example 2 with CatsResponse

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

the class RemoveHeadersFuzzer method process.

private void process(FuzzingData data, Set<CatsHeader> headersSubset, Set<CatsHeader> requiredHeaders) {
    testCaseListener.addScenario(LOGGER, "Send only the following headers: {} plus any authentication headers.", headersSubset);
    boolean anyMandatoryHeaderRemoved = this.isAnyMandatoryHeaderRemoved(headersSubset, requiredHeaders);
    testCaseListener.addExpectedResult(LOGGER, "Should return [{}] response code as mandatory headers [{}] removed", ResponseCodeFamily.getExpectedWordingBasedOnRequiredFields(anyMandatoryHeaderRemoved));
    CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(headersSubset).payload(data.getPayload()).addUserHeaders(false).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
    testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.getResultCodeBasedOnRequiredFieldsRemoved(anyMandatoryHeaderRemoved));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse)

Example 3 with CatsResponse

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

the class BaseHeadersFuzzer method process.

private void process(FuzzingData data, Set<CatsHeader> clonedHeaders, CatsHeader header, FuzzingStrategy fuzzingStrategy) {
    String previousHeaderValue = header.getValue();
    header.withValue(fuzzingStrategy.process(previousHeaderValue));
    try {
        boolean isRequiredHeaderFuzzed = clonedHeaders.stream().filter(CatsHeader::isRequired).collect(Collectors.toList()).contains(header);
        testCaseListener.addScenario(logger, "Send [{}] in headers: header [{}] with value [{}]", this.typeOfDataSentToTheService(), header.getName(), fuzzingStrategy.truncatedValue());
        testCaseListener.addExpectedResult(logger, "Should get a [{}] response code", this.getExpectedResultCode(isRequiredHeaderFuzzed).asString());
        ServiceData serviceData = ServiceData.builder().relativePath(data.getPath()).headers(clonedHeaders).payload(data.getPayload()).fuzzedHeader(header.getName()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build();
        CatsResponse response = serviceCaller.call(serviceData);
        testCaseListener.reportResult(logger, data, response, this.getExpectedResultCode(isRequiredHeaderFuzzed), this.matchResponseSchema());
    } finally {
        /* we reset back the current header */
        header.withValue(previousHeaderValue);
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ServiceData(com.endava.cats.io.ServiceData) CatsHeader(com.endava.cats.model.CatsHeader)

Example 4 with CatsResponse

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

the class BaseSecurityChecksHeadersFuzzer method process.

private void process(FuzzingData data, Set<CatsHeader> headers) {
    String headerValue = headers.stream().filter(header -> header.getName().equalsIgnoreCase(targetHeaderName())).findFirst().orElse(CatsHeader.builder().build()).getValue();
    testCaseListener.addScenario(log, "Send a happy flow request with a [{}] {} header, value [{}]", typeOfHeader(), targetHeaderName(), headerValue);
    testCaseListener.addExpectedResult(log, "Should get a {} response code", getExpectedResponseCode());
    CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(new ArrayList<>(headers)).payload(data.getPayload()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
    testCaseListener.reportResult(log, data, response, ResponseCodeFamily.FOURXX_MT);
}
Also used : Arrays(java.util.Arrays) Cloner(com.endava.cats.generator.Cloner) PrettyLoggerFactory(io.github.ludovicianul.prettylogger.PrettyLoggerFactory) TestCaseListener(com.endava.cats.report.TestCaseListener) Set(java.util.Set) CatsResponse(com.endava.cats.model.CatsResponse) PrettyLogger(io.github.ludovicianul.prettylogger.PrettyLogger) ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) ArrayList(java.util.ArrayList) Fuzzer(com.endava.cats.Fuzzer) ServiceData(com.endava.cats.io.ServiceData) List(java.util.List) ServiceCaller(com.endava.cats.io.ServiceCaller) FuzzingData(com.endava.cats.model.FuzzingData) CatsHeader(com.endava.cats.model.CatsHeader) CatsResponse(com.endava.cats.model.CatsResponse) ArrayList(java.util.ArrayList)

Example 5 with CatsResponse

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

the class BaseHttpWithPayloadSimpleFuzzer method process.

private void process(FuzzingData data) {
    testCaseListener.addScenario(logger, this.getScenario());
    testCaseListener.addExpectedResult(logger, "Should get a 4XX response code");
    ServiceData serviceData = ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(this.getPayload(data)).replaceRefData(false).httpMethod(data.getMethod()).build();
    if (JsonUtils.isHttpMethodWithPayload(data.getMethod())) {
        CatsResponse response = serviceCaller.call(serviceData);
        testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.FOURXX);
    } else {
        testCaseListener.skipTest(logger, "Method " + data.getMethod() + " not supported by " + this);
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ServiceData(com.endava.cats.io.ServiceData)

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