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