Search in sources :

Example 76 with FuzzingData

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");
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 77 with FuzzingData

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));
}
Also used : 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 78 with FuzzingData

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;
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) HashMap(java.util.HashMap) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) FuzzingData(com.endava.cats.model.FuzzingData) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) File(java.io.File)

Example 79 with FuzzingData

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();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 80 with FuzzingData

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());
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) HashMap(java.util.HashMap) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) FuzzingData(com.endava.cats.model.FuzzingData) 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