use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class ReplayCommand method executeTestCase.
public void executeTestCase(String testCaseFileName) throws IOException {
String testCaseFile = Files.readString(Paths.get(testCaseFileName));
LOGGER.note("Loaded content: \n" + testCaseFile);
CatsTestCase testCase = JsonUtils.GSON.fromJson(testCaseFile, CatsTestCase.class);
LOGGER.info("Calling service...");
CatsResponse response = serviceCaller.callService(testCase.getRequest(), Collections.emptySet());
LOGGER.complete("Response body: \n{}", JsonUtils.GSON.toJson(response.getJsonBody()));
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed.
@Test
void givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed() throws Exception {
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("field", "oldValue");
FuzzingData data = this.setupFuzzingData(catsResponse, jsonObject, "T(java.time.OffsetDateTime).now().plusDays(20)");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(spyFunctionalFuzzer, Mockito.times(1)).processCustomFuzzerFile(data);
Mockito.verify(testCaseListener, Mockito.times(2)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.TWOXX));
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class SecurityFuzzerTest method setContext.
private FuzzingData setContext(String fuzzerFile, String responsePayload) throws Exception {
ReflectionTestUtils.setField(filesArguments, "securityFuzzerFile", new File(fuzzerFile));
Map<String, List<String>> responses = new HashMap<>();
responses.put("200", Collections.singletonList("response"));
CatsResponse catsResponse = CatsResponse.from(200, responsePayload, "POST", 2);
Map<String, Schema> properties = new HashMap<>();
properties.put("firstName", new StringSchema());
properties.put("lastName", new StringSchema());
properties.put("age", new IntegerSchema());
properties.put("city", new StringSchema());
StringSchema email = new StringSchema();
email.setFormat("email");
properties.put("email", email);
ObjectSchema person = new ObjectSchema();
person.setProperties(properties);
FuzzingData data = FuzzingData.builder().path("/pets/{id}/move").payload("{'name':'oldValue', 'firstName':'John','lastName':'Cats','email':'john@yahoo.com'}").responses(responses).responseCodes(Collections.singleton("200")).method(HttpMethod.POST).reqSchema(person).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
return data;
}
use of com.endava.cats.model.CatsResponse 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(""));
}
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class NewFieldsFuzzer method process.
private void process(FuzzingData data) {
JsonElement fuzzedJson = this.addNewField(data);
ResponseCodeFamily expectedResultCode = ResponseCodeFamily.TWOXX;
if (JsonUtils.isHttpMethodWithPayload(data.getMethod())) {
expectedResultCode = ResponseCodeFamily.FOURXX;
}
testCaseListener.addScenario(LOGGER, "Add new field inside the request: name [{}], value [{}]. All other details are similar to a happy flow", NEW_FIELD, NEW_FIELD);
testCaseListener.addExpectedResult(LOGGER, "Should get a [{}] response code", expectedResultCode.asString());
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(fuzzedJson.toString()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
testCaseListener.reportResult(LOGGER, data, response, expectedResultCode);
}
Aggregations