Search in sources :

Example 1 with CatsUtil

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

the class SecurityFuzzerTest method setup.

@BeforeEach
void setup() {
    catsDSLParser = new CatsDSLParser();
    catsUtil = new CatsUtil(catsDSLParser);
    serviceCaller = Mockito.mock(ServiceCaller.class);
    filesArguments = new FilesArguments(catsUtil);
    customFuzzerUtil = new CustomFuzzerUtil(serviceCaller, catsUtil, testCaseListener, catsDSLParser);
    securityFuzzer = new SecurityFuzzer(filesArguments, customFuzzerUtil);
    ReflectionTestUtils.setField(testCaseListener, "testCaseExporter", Mockito.mock(TestCaseExporter.class));
}
Also used : FilesArguments(com.endava.cats.args.FilesArguments) CatsUtil(com.endava.cats.util.CatsUtil) CustomFuzzerUtil(com.endava.cats.fuzzer.CustomFuzzerUtil) ServiceCaller(com.endava.cats.io.ServiceCaller) TestCaseExporter(com.endava.cats.report.TestCaseExporter) CatsDSLParser(com.endava.cats.dsl.CatsDSLParser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with CatsUtil

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

the class BaseFieldsFuzzerTest method createFuzzingData.

@NotNull
private FuzzingData createFuzzingData() {
    FuzzingResult fuzzingResult = Mockito.mock(FuzzingResult.class);
    Mockito.when(fuzzingResult.getJson()).thenReturn("{}");
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Set<String> fields = Collections.singleton("field");
    Map<String, Schema> schemaMap = new HashMap<>();
    schemaMap.put("field", new StringSchema());
    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());
    return data;
}
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) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CatsUtil

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

the class FunctionalFuzzerTest method setup.

@BeforeEach
void setup() {
    catsDSLParser = new CatsDSLParser();
    catsUtil = new CatsUtil(catsDSLParser);
    serviceCaller = Mockito.mock(ServiceCaller.class);
    filesArguments = new FilesArguments(catsUtil);
    customFuzzerUtil = new CustomFuzzerUtil(serviceCaller, catsUtil, testCaseListener, catsDSLParser);
    functionalFuzzer = new FunctionalFuzzer(filesArguments, customFuzzerUtil);
    filesArguments.getCustomFuzzerDetails().clear();
    ReflectionTestUtils.setField(testCaseListener, "testCaseExporter", Mockito.mock(TestCaseExporter.class));
}
Also used : FilesArguments(com.endava.cats.args.FilesArguments) CatsUtil(com.endava.cats.util.CatsUtil) CustomFuzzerUtil(com.endava.cats.fuzzer.CustomFuzzerUtil) ServiceCaller(com.endava.cats.io.ServiceCaller) TestCaseExporter(com.endava.cats.report.TestCaseExporter) CatsDSLParser(com.endava.cats.dsl.CatsDSLParser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CatsUtil

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

the class FunctionalFuzzerTest method setupFuzzingData.

private FuzzingData setupFuzzingData(CatsResponse catsResponse, JsonObject jsonObject, String... customFieldValues) throws IOException {
    Map<String, List<String>> responses = new HashMap<>();
    responses.put("200", Collections.singletonList("response"));
    FuzzingData data = FuzzingData.builder().path("path1").payload("{\"field\":\"oldValue\"}").responses(responses).responseCodes(Collections.singleton("200")).reqSchema(new StringSchema()).method(HttpMethod.POST).build();
    CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
    Mockito.when(mockCatsUtil.parseYaml(any())).thenReturn(createCustomFuzzerFile(customFieldValues));
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    filesArguments = new FilesArguments(mockCatsUtil);
    customFuzzerUtil = new CustomFuzzerUtil(serviceCaller, mockCatsUtil, testCaseListener, catsDSLParser);
    functionalFuzzer = new FunctionalFuzzer(filesArguments, customFuzzerUtil);
    ReflectionTestUtils.setField(filesArguments, "customFuzzerFile", new File("custom"));
    return data;
}
Also used : FilesArguments(com.endava.cats.args.FilesArguments) HashMap(java.util.HashMap) CatsUtil(com.endava.cats.util.CatsUtil) FuzzingData(com.endava.cats.model.FuzzingData) CustomFuzzerUtil(com.endava.cats.fuzzer.CustomFuzzerUtil) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) File(java.io.File)

Example 5 with CatsUtil

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

the class BypassAuthenticationFuzzerTest method setup.

@BeforeEach
void setup() {
    catsUtil = Mockito.mock(CatsUtil.class);
    filesArguments = new FilesArguments(catsUtil);
    serviceCaller = Mockito.mock(ServiceCaller.class);
    bypassAuthenticationFuzzer = new BypassAuthenticationFuzzer(serviceCaller, testCaseListener, filesArguments);
    ReflectionTestUtils.setField(testCaseListener, "testCaseExporter", Mockito.mock(TestCaseExporter.class));
}
Also used : FilesArguments(com.endava.cats.args.FilesArguments) CatsUtil(com.endava.cats.util.CatsUtil) ServiceCaller(com.endava.cats.io.ServiceCaller) TestCaseExporter(com.endava.cats.report.TestCaseExporter) BeforeEach(org.junit.jupiter.api.BeforeEach)

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