Search in sources :

Example 41 with FuzzingData

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

the class NullValuesInFieldsFuzzerTest method shouldNotRunForSkippedFields.

@Test
void shouldNotRunForSkippedFields() {
    Mockito.when(ignoreArguments.getSkippedFields()).thenReturn(Collections.singletonList("id"));
    Assertions.assertThat(nullValuesInFieldsFuzzer.skipForFields()).containsOnly("id");
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(Sets.newHashSet("id"));
    Mockito.when(data.getPayload()).thenReturn("{}");
    nullValuesInFieldsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).skipTest(Mockito.any(), Mockito.any());
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 42 with FuzzingData

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

the class SecurityFuzzerTest method givenAnEmptySecurityFuzzerFile_whenTheFuzzerRuns_thenNothingHappens.

@Test
void givenAnEmptySecurityFuzzerFile_whenTheFuzzerRuns_thenNothingHappens() {
    FuzzingData data = FuzzingData.builder().build();
    SecurityFuzzer spyCustomFuzzer = Mockito.spy(securityFuzzer);
    spyCustomFuzzer.fuzz(data);
    Mockito.verifyNoInteractions(testCaseListener);
    Assertions.assertThat(securityFuzzer.description()).isNotNull();
    Assertions.assertThat(securityFuzzer).hasToString(securityFuzzer.getClass().getSimpleName());
    Assertions.assertThat(securityFuzzer.reservedWords()).containsOnly(CatsDSLWords.EXPECTED_RESPONSE_CODE, CatsDSLWords.DESCRIPTION, CatsDSLWords.OUTPUT, CatsDSLWords.VERIFY, CatsDSLWords.STRINGS_FILE, CatsDSLWords.TARGET_FIELDS, CatsDSLWords.MAP_VALUES, CatsDSLWords.ONE_OF_SELECTION, CatsDSLWords.ADDITIONAL_PROPERTIES, CatsDSLWords.ELEMENT, CatsDSLWords.HTTP_METHOD, CatsDSLWords.TARGET_FIELDS_TYPES);
}
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 43 with FuzzingData

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

the class SecurityFuzzerTest method givenASecurityFuzzerFileWithAPathThatIsNotInContract_whenTheFuzzerRuns_thenAnErrorIsReported.

@Test
void givenASecurityFuzzerFileWithAPathThatIsNotInContract_whenTheFuzzerRuns_thenAnErrorIsReported() throws Exception {
    FuzzingData data = setContext("src/test/resources/securityFuzzer.yml", "{'name': {'first': 'Cats'}, 'id': '25'}");
    SecurityFuzzer spySecurityFuzzer = Mockito.spy(securityFuzzer);
    filesArguments.loadSecurityFuzzerFile();
    spySecurityFuzzer.fuzz(data);
    Mockito.verifyNoInteractions(testCaseListener);
}
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 44 with FuzzingData

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

the class ZalgoTextInStringFieldsSanitizeValidateFuzzerTest 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 = zalgoTextInStringFieldsSanitizeValidateFuzzer.getFieldFuzzingStrategy(data, "field").get(0);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).contains("c̷̨̛̥̬͉̘̬̻̩͕͚̦̺̻͓̳͇̲̭̝̙̟̈́̉̐͂͒̆͂̿͌̑͐̌̇̈́̾̉̆̀̅̓͛͋̈̄͊̈̄̎̃̒͂̓̊̌̎̌̃́̅͊̏͘͘͘̕̕͘͠͝a");
    Assertions.assertThat(zalgoTextInStringFieldsSanitizeValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.TWOXX);
    Assertions.assertThat(zalgoTextInStringFieldsSanitizeValidateFuzzer.description()).isNotNull();
    Assertions.assertThat(zalgoTextInStringFieldsSanitizeValidateFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(zalgoTextInStringFieldsSanitizeValidateFuzzer.getInvisibleChars()).isEmpty();
    Assertions.assertThat(zalgoTextInStringFieldsSanitizeValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
}
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 45 with FuzzingData

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

the class BaseBoundaryFieldFuzzerTest method getMockFuzzingData.

private FuzzingData getMockFuzzingData() {
    Map<String, Schema> schemaMap = new HashMap<>();
    schemaMap.put("field", new StringSchema());
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    return data;
}
Also used : HashMap(java.util.HashMap) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) 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)

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