Search in sources :

Example 6 with FuzzingResult

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

the class BaseFieldsFuzzerTest method shouldExpectDifferentCodesBasedOnFuzzedFieldMatchingPattern.

@ParameterizedTest
@CsvSource(value = { "null,[a-z]+,200", "cats,[a-z]+,200", "CATS,[a-z]+,400" }, nullValues = "null")
void shouldExpectDifferentCodesBasedOnFuzzedFieldMatchingPattern(String fuzzedValue, String pattern, String responseCode) {
    FuzzingResult fuzzingResult = new FuzzingResult("{\"field\":\"test\"}", fuzzedValue);
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Set<String> fields = Collections.singleton("field");
    Map<String, Schema> schemaMap = new HashMap<>();
    StringSchema schema = new StringSchema();
    schema.setPattern(pattern);
    schemaMap.put("field", schema);
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(fields);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    Mockito.when(data.getPayload()).thenReturn("{\"field\": 2}");
    CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
    Mockito.when(mockCatsUtil.replaceField(Mockito.eq("{\"field\": 2}"), Mockito.eq("field"), Mockito.any())).thenReturn(fuzzingResult);
    baseFieldsFuzzer = new MyBaseFieldsFuzzer(serviceCaller, testCaseListener, mockCatsUtil, filesArguments);
    Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any());
    baseFieldsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.from(responseCode)));
}
Also used : HashMap(java.util.HashMap) CatsUtil(com.endava.cats.util.CatsUtil) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) FuzzingResult(com.endava.cats.model.FuzzingResult) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FuzzingResult (com.endava.cats.model.FuzzingResult)6 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CatsDSLParser (com.endava.cats.dsl.CatsDSLParser)2 FuzzingData (com.endava.cats.model.FuzzingData)2 CatsUtil (com.endava.cats.util.CatsUtil)2 Schema (io.swagger.v3.oas.models.media.Schema)2 StringSchema (io.swagger.v3.oas.models.media.StringSchema)2 HashMap (java.util.HashMap)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 ResponseCodeFamily (com.endava.cats.http.ResponseCodeFamily)1 ServiceData (com.endava.cats.io.ServiceData)1 CatsResponse (com.endava.cats.model.CatsResponse)1 FuzzingConstraints (com.endava.cats.model.FuzzingConstraints)1 DocumentContext (com.jayway.jsonpath.DocumentContext)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.jupiter.api.Test)1