Search in sources :

Example 51 with FuzzingStrategy

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

the class ReplaceFuzzingStrategyTest method givenAString_whenUsingTheReplaceFuzzingStrategy_thenTheStringIsCorrectlyProcessed.

@Test
void givenAString_whenUsingTheReplaceFuzzingStrategy_thenTheStringIsCorrectlyProcessed() {
    FuzzingStrategy strategy = FuzzingStrategy.replace().withData("inner");
    Assertions.assertThat(strategy.process("string")).isEqualTo("inner");
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 52 with FuzzingStrategy

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

the class SkipFuzzingStrategyTest method givenAString_whenUsingTheSkipFuzzingStrategy_thenTheStringIsCorrectlyProcessed.

@Test
void givenAString_whenUsingTheSkipFuzzingStrategy_thenTheStringIsCorrectlyProcessed() {
    FuzzingStrategy strategy = FuzzingStrategy.skip().withData("inner");
    Assertions.assertThat(strategy.process("string")).isEqualTo("inner");
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 53 with FuzzingStrategy

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

the class TrailFuzzingStrategyTest method givenAString_whenUsingTheTrailFuzzingStrategy_thenTheStringIsCorrectlyProcessed.

@Test
void givenAString_whenUsingTheTrailFuzzingStrategy_thenTheStringIsCorrectlyProcessed() {
    FuzzingStrategy strategy = FuzzingStrategy.trail().withData("inner");
    Assertions.assertThat(strategy.process("string")).isEqualTo("stringinner");
}
Also used : FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 54 with FuzzingStrategy

use of com.endava.cats.model.FuzzingStrategy 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)

Example 55 with FuzzingStrategy

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

the class WithinControlCharsInFieldsSanitizeValidateFuzzerTest method shouldProperlyOverrideSuperClassMethods.

@Test
void shouldProperlyOverrideSuperClassMethods() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Map<String, Schema> reqTypes = new HashMap<>();
    reqTypes.put("field", new StringSchema());
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(reqTypes);
    FuzzingStrategy fuzzingStrategy = withinControlCharsInFieldsSanitizeValidateFuzzer.getFieldFuzzingStrategy(data, "field").get(1);
    Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(fuzzingStrategy.getData()).contains("\u0007");
    Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.TWOXX);
    Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.description()).isNotNull();
    Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());
    Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
}
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)

Aggregations

FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)67 QuarkusTest (io.quarkus.test.junit.QuarkusTest)62 Test (org.junit.jupiter.api.Test)62 FuzzingData (com.endava.cats.model.FuzzingData)35 StringSchema (io.swagger.v3.oas.models.media.StringSchema)34 Schema (io.swagger.v3.oas.models.media.Schema)30 HashMap (java.util.HashMap)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)4 CatsDSLParser (com.endava.cats.dsl.CatsDSLParser)3 FuzzingResult (com.endava.cats.model.FuzzingResult)3 CatsHeader (com.endava.cats.model.CatsHeader)2 CatsResponse (com.endava.cats.model.CatsResponse)2 DryRun (com.endava.cats.annotations.DryRun)1 ApiArguments (com.endava.cats.args.ApiArguments)1 AuthArguments (com.endava.cats.args.AuthArguments)1 FilesArguments (com.endava.cats.args.FilesArguments)1 ProcessingArguments (com.endava.cats.args.ProcessingArguments)1 CatsDSLWords (com.endava.cats.dsl.CatsDSLWords)1 ADDITIONAL_PROPERTIES (com.endava.cats.dsl.CatsDSLWords.ADDITIONAL_PROPERTIES)1