Search in sources :

Example 6 with CatsUtil

use of com.endava.cats.util.CatsUtil 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)

Example 7 with CatsUtil

use of com.endava.cats.util.CatsUtil in project cats by Endava.

the class BaseFieldsFuzzerTest method shouldNotRunWhenNoFields.

@Test
void shouldNotRunWhenNoFields() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(Collections.emptySet());
    CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
    baseFieldsFuzzer = new MyBaseFieldsFuzzer(serviceCaller, testCaseListener, mockCatsUtil, filesArguments);
    baseFieldsFuzzer.fuzz(data);
    Mockito.verifyNoInteractions(testCaseListener);
}
Also used : CatsUtil(com.endava.cats.util.CatsUtil) FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CatsUtil (com.endava.cats.util.CatsUtil)7 FilesArguments (com.endava.cats.args.FilesArguments)4 FuzzingData (com.endava.cats.model.FuzzingData)4 CustomFuzzerUtil (com.endava.cats.fuzzer.CustomFuzzerUtil)3 ServiceCaller (com.endava.cats.io.ServiceCaller)3 TestCaseExporter (com.endava.cats.report.TestCaseExporter)3 StringSchema (io.swagger.v3.oas.models.media.StringSchema)3 HashMap (java.util.HashMap)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 CatsDSLParser (com.endava.cats.dsl.CatsDSLParser)2 FuzzingResult (com.endava.cats.model.FuzzingResult)2 Schema (io.swagger.v3.oas.models.media.Schema)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 File (java.io.File)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.jupiter.api.Test)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1