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