Search in sources :

Example 1 with FuzzingData

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

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

the class TestCaseListenerTest method shouldReportInfoWhenResponseCode200IsExpectedAndResponseBodyIsArray.

@Test
void shouldReportInfoWhenResponseCode200IsExpectedAndResponseBodyIsArray() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    TestCaseListener spyListener = Mockito.spy(testCaseListener);
    Mockito.when(response.getBody()).thenReturn("[{'test':1},{'test':2}]");
    Mockito.when(data.getResponseCodes()).thenReturn(Sets.newHashSet("200", "400"));
    Mockito.when(data.getResponses()).thenReturn(ImmutableMap.of("400", Collections.singletonList("{'test':'4'}"), "200", Collections.singletonList("{'other':'2'}")));
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    spyListener.createAndExecuteTest(logger, fuzzer, () -> spyListener.reportResult(logger, data, response, ResponseCodeFamily.FOURXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    Mockito.verify(spyListener, Mockito.times(1)).reportInfo(logger, "Response matches expected result. Response code [{}] is documented and response body matches the corresponding schema.", response.responseCodeAsString());
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with FuzzingData

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

the class TestCaseListenerTest method shouldReportInfoWhenResponseCodeNotNecessarilyDocumentedIsExpectedAndResponseBodyMatchesButFuzzedFieldNotPresent.

@ParameterizedTest
@CsvSource({ "406,FOURXX_MT", "415,FOURXX_MT", "400,FOURXX" })
void shouldReportInfoWhenResponseCodeNotNecessarilyDocumentedIsExpectedAndResponseBodyMatchesButFuzzedFieldNotPresent(String responseCode, ResponseCodeFamily family) {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    TestCaseListener spyListener = Mockito.spy(testCaseListener);
    Mockito.when(response.getBody()).thenReturn("{'test':1}");
    Mockito.when(data.getResponseCodes()).thenReturn(Sets.newHashSet("200", "4xx"));
    Mockito.when(data.getResponses()).thenReturn(new TreeMap<>(ImmutableMap.of("4xx", Collections.singletonList("{'test':'4'}"), "200", Collections.singletonList("{'other':'2'}"))));
    Mockito.when(response.responseCodeAsString()).thenReturn(responseCode);
    Mockito.when(response.getFuzzedField()).thenReturn("test");
    spyListener.createAndExecuteTest(logger, fuzzer, () -> spyListener.reportResult(logger, data, response, family));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    Mockito.verify(spyListener, Mockito.times(1)).reportInfo(logger, "Response matches expected result. Response code [{}] is documented and response body matches the corresponding schema.", response.responseCodeAsString());
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FuzzingData

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

the class TestCaseListenerTest method shouldReportInfoWhenResponseCodeIsExpectedAndResponseBodyAndDocumentedResponsesAreArrays.

@ParameterizedTest
@CsvSource(value = { "[]|[{'test':'4'},{'test':'4'}]", "[{'test':1},{'test':2}]|{'test':'4'}" }, delimiter = '|')
void shouldReportInfoWhenResponseCodeIsExpectedAndResponseBodyAndDocumentedResponsesAreArrays(String returnedBody, String documentedResponses) {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    TestCaseListener spyListener = Mockito.spy(testCaseListener);
    Mockito.when(response.getBody()).thenReturn(returnedBody);
    Mockito.when(data.getResponseCodes()).thenReturn(Sets.newHashSet("200", "400"));
    Mockito.when(data.getResponses()).thenReturn(ImmutableMap.of("400", Collections.singletonList(documentedResponses), "200", Collections.singletonList("{'other':'2'}")));
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    spyListener.createAndExecuteTest(logger, fuzzer, () -> spyListener.reportResult(logger, data, response, ResponseCodeFamily.FOURXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    Mockito.verify(spyListener, Mockito.times(1)).reportInfo(logger, "Response matches expected result. Response code [{}] is documented and response body matches the corresponding schema.", response.responseCodeAsString());
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with FuzzingData

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

the class TestCaseListenerTest method shouldReportWarnWhenResponseCode400IsExpectedAndResponseBodyMatchesButFuzzedFieldNotPresent.

@Test
void shouldReportWarnWhenResponseCode400IsExpectedAndResponseBodyMatchesButFuzzedFieldNotPresent() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    TestCaseListener spyListener = Mockito.spy(testCaseListener);
    Mockito.when(response.getBody()).thenReturn("{'test':1}");
    Mockito.when(data.getResponseCodes()).thenReturn(Sets.newHashSet("200", "400"));
    Mockito.when(data.getResponses()).thenReturn(ImmutableMap.of("400", Collections.singletonList("{'test':'4'}"), "200", Collections.singletonList("{'other':'2'}")));
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    Mockito.when(response.getFuzzedField()).thenReturn("someField");
    spyListener.createAndExecuteTest(logger, fuzzer, () -> spyListener.reportResult(logger, data, response, ResponseCodeFamily.FOURXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseWarns();
    Mockito.verify(spyListener, Mockito.times(1)).reportWarn(logger, "Response does NOT match expected result. Response code [{}] is documented, but response body does NOT matches the corresponding schema.", response.responseCodeAsString());
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FuzzingData (com.endava.cats.model.FuzzingData)167 QuarkusTest (io.quarkus.test.junit.QuarkusTest)139 Test (org.junit.jupiter.api.Test)139 StringSchema (io.swagger.v3.oas.models.media.StringSchema)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)47 CatsResponse (com.endava.cats.model.CatsResponse)43 HashMap (java.util.HashMap)43 Schema (io.swagger.v3.oas.models.media.Schema)36 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)35 CsvSource (org.junit.jupiter.params.provider.CsvSource)19 List (java.util.List)17 OpenAPI (io.swagger.v3.oas.models.OpenAPI)14 OpenAPIParser (io.swagger.parser.OpenAPIParser)12 PathItem (io.swagger.v3.oas.models.PathItem)12 HashSet (java.util.HashSet)8 File (java.io.File)7 CatsHeader (com.endava.cats.model.CatsHeader)6 Set (java.util.Set)6 CatsUtil (com.endava.cats.util.CatsUtil)5 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)5