Search in sources :

Example 56 with CatsResponse

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

the class TestCaseListenerTest method givenADocumentedResponseThatMatchesTheResponseCodeAndSchema_whenReportingTheResult_thenTheResultIsCorrectlyReported.

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

Example 57 with CatsResponse

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

the class CheckSecurityHeadersFuzzerTest method shouldNotReportMissingSecurityHeaders.

@Test
void shouldNotReportMissingSecurityHeaders() {
    FuzzingData data = FuzzingData.builder().headers(new HashSet<>(HEADERS)).requestContentTypes(Collections.singletonList("application/json")).reqSchema(new StringSchema()).build();
    Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
    Mockito.doNothing().when(testCaseListener).reportError(Mockito.any(), Mockito.anyString(), Mockito.any());
    List<CatsHeader> allHeaders = new ArrayList<>(SOME_SECURITY_HEADERS);
    allHeaders.add(CatsHeader.builder().name("dummy").value("dummy").build());
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).headers(Stream.concat(allHeaders.stream(), MISSING_HEADERS.stream()).collect(Collectors.toList())).build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    checkSecurityHeadersFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) ArrayList(java.util.ArrayList) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HashSet(java.util.HashSet) CatsHeader(com.endava.cats.model.CatsHeader) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 58 with CatsResponse

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

the class CheckSecurityHeadersFuzzerTest method shouldReportMissingSecurityHeaders.

@Test
void shouldReportMissingSecurityHeaders() {
    FuzzingData data = FuzzingData.builder().headers(new HashSet<>(HEADERS)).requestContentTypes(Collections.singletonList("application/json")).reqSchema(new StringSchema()).build();
    Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
    Mockito.doNothing().when(testCaseListener).reportError(Mockito.any(), Mockito.anyString(), Mockito.any());
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).headers(SOME_SECURITY_HEADERS).build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    checkSecurityHeadersFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("Missing recommended Security Headers: {}"), AdditionalMatchers.aryEq(new Object[] { MISSING_HEADERS.stream().map(CatsHeader::nameAndValue).collect(Collectors.toSet()) }));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HashSet(java.util.HashSet) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 59 with CatsResponse

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

the class DuplicateHeaderFuzzerTest method givenASetOfHeaders_whenCallingTheDuplicateHeadersFuzzer_thenTheResultsAreCorrectlyReported.

@Test
void givenASetOfHeaders_whenCallingTheDuplicateHeadersFuzzer_thenTheResultsAreCorrectlyReported() {
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    FuzzingData data = FuzzingData.builder().headers(Collections.singleton(CatsHeader.builder().name("header").value("value").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());
    duplicateHeaderFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.FOURXX));
}
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)

Example 60 with CatsResponse

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

the class DuplicateHeaderFuzzerTest method givenAnEmptySetOfHeaders_whenCallingTheDuplicateHeadersFuzzer_thenTheResultsAreCorrectlyReported.

@Test
void givenAnEmptySetOfHeaders_whenCallingTheDuplicateHeadersFuzzer_thenTheResultsAreCorrectlyReported() {
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    FuzzingData data = FuzzingData.builder().headers(Collections.emptySet()).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());
    duplicateHeaderFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.FOURXX));
}
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

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