Search in sources :

Example 66 with FuzzingData

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

the class OnlyWhitespacesInFieldsValidateTrimFuzzerTest method givenANewSpacesOnlyInFieldsValidateTrimFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheSpacesOnlyInFieldsValidateTrimFuzzer.

@Test
void givenANewSpacesOnlyInFieldsValidateTrimFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheSpacesOnlyInFieldsValidateTrimFuzzer() {
    Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
    Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.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 = onlyWhitespacesInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(0);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).contains(" ");
    stringSchema.setMinLength(5);
    fuzzingStrategy = onlyWhitespacesInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(0);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat(" ", stringSchema.getMinLength() + 1));
    Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.description()).isNotNull();
    Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
    Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.getInvisibleChars()).contains(" ");
}
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 67 with FuzzingData

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

the class FunctionalFuzzerTest method shouldReplaceRefData.

@Test
void shouldReplaceRefData() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
    File refData = File.createTempFile("refData", ".yml");
    String line = "this/is/custom/${resp}";
    Files.write(refData.toPath(), line.getBytes());
    ReflectionTestUtils.setField(filesArguments, "refDataFile", refData);
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    spyFunctionalFuzzer.replaceRefData();
    File refDataReplaced = new File(refData.getAbsolutePath().substring(0, refData.getAbsolutePath().lastIndexOf(".")) + "_replaced.yml");
    String replaced = Files.readString(refDataReplaced.toPath());
    Assertions.assertThat(replaced).isEqualTo("this/is/custom/200\n");
    refData.deleteOnExit();
    refDataReplaced.deleteOnExit();
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) File(java.io.File) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 68 with FuzzingData

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

the class FunctionalFuzzerTest method shouldParseRequestFields.

@Test
void shouldParseRequestFields() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
    filesArguments.loadCustomFuzzerFile();
    functionalFuzzer.fuzz(data);
    functionalFuzzer.executeCustomFuzzerTests();
    Map<String, String> variables = customFuzzerUtil.getVariables();
    Assertions.assertThat(variables).containsEntry("resp", "200").containsEntry("custId", "john");
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 69 with FuzzingData

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

the class FunctionalFuzzerTest method givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed.

@Test
void givenACustomFuzzerFileWithSimpleTestCases_whenTheFuzzerRuns_thenCustomTestCasesAreExecutedAndDatesAreProperlyParsed() throws Exception {
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).build();
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("field", "oldValue");
    FuzzingData data = this.setupFuzzingData(catsResponse, jsonObject, "T(java.time.OffsetDateTime).now().plusDays(20)");
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(spyFunctionalFuzzer, Mockito.times(1)).processCustomFuzzerFile(data);
    Mockito.verify(testCaseListener, Mockito.times(2)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.eq(catsResponse), Mockito.eq(ResponseCodeFamily.TWOXX));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) JsonObject(com.google.gson.JsonObject) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 70 with FuzzingData

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

the class FunctionalFuzzerTest method shouldVerifyWithRequestVariables.

@Test
void shouldVerifyWithRequestVariables() throws Exception {
    FuzzingData data = setContext("src/test/resources/functionalFuzzer-req-verify.yml", "{\"name\": {\"first\": \"Cats\"}, \"id\": \"25\", \"code\":\"150\",\"petName\":\"myPet\"}");
    FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
    filesArguments.loadCustomFuzzerFile();
    spyFunctionalFuzzer.fuzz(data);
    spyFunctionalFuzzer.executeCustomFuzzerTests();
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(PrettyLogger.class), Mockito.eq("Response matches all 'verify' parameters"), Mockito.any());
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) PrettyLogger(io.github.ludovicianul.prettylogger.PrettyLogger) 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