use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class CommonWithinMethodsTest method shouldInsertWithoutReplaceWhenEnums.
@Test
void shouldInsertWithoutReplaceWhenEnums() {
StringSchema schema = new StringSchema();
schema.setEnum(List.of("ENUM"));
FuzzingData fuzzingData = Mockito.mock(FuzzingData.class);
Map<String, Schema> reqPropTypes = Map.of("test2", schema);
Mockito.when(fuzzingData.getRequestPropertyTypes()).thenReturn(reqPropTypes);
List<FuzzingStrategy> fuzzingStrategyList = CommonWithinMethods.getFuzzingStrategies(fuzzingData, "test2", List.of(YY), false);
Assertions.assertThat(fuzzingStrategyList).hasSize(1);
Assertions.assertThat(fuzzingStrategyList.get(0).getData()).isEqualTo("EN" + YY + "UM");
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class SecurityFuzzerTest method shouldConsiderFieldsWithTypeStringWhenRunningFuzzer.
@Test
void shouldConsiderFieldsWithTypeStringWhenRunningFuzzer() throws Exception {
FuzzingData data = setContext("src/test/resources/securityFuzzer-fieldTypes.yml", "{'name': {'first': 'Cats'}, 'id': '25'}");
SecurityFuzzer spySecurityFuzzer = Mockito.spy(securityFuzzer);
filesArguments.loadSecurityFuzzerFile();
spySecurityFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(63)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class SecurityFuzzerTest method setContext.
private FuzzingData setContext(String fuzzerFile, String responsePayload) throws Exception {
ReflectionTestUtils.setField(filesArguments, "securityFuzzerFile", new File(fuzzerFile));
Map<String, List<String>> responses = new HashMap<>();
responses.put("200", Collections.singletonList("response"));
CatsResponse catsResponse = CatsResponse.from(200, responsePayload, "POST", 2);
Map<String, Schema> properties = new HashMap<>();
properties.put("firstName", new StringSchema());
properties.put("lastName", new StringSchema());
properties.put("age", new IntegerSchema());
properties.put("city", new StringSchema());
StringSchema email = new StringSchema();
email.setFormat("email");
properties.put("email", email);
ObjectSchema person = new ObjectSchema();
person.setProperties(properties);
FuzzingData data = FuzzingData.builder().path("/pets/{id}/move").payload("{'name':'oldValue', 'firstName':'John','lastName':'Cats','email':'john@yahoo.com'}").responses(responses).responseCodes(Collections.singleton("200")).method(HttpMethod.POST).reqSchema(person).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
return data;
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class StringFieldsLeftBoundaryFuzzerTest method givenANewStringFieldsLeftBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsLeftBoundaryFuzzer.
@Test
void givenANewStringFieldsLeftBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsLeftBoundaryFuzzer() {
NumberSchema nrSchema = new NumberSchema();
FuzzingData data = FuzzingData.builder().requestPropertyTypes(Collections.singletonMap("test", nrSchema)).build();
Assertions.assertThat(stringFieldsLeftBoundaryFuzzer.getSchemasThatTheFuzzerWillApplyTo().stream().anyMatch(schema -> schema.isAssignableFrom(StringSchema.class))).isTrue();
Assertions.assertThat(stringFieldsLeftBoundaryFuzzer.getBoundaryValue(nrSchema)).isNotNull();
Assertions.assertThat(stringFieldsLeftBoundaryFuzzer.hasBoundaryDefined("test", data)).isFalse();
Assertions.assertThat(stringFieldsLeftBoundaryFuzzer.description()).isNotNull();
nrSchema.setMinLength(2);
Assertions.assertThat(stringFieldsLeftBoundaryFuzzer.hasBoundaryDefined("test", data)).isTrue();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class WithinMultiCodePointEmojisInFieldsValidateTrimFuzzerTest method shouldProperlyOverrideSuperClassMethods.
@Test
void shouldProperlyOverrideSuperClassMethods() {
FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> reqTypes = new HashMap<>();
reqTypes.put("field", new StringSchema());
Mockito.when(data.getRequestPropertyTypes()).thenReturn(reqTypes);
FuzzingStrategy fuzzingStrategy = withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "field").get(1);
Assertions.assertThat(fuzzingStrategy.getData()).contains("\uD83D\uDC68\u200D\uD83C\uDFED️");
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(withinMultiCodePointEmojisInFieldsValidateTrimFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());
}
Aggregations