Search in sources :

Example 6 with FuzzingData

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

the class TestCaseListenerTest method shouldReportWarnWhenResponseCode400IsUndocumentedAndResponseBodyMatches.

@Test
void shouldReportWarnWhenResponseCode400IsUndocumentedAndResponseBodyMatches() {
    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", "401"));
    Mockito.when(data.getResponses()).thenReturn(ImmutableMap.of("401", 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)).increaseWarns();
    Mockito.verify(spyListener, Mockito.times(1)).reportWarn(logger, "Response does NOT match expected result. Response code is from a list of expected codes for this FUZZER, but it is undocumented: expected {}, actual [{}], documented response codes: {}", ResponseCodeFamily.FOURXX.allowedResponseCodes(), response.responseCodeAsString(), data.getResponseCodes());
}
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 7 with FuzzingData

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

the class TestCaseListenerTest method givenAnUndocumentedResponseThatMatchesTheResponseCode_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenAnUndocumentedResponseThatMatchesTheResponseCode_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("200");
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResultDetails()).startsWith("Response does NOT match expected result. Response code is from a list of expected codes for this FUZZER");
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with FuzzingData

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

the class TestCaseListenerTest method givenADocumentedResponseThatMatchesTheResponseCodeAndButNotSchema_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenADocumentedResponseThatMatchesTheResponseCodeAndButNotSchema_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("200"));
    Mockito.when(data.getResponses()).thenReturn(Collections.singletonMap("200", Collections.singletonList("nomatch")));
    Mockito.when(response.responseCodeAsString()).thenReturn("200");
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResultDetails()).startsWith("Response does NOT match expected result. Response code");
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with FuzzingData

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

the class TestCaseListenerTest method shouldReportInfoWhenResponseCode400IsExpectedAndResponseBodyMatchesAndFuzzedFieldNullOrPresent.

@ParameterizedTest
@CsvSource({ ",", "test" })
void shouldReportInfoWhenResponseCode400IsExpectedAndResponseBodyMatchesAndFuzzedFieldNullOrPresent(String fuzzedField) {
    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(fuzzedField);
    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 10 with FuzzingData

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

the class BypassAuthenticationFuzzerTest method givenAPayloadWithAuthenticationHeaders_whenApplyingTheBypassAuthenticationFuzzer_thenTheFuzzerRuns.

@Test
void givenAPayloadWithAuthenticationHeaders_whenApplyingTheBypassAuthenticationFuzzer_thenTheFuzzerRuns() {
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    FuzzingData data = FuzzingData.builder().headers(Collections.singleton(CatsHeader.builder().name("authorization").value("auth").build())).responses(responses).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any());
    bypassAuthenticationFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.FOURXX_AA));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) HashMap(java.util.HashMap) FuzzingData(com.endava.cats.model.FuzzingData) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

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