use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecuted.
@Test
void givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecuted() throws Exception {
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("field", "oldValue");
FuzzingData data = this.setupFuzzingData(catsResponse, jsonObject, "newValue", "newValue2");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(spyFunctionalFuzzer, Mockito.times(1)).processCustomFuzzerFile(data);
Mockito.verify(testCaseListener, Mockito.times(3)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.TWOXX));
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class BypassAuthenticationFuzzerTest method givenAPayloadWithAuthenticationHeadersAndCustomHeaders_whenApplyingTheBypassAuthenticationFuzzer_thenTheFuzzerRuns.
@Test
void givenAPayloadWithAuthenticationHeadersAndCustomHeaders_whenApplyingTheBypassAuthenticationFuzzer_thenTheFuzzerRuns() throws Exception {
ReflectionTestUtils.setField(filesArguments, "headersFile", new File("notEmpty"));
Mockito.when(catsUtil.parseYaml(Mockito.anyString())).thenReturn(createCustomFuzzerFile());
filesArguments.loadHeaders();
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).path("test1").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));
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class DummyRequestFuzzerTest method givenAHttpMethodWithPayload_whenApplyingTheMalformedJsonFuzzer_thenTheResultsAreCorrectlyReported.
@Test
void givenAHttpMethodWithPayload_whenApplyingTheMalformedJsonFuzzer_thenTheResultsAreCorrectlyReported() {
FuzzingData data = FuzzingData.builder().method(HttpMethod.POST).build();
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(400).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any());
dummyRequestFuzzer.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 HappyFuzzerTest method givenARequest_whenCallingTheHappyFuzzer_thenTestCasesAreCorrectlyExecuted.
@Test
void givenARequest_whenCallingTheHappyFuzzer_thenTestCasesAreCorrectlyExecuted() {
CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
Map<String, List<String>> responses = new HashMap<>();
responses.put("200", Collections.singletonList("response"));
FuzzingData data = FuzzingData.builder().path("path1").method(HttpMethod.POST).payload("{'field':'oldValue'}").responses(responses).responseCodes(Collections.singleton("200")).reqSchema(new StringSchema()).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
happyFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.TWOXX));
Assertions.assertThat(happyFuzzer.description()).isNotNull();
Assertions.assertThat(happyFuzzer).hasToString(happyFuzzer.getClass().getSimpleName());
}
use of com.endava.cats.model.CatsResponse in project cats by Endava.
the class HttpMethodsFuzzerTest method shouldNotFuzzSamePathTwice.
@Test
void shouldNotFuzzSamePathTwice() {
FuzzingData data = FuzzingData.builder().path("/pet").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);
httpMethodsFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(7)).reportError(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 200 }));
httpMethodsFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(7)).reportError(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 200 }));
}
Aggregations