Search in sources :

Example 16 with FuzzingData

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportWarnWhenServiceRespondsWith400.

@Test
void shouldCallServiceAndReportWarnWhenServiceRespondsWith400() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(400).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportWarn(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 400 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 17 with FuzzingData

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportInfoWhenServiceRespondsWith405.

@Test
void shouldCallServiceAndReportInfoWhenServiceRespondsWith405() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportInfo(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 18 with FuzzingData

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportErrorWhenServiceRespondsWith200.

@Test
void shouldCallServiceAndReportErrorWhenServiceRespondsWith200() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportError(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 200 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 19 with FuzzingData

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

the class TestCaseListenerTest method shouldCallInfoInsteadOfWarnWhenIgnoreCodeSupplied.

@ParameterizedTest
@CsvSource({ "true,false,false", "false,true,false", "true,true,true" })
void shouldCallInfoInsteadOfWarnWhenIgnoreCodeSupplied(boolean ignoreResponseCodes, boolean ignoreUndocumentedRespCode, boolean ignoreResponseBodyCheck) {
    Mockito.when(ignoreArguments.isIgnoredResponseCode(Mockito.anyString())).thenReturn(ignoreResponseCodes);
    Mockito.when(ignoreArguments.isIgnoreResponseCodeUndocumentedCheck()).thenReturn(ignoreUndocumentedRespCode);
    Mockito.when(ignoreArguments.isIgnoreResponseBodyCheck()).thenReturn(ignoreResponseBodyCheck);
    CatsResponse response = CatsResponse.builder().body("{}").responseCode(200).build();
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Mockito.when(data.getResponseCodes()).thenReturn(Set.of("300", "400"));
    Mockito.when(data.getResponses()).thenReturn(Map.of("300", Collections.emptyList()));
    prepareTestCaseListenerSimpleSetup(response);
    testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX);
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseErrors();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSkipped();
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    MDC.remove(TestCaseListener.ID);
}
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 20 with FuzzingData

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

the class TestCaseListenerTest method givenADocumentedResponseThatIsNotExpected_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenADocumentedResponseThatIsNotExpected_whenReportingTheResult_thenTheResultIsCorrectlyReported() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    Mockito.when(response.getBody()).thenReturn("{'test':1}");
    Mockito.when(data.getResponseCodes()).thenReturn(Collections.singleton("400"));
    Mockito.when(data.getResponses()).thenReturn(Collections.singletonMap("200", Collections.singletonList("test")));
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseErrors();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
}
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