Search in sources :

Example 61 with FuzzingData

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

the class OnlyMultiCodePointEmojisInFieldsTrimValidateFuzzerTest method shouldProperlyOverrideMethods.

@Test
void shouldProperlyOverrideMethods() {
    Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
    Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.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 = onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\uD83D\uDC68\u200D\uD83C\uDFED️");
    stringSchema.setMinLength(5);
    fuzzingStrategy = onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    String theEmoji = "\uD83D\uDC68\u200D\uD83C\uDFED️";
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat(theEmoji, (stringSchema.getMinLength() / theEmoji.length()) + 1));
    Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.description()).isNotNull();
    Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
    Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getInvisibleChars()).contains("\uD83D\uDC68\u200D\uD83C\uDFED️");
}
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 62 with FuzzingData

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

the class OnlyMultiCodePointEmojisInFieldsValidateTrimFuzzerTest 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 = onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\uD83D\uDC68\u200D\uD83C\uDFED️");
}
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 63 with FuzzingData

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

the class OnlySingleCodePointEmojisInFieldsTrimValidateFuzzerTest method shouldReturnDefaultNumberOfTabs.

@Test
void shouldReturnDefaultNumberOfTabs() {
    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 = onlySingleCodePointEmojisInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "another_schema").get(0);
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\uD83E\uDD76");
}
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 64 with FuzzingData

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

the class OnlySingleCodePointEmojisInFieldsValidateTrimFuzzerTest 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 = onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\uD83D\uDC80");
}
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 65 with FuzzingData

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

the class OnlyWhitespacesInFieldsTrimValidateFuzzerTest method givenANewSpacesOnlyInFieldsTrimValidateFuzzer_whenGettingTheFieldsFuzzingStrategyAndTheSchemaDoesNotExist_thenTheDefaultNumberOfSpacesAreReturned.

@Test
void givenANewSpacesOnlyInFieldsTrimValidateFuzzer_whenGettingTheFieldsFuzzingStrategyAndTheSchemaDoesNotExist_thenTheDefaultNumberOfSpacesAreReturned() {
    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 = onlyWhitespacesInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "another_schema").get(0);
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(" ");
}
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