Search in sources :

Example 1 with CatsDSLParser

use of com.endava.cats.dsl.CatsDSLParser in project cats by Endava.

the class CatsUtilTest method shouldNotAddTopElement.

@Test
void shouldNotAddTopElement() {
    CatsUtil catsUtil = new CatsUtil(new CatsDSLParser());
    String payload = "{\"field\":\"value\", \"anotherField\":{\"subfield\": \"otherValue\"}}";
    Map<String, String> currentPathValues = Collections.singletonMap("additionalProperties", "{mapValues={test1=value1,test2=value2}}");
    String updatedPayload = catsUtil.setAdditionalPropertiesToPayload(currentPathValues, payload);
    Assertions.assertThat(updatedPayload).doesNotContain("metadata").contains("test1");
}
Also used : CatsDSLParser(com.endava.cats.dsl.CatsDSLParser) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CatsDSLParser

use of com.endava.cats.dsl.CatsDSLParser in project cats by Endava.

the class CatsUtilTest method shouldReturnEmptyFuzzingResultWhenEmptyJson.

@Test
void shouldReturnEmptyFuzzingResultWhenEmptyJson() {
    CatsUtil catsUtil = new CatsUtil(new CatsDSLParser());
    FuzzingStrategy strategy = FuzzingStrategy.replace().withData("fuzzed");
    FuzzingResult result = catsUtil.replaceField("", "test", strategy);
    Assertions.assertThat(result.getFuzzedValue()).isEmpty();
    Assertions.assertThat(result.getJson()).isEmpty();
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) FuzzingResult(com.endava.cats.model.FuzzingResult) CatsDSLParser(com.endava.cats.dsl.CatsDSLParser) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CatsDSLParser

use of com.endava.cats.dsl.CatsDSLParser 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 4 with CatsDSLParser

use of com.endava.cats.dsl.CatsDSLParser 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 5 with CatsDSLParser

use of com.endava.cats.dsl.CatsDSLParser in project cats by Endava.

the class CatsUtilTest method givenAPayloadAndAFuzzingStrategy_whenReplacingTheFuzzedValue_thenThePayloadIsProperlyFuzzed.

@ParameterizedTest
@CsvSource(value = { "{\"field\":\"value\", \"anotherField\":\"otherValue\"}|field", "{\"field\": 2, \"anotherField\":\"otherValue\"}|field", "[{\"field\": 2, \"anotherField\":\"otherValue\"},{\"field\": 2, \"anotherField\":\"otherValue\"}]|field", "{\"field\": {\"subField\":\"value\"}, \"anotherField\":\"otherValue\"}|field#subField", "{\"field\": [{\"subField\":\"value\"},{\"subField\":\"value\"}], \"anotherField\":\"otherValue\"}|field[*]#subField" }, delimiter = '|')
void givenAPayloadAndAFuzzingStrategy_whenReplacingTheFuzzedValue_thenThePayloadIsProperlyFuzzed(String json, String path) {
    CatsUtil catsUtil = new CatsUtil(new CatsDSLParser());
    FuzzingStrategy strategy = FuzzingStrategy.replace().withData("fuzzed");
    FuzzingResult result = catsUtil.replaceField(json, path, strategy);
    Assertions.assertThat(result.getFuzzedValue()).isEqualTo("fuzzed");
    Assertions.assertThat(result.getJson()).contains("fuzzed");
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) FuzzingResult(com.endava.cats.model.FuzzingResult) CatsDSLParser(com.endava.cats.dsl.CatsDSLParser) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CatsDSLParser (com.endava.cats.dsl.CatsDSLParser)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Test (org.junit.jupiter.api.Test)4 FilesArguments (com.endava.cats.args.FilesArguments)2 CustomFuzzerUtil (com.endava.cats.fuzzer.CustomFuzzerUtil)2 ServiceCaller (com.endava.cats.io.ServiceCaller)2 FuzzingResult (com.endava.cats.model.FuzzingResult)2 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)2 TestCaseExporter (com.endava.cats.report.TestCaseExporter)2 CatsUtil (com.endava.cats.util.CatsUtil)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Map (java.util.Map)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1