Skip to content

Commit

Permalink
Make XXXOnlyFuzzers run for DELETE and GET
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed May 24, 2022
1 parent f714688 commit be7ac26
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.endava.cats.args.FilesArguments;
import com.endava.cats.args.IgnoreArguments;
import com.endava.cats.fuzzer.fields.base.Expect4XXForRequiredBaseFieldsFuzzer;
import com.endava.cats.http.HttpMethod;
import com.endava.cats.http.ResponseCodeFamily;
import com.endava.cats.io.ServiceCaller;
import com.endava.cats.model.FuzzingData;
Expand All @@ -12,7 +11,6 @@
import com.endava.cats.report.TestCaseListener;
import com.endava.cats.util.CatsUtil;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -37,11 +35,6 @@ public ResponseCodeFamily getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()
return ResponseCodeFamily.FOURXX;
}

@Override
public List<HttpMethod> skipForHttpMethods() {
return Arrays.asList(HttpMethod.GET, HttpMethod.DELETE);
}

/**
* Supplied skipped fields are skipped when we only sent invalid data.
*
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/endava/cats/model/util/PayloadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class PayloadUtils {

Expand All @@ -27,13 +29,8 @@ public abstract class PayloadUtils {
"\u0016", "\u0017", "\u0018", "\u0019", "\u001A", "\u001B", "\u001C", "\u001D", "\u001E", "\u001F", "\u007F", "\u0080", "\u0081",
"\u0082", "\u0083", "\u0085", "\u0086", "\u0087", "\u0088", "\u008A", "\u008B", "\u008C", "\u008D", "\u0090", "\u0091", "\u0093",
"\u0094", "\u0095", "\u0096", "\u0097", "\u0098", "\u0099", "\u009A", "\u009B", "\u009C", "\u009D", "\u009E", "\u009F", "\uFEFF", "\uFFFE", "\u00AD");
private static final List<String> controlCharsFields = Arrays.asList(
"\r\n", "\u0007", "\u0008", "\u0009", "\n", "\u000B", "\u000C", "\r", "\u200B", "\u200C", "\u200D", "\u200E",
"\u200F", "\u202A", "\u202B", "\u202C", "\u202D", "\u202E", "\u2060", "\u2061", "\u2062", "\u2063", "\u2064", "\u206D",
"\u0015", "\u0016", "\u0017", "\u0018", "\u0019", "\u001A", "\u001B", "\u001C", "\u001D", "\u001E", "\u001F", "\u007F",
"\u0080", "\u0081", "\u0082", "\u0083", "\u0085", "\u0086", "\u0087", "\u0088", "\u008A", "\u008B", "\u008C", "\u008D",
"\u0090", "\u0091", "\u0093", "\u0094", "\u0095", "\u0096", "\u0097", "\u0098", "\u0099", "\u009A", "\u009B", "\u009C",
"\u009D", "\u009E", "\u009F", "\uFEFF", "\uFFFE", "\u00AD");
private static final List<String> controlCharsFields = Stream.concat(controlCharsHeaders.stream(), Stream.of("\u0009")).collect(Collectors.toList());

private static final String BAD_PAYLOAD = "퀜\uD80C\uDE1B\uD859\uDCBC\uD872\uDC4F璫骋\uD85B\uDC0F\uD842\uDF46\uD85D\uDC7C\uD85C\uDC71\uD884\uDC2E\uD854\uDCA4\uD861\uDE98\uD85E\uDCD4\uD86F\uDC65\uD849\uDC0D" +
"\uD863\uDE3B\uD869\uDD16\uD83A\uDD20૰촩\uD84F\uDF32\uD86F\uDEFA\uD842\uDEB0ў璵\uD854\uDF4F\uD85A\uDC86\uD861\uDECC帩쫲\uD822\uDFAC\uD876\uDC73\uD85D\uDEB9\uD86B\uDC4C旳ᥛ\uD852\uDCD0ࣝ" +
"\uD863\uDF3A\uD850\uDD22\uD878\uDC82哐꿥㾁纬\uD875\uDC5F\uD879\uDD17\uD872\uDCBB\uD83E\uDDE0\uD866\uDC00\uD804\uDC69\uD884\uDD1E\uD84F\uDED9\uD841\uDCFE\uD880\uDF5B\uD82C\uDD0A㊟韻悈씜\uD860" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private FuzzingData setContext(String fuzzerFile, String responsePayload) throws
person.setProperties(properties);
FuzzingData data = FuzzingData.builder().path("/pets/{id}/move").payload("{'name':'oldValue', 'firstName':'John','lastName':'Cats','email':'john@yahoo.com'}").
responses(responses).responseCodes(Collections.singleton("200")).method(HttpMethod.POST).reqSchema(person).headers(new HashSet<>())
.requestContentTypes(List.of("application/json")).build();
.requestContentTypes(List.of("application/json")).requestPropertyTypes(properties).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setup() {
@Test
void givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheTabsOnlyInFieldsTrimValidateFuzzer() {
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.skipForHttpMethods()).isEmpty();

FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> schemaMap = new HashMap<>();
Expand All @@ -55,14 +55,14 @@ void givenANewTabsOnlyInFieldsTrimValidateFuzzer_whenCreatingANewInstance_thenTh

FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0000");

stringSchema.setMinLength(5);

fuzzingStrategy = onlyControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);

Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat("\u0007", stringSchema.getMinLength() + 1));
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat("\u0000", stringSchema.getMinLength() + 1));
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.description()).isNotNull();
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlyControlCharsInFieldsTrimValidateFuzzer.getInvisibleChars()).contains("\t");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void setup() {
void shouldOverrideDefaultMethods() {
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.skipForHttpMethods()).isEmpty();
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlyControlCharsInFieldsValidateTrimFuzzer.getInvisibleChars()).contains("\t");
Expand All @@ -60,7 +60,7 @@ void shouldReturnProperLengthWhenNoMinLLength() {

FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0000");
}

@Test
Expand All @@ -75,7 +75,7 @@ void shouldReturnProperLengthWhenMinValue() {

FuzzingStrategy fuzzingStrategy = onlyControlCharsInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(data, "schema").get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat("\u0007", stringSchema.getMinLength() + 1));
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo(StringUtils.repeat("\u0000", stringSchema.getMinLength() + 1));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void setup() {
@Test
void shouldProperlyOverrideMethods() {
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsTrimValidateFuzzer.skipForHttpMethods()).isEmpty();

FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> schemaMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void setup() {
void shouldOverrideDefaultMethods() {
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.skipForHttpMethods()).isEmpty();
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlyMultiCodePointEmojisInFieldsValidateTrimFuzzer.getInvisibleChars()).contains("\uD83D\uDC69\uD83C\uDFFE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void setup() {
@Test
void shouldProperlyOverrideMethods() {
Assertions.assertThat(onlySingleCodePointEmojisInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlySingleCodePointEmojisInFieldsTrimValidateFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlySingleCodePointEmojisInFieldsTrimValidateFuzzer.skipForHttpMethods()).isEmpty();

FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> schemaMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void setup() {
void shouldOverrideDefaultMethods() {
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.skipForHttpMethods()).isEmpty();
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.description()).isNotNull();
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlySingleCodePointEmojisInFieldsValidateTrimFuzzer.getInvisibleChars()).contains("\uD83D\uDC7E");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void shouldProperlyOverrideMethods() {
Assertions.assertThat(onlyWhitespacesInFieldsTrimValidateFuzzer.description()).isNotNull();
Assertions.assertThat(onlyWhitespacesInFieldsTrimValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(onlyWhitespacesInFieldsTrimValidateFuzzer.getInvisibleChars()).contains(" ");
Assertions.assertThat(onlyWhitespacesInFieldsTrimValidateFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyWhitespacesInFieldsTrimValidateFuzzer.skipForHttpMethods()).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void setup() {
@Test
void givenANewSpacesOnlyInFieldsValidateTrimFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheSpacesOnlyInFieldsValidateTrimFuzzer() {
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.skipForHttpMethods()).containsExactly(HttpMethod.GET, HttpMethod.DELETE);
Assertions.assertThat(onlyWhitespacesInFieldsValidateTrimFuzzer.skipForHttpMethods()).isEmpty();

FuzzingData data = Mockito.mock(FuzzingData.class);
Map<String, Schema> schemaMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void givenANewTrailingTabsInFieldsTrimValidateFuzzer_whenCreatingANewInstance_th
FuzzingStrategy fuzzingStrategy = trailingControlCharsInFieldsTrimValidateFuzzer.getFieldFuzzingStrategy(null, null).get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.trail().name());

Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0000");
Assertions.assertThat(trailingControlCharsInFieldsTrimValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(trailingControlCharsInFieldsTrimValidateFuzzer.description()).isNotNull();
Assertions.assertThat(trailingControlCharsInFieldsTrimValidateFuzzer.typeOfDataSentToTheService()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void givenANewTrailingTabsInFieldsValidateTrimFuzzer_whenCreatingANewInstance_th
FuzzingStrategy fuzzingStrategy = trailingControlCharsInFieldsValidateTrimFuzzer.getFieldFuzzingStrategy(null, null).get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.trail().name());

Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0007");
Assertions.assertThat(fuzzingStrategy.getData()).isEqualTo("\u0000");
Assertions.assertThat(trailingControlCharsInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(trailingControlCharsInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(trailingControlCharsInFieldsValidateTrimFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void shouldProperlyOverrideSuperClassMethods() {
FuzzingStrategy fuzzingStrategy = withinControlCharsInFieldsSanitizeValidateFuzzer.getFieldFuzzingStrategy(data, "field").get(1);
Assertions.assertThat(fuzzingStrategy.name()).isEqualTo(FuzzingStrategy.replace().name());

Assertions.assertThat(fuzzingStrategy.getData().toString()).contains("\u0007");
Assertions.assertThat(fuzzingStrategy.getData().toString()).contains("\u0000");
Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.description()).isNotNull();
Assertions.assertThat(withinControlCharsInFieldsSanitizeValidateFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ void shouldProperlyOverrideSuperClassMethods() {
Mockito.when(data.getRequestPropertyTypes()).thenReturn(reqTypes);
FuzzingStrategy fuzzingStrategy = controlCharsWithinFieldsValidateSanitizeFuzzer.getFieldFuzzingStrategy(data, "field").get(1);

Assertions.assertThat(fuzzingStrategy.getData().toString()).contains("\u0007");
Assertions.assertThat(fuzzingStrategy.getData().toString()).contains("\u0000");
Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.getExpectedHttpCodeWhenFuzzedValueNotMatchesPattern()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);
Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualTo(ResponseCodeFamily.FOURXX);

Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.description()).isNotNull();
Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.typeOfDataSentToTheService()).isNotNull();
Assertions.assertThat(controlCharsWithinFieldsValidateSanitizeFuzzer.concreteFuzzStrategy().name()).isEqualTo(FuzzingStrategy.replace().name());

}

@Test
Expand Down

0 comments on commit be7ac26

Please sign in to comment.