Search in sources :

Example 36 with CatsResponse

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

Example 37 with CatsResponse

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));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) JsonObject(com.google.gson.JsonObject) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 38 with CatsResponse

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

Example 39 with CatsResponse

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

Example 40 with CatsResponse

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

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