Search in sources :

Example 56 with FuzzingData

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

the class BaseFieldsFuzzerTest method shouldSkipWhenFuzzingNotPossibleFromFuzzer.

@Test
void shouldSkipWhenFuzzingNotPossibleFromFuzzer() {
    FuzzingData data = createFuzzingData();
    BaseFieldsFuzzer spyFuzzer = Mockito.spy(baseFieldsFuzzer);
    Mockito.when(spyFuzzer.isFuzzingPossibleSpecificToFuzzer(Mockito.eq(data), Mockito.anyString(), Mockito.any())).thenReturn(false);
    spyFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).skipTest(Mockito.any(), Mockito.eq("Field could not be fuzzed. Possible reasons: field is not a primitive, is a discriminator or is not matching the Fuzzer schemas"));
}
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 57 with FuzzingData

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

the class OnlyControlCharsInFieldsTrimValidateFuzzerTest method givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheTabsOnlyInFieldsTrimValidateFuzzer.

@Test
void givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheTabsOnlyInFieldsTrimValidateFuzzer() {
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Map<String, Schema> schemaMap = new HashMap<>();
    StringSchema stringSchema = new StringSchema();
    schemaMap.put("schema", stringSchema);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
    stringSchema.setMinLength(5);
    fuzzingStrategy = onlyControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat("\u0007", stringSchema.getMinLength() + 1));
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.description()).isNotNull();
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.getInvisibleChars()).contains("\t");
    Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.skipForFields()).containsOnly("pet");
}
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)

Example 58 with FuzzingData

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

the class OnlyControlCharsInFieldsTrimValidateFuzzerTest method givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenGettingTheFieldsFuzzingStrategyAndTheSchemaDoesNotExist_thenTheDefaultNumberOfTabsAreReturned.

@Test
void givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenGettingTheFieldsFuzzingStrategyAndTheSchemaDoesNotExist_thenTheDefaultNumberOfTabsAreReturned() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Map<String, Schema> schemaMap = new HashMap<>();
    StringSchema stringSchema = new StringSchema();
    schemaMap.put("schema", stringSchema);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "another_schema").get(0);
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\r\n");
}
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)

Example 59 with FuzzingData

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

the class OnlyControlCharsInFieldsValidateTrimFuzzerTest method shouldReturnProperLengthWhenNoMinLLength.

@Test
void shouldReturnProperLengthWhenNoMinLLength() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Map<String, Schema> schemaMap = new HashMap<>();
    StringSchema stringSchema = new StringSchema();
    schemaMap.put("schema", stringSchema);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
}
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)

Example 60 with FuzzingData

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

the class OnlyMultiCodePointEmojisInFieldsTrimValidateFuzzerTest method shouldReturnFirstCharacter.

@Test
void shouldReturnFirstCharacter() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Map<String, Schema> schemaMap = new HashMap<>();
    StringSchema stringSchema = new StringSchema();
    schemaMap.put("schema", stringSchema);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    FuzzingStrategy fuzzingStrategy = onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "another_schema").get(0);
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\uD83D\uDC69\uD83C\uDFFE");
}
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