Search in sources :

Example 1 with ServiceData

use of com.endava.cats.io.ServiceData 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 2 with ServiceData

use of com.endava.cats.io.ServiceData 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)

Example 3 with ServiceData

use of com.endava.cats.io.ServiceData in project cats by Endava.

the class BypassAuthenticationFuzzer method process.

private void process(FuzzingData data) {
    testCaseListener.addScenario(LOGGER, "Send a happy flow bypassing authentication");
    testCaseListener.addExpectedResult(LOGGER, "Should get a 403 or 401 response code");
    Set<String> authenticationHeaders = this.getAuthenticationHeaderProvided(data);
    if (!authenticationHeaders.isEmpty()) {
        ServiceData serviceData = ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).httpMethod(data.getMethod()).payload(data.getPayload()).skippedHeaders(authenticationHeaders).queryParams(data.getQueryParams()).build();
        CatsResponse response = serviceCaller.call(serviceData);
        testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.FOURXX_AA);
    } else {
        testCaseListener.skipTest(LOGGER, "No authentication header provided.");
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ServiceData(com.endava.cats.io.ServiceData)

Example 4 with ServiceData

use of com.endava.cats.io.ServiceData in project cats by Endava.

the class BaseFieldsFuzzer method process.

protected void process(FuzzingData data, String fuzzedField, FuzzingStrategy fuzzingStrategy) {
    FuzzingConstraints fuzzingConstraints = this.createFuzzingConstraints(data, fuzzingStrategy, fuzzedField);
    testCaseListener.addScenario(logger, "Send [{}] in request fields: field [{}], value [{}], is required [{}]", this.typeOfDataSentToTheService(), fuzzedField, fuzzingStrategy.truncatedValue(), fuzzingConstraints.getRequiredString());
    if (this.isFuzzingPossible(data, fuzzedField, fuzzingStrategy)) {
        FuzzingResult fuzzingResult = catsUtil.replaceField(data.getPayload(), fuzzedField, fuzzingStrategy);
        boolean isFuzzedValueMatchingPattern = this.isFuzzedValueMatchingPattern(fuzzingResult.getFuzzedValue(), data, fuzzedField);
        ServiceData serviceData = ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(fuzzingResult.getJson()).httpMethod(data.getMethod()).fuzzedField(fuzzedField).queryParams(data.getQueryParams()).build();
        CatsResponse response = serviceCaller.call(serviceData);
        ResponseCodeFamily expectedResponseCodeBasedOnConstraints = this.getExpectedResponseCodeBasedOnConstraints(isFuzzedValueMatchingPattern, fuzzingConstraints);
        testCaseListener.addExpectedResult(logger, "Should return [{}]", expectedResponseCodeBasedOnConstraints.asString());
        testCaseListener.reportResult(logger, data, response, expectedResponseCodeBasedOnConstraints);
    } else {
        FuzzingStrategy strategy = this.createSkipStrategy(fuzzingStrategy);
        testCaseListener.skipTest(logger, strategy.process(""));
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) FuzzingResult(com.endava.cats.model.FuzzingResult) FuzzingConstraints(com.endava.cats.model.FuzzingConstraints) ServiceData(com.endava.cats.io.ServiceData)

Aggregations

ServiceData (com.endava.cats.io.ServiceData)4 CatsResponse (com.endava.cats.model.CatsResponse)4 ResponseCodeFamily (com.endava.cats.http.ResponseCodeFamily)1 CatsHeader (com.endava.cats.model.CatsHeader)1 FuzzingConstraints (com.endava.cats.model.FuzzingConstraints)1 FuzzingResult (com.endava.cats.model.FuzzingResult)1 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)1