Skip to content

Commit 69839cd

Browse files
committed
feat: Add --positiveOnly and --negativeOnly argument to run only positive or negative scenarios only across all fuzzers
1 parent f481165 commit 69839cd

File tree

56 files changed

+513
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+513
-279
lines changed

src/main/java/com/endava/cats/args/FilterArguments.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ enum FormatType {
186186
description = "Path to custom profile configuration file (YAML)")
187187
private Path customProfileFile;
188188

189+
@CommandLine.Option(
190+
names = {"--negativeOnly"},
191+
description = "Run only fuzzers that expect 4XX responses (validation and error testing scenarios). " +
192+
"This includes fuzzers testing required fields, invalid values, authentication, etc. " +
193+
"Excludes happy path fuzzers and linters.")
194+
@Getter
195+
private boolean only4xxFuzzers;
196+
197+
@CommandLine.Option(
198+
names = {"--positiveOnly"},
199+
description = "Run only fuzzers that expect 2XX responses (happy path and valid data scenarios). " +
200+
"This includes happy path fuzzers, valid examples, and default values. " +
201+
"Excludes validation error fuzzers and linters.")
202+
@Getter
203+
private boolean only2xxFuzzers;
204+
189205
@Setter
190206
private TotalCountType totalCountType = TotalCountType.FUZZERS;
191207

src/main/java/com/endava/cats/fuzzer/executor/FieldsIteratorExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ private void executeTestCase(FieldsIteratorExecutorContext context, String fuzze
108108
testCaseListener.addExpectedResult(context.getLogger(), "Should return [{}]",
109109
context.getExpectedResponseCode() != null ? context.getExpectedResponseCode().asString() : "a response that doesn't match" + matchArguments.getMatchString());
110110

111+
if (!testCaseListener.shouldContinueExecution(context.getLogger(), context.getExpectedResponseCode())) {
112+
testCaseListener.skipTest(context.getLogger(), "Test skipped due to response code filtering");
113+
return;
114+
}
115+
111116
FuzzingResult fuzzingResult = this.getFuzzingResult(context, fuzzedField, strategy);
112117

113118
CatsResponse response = serviceCaller.call(

src/main/java/com/endava/cats/fuzzer/executor/HeadersIteratorExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public void execute(HeadersIteratorExecutorContext context) {
7070
testCaseListener.addExpectedResult(context.getLogger(), "Should return [{}]",
7171
expectedResponseCode != null ? expectedResponseCode.asString() : "a response that doesn't match" + matchArguments.getMatchString());
7272

73+
if (!testCaseListener.shouldContinueExecution(context.getLogger(), expectedResponseCode)) {
74+
testCaseListener.skipTest(context.getLogger(), "Test skipped due to response code filtering");
75+
return;
76+
}
77+
7378
ServiceData serviceData = ServiceData.builder()
7479
.relativePath(context.getFuzzingData().getPath())
7580
.contractPath(context.getFuzzingData().getContractPath())

src/main/java/com/endava/cats/fuzzer/executor/SimpleExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public void execute(SimpleExecutorContext context) {
5656
testCaseListener.addScenario(context.getLogger(), context.getScenario());
5757
testCaseListener.addExpectedResult(context.getLogger(), "Should return {}" + context.getExpectedResult(), context.getExpectedSpecificResponseCode());
5858

59+
if (!testCaseListener.shouldContinueExecution(context.getLogger(), context.getExpectedResponseCode())) {
60+
testCaseListener.skipTest(context.getLogger(), "Test skipped due to response code filtering");
61+
return;
62+
}
63+
5964
CatsResponse response = serviceCaller.call(
6065
ServiceData.builder()
6166
.relativePath(context.getPath())

src/main/java/com/endava/cats/fuzzer/fields/DuplicateKeysFieldsFuzzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ private void runDuplicationTestCase(FuzzingData data, String field, String dupli
121121
testCaseListener.addExpectedResult(logger,
122122
"Service should return a [{}] response", ResponseCodeFamilyPredefined.FOURXX.asString());
123123

124+
if (!testCaseListener.shouldContinueExecution(logger, ResponseCodeFamilyPredefined.FOURXX)) {
125+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
126+
return;
127+
}
128+
124129
CatsResponse response = serviceCaller.call(buildServiceData(data, duplicatedPayload));
125130
testCaseListener.reportResult(logger, data, response, ResponseCodeFamilyPredefined.FOURXX);
126131
}

src/main/java/com/endava/cats/fuzzer/fields/InsertWhitespacesInFieldNamesFieldFuzzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ private void process(FuzzingData data, String field, String randomWhitespace) {
5959
testCaseListener.addScenario(logger, "Insert random whitespaces in the field name [{}]", field);
6060
testCaseListener.addExpectedResult(logger, "Should get a [{}] response code", ResponseCodeFamilyPredefined.FOURXX);
6161

62+
if (!testCaseListener.shouldContinueExecution(logger, ResponseCodeFamilyPredefined.FOURXX)) {
63+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
64+
return;
65+
}
66+
6267
String fuzzedJson = JsonUtils.insertCharactersInFieldKey(data.getPayload(), field, randomWhitespace);
6368

6469
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders())

src/main/java/com/endava/cats/fuzzer/fields/NewFieldsFuzzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ private void process(FuzzingData data) {
6262
testCaseListener.addScenario(logger, "Add new field inside the request: name [{}], value [{}]. All other details are similar to a happy flow", NEW_FIELD, NEW_FIELD);
6363
testCaseListener.addExpectedResult(logger, "Should get a [{}] response code", expectedResultCode.asString());
6464

65+
if (!testCaseListener.shouldContinueExecution(logger, expectedResultCode)) {
66+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
67+
return;
68+
}
69+
6570
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders())
6671
.payload(fuzzedJson).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).contractPath(data.getContractPath())
6772
.contentType(data.getFirstRequestContentType()).pathParamsPayload(data.getPathParamsPayload())

src/main/java/com/endava/cats/fuzzer/fields/RemoveFieldsFuzzer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.endava.cats.args.ProcessingArguments;
66
import com.endava.cats.fuzzer.api.Fuzzer;
77
import com.endava.cats.http.HttpMethod;
8+
import com.endava.cats.http.ResponseCodeFamily;
89
import com.endava.cats.http.ResponseCodeFamilyPredefined;
910
import com.endava.cats.io.ServiceCaller;
1011
import com.endava.cats.io.ServiceData;
@@ -89,8 +90,14 @@ private void process(FuzzingData data, List<String> required, Set<String> subset
8990
testCaseListener.addScenario(logger, "Remove the following fields from request: {}", subset);
9091

9192
boolean hasRequiredFieldsRemove = this.hasRequiredFieldsRemove(required, subset);
93+
ResponseCodeFamily expectedResponseCode = ResponseCodeFamilyPredefined.getResultCodeBasedOnRequiredFieldsRemoved(hasRequiredFieldsRemove);
9294
testCaseListener.addExpectedResult(logger, "Should return [{}] response code as required fields [{}] removed", ResponseCodeFamilyPredefined.getExpectedWordingBasedOnRequiredFields(hasRequiredFieldsRemove));
9395

96+
if (!testCaseListener.shouldContinueExecution(logger, expectedResponseCode)) {
97+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
98+
return;
99+
}
100+
94101
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders())
95102
.payload(finalJsonPayload).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).contractPath(data.getContractPath())
96103
.contentType(data.getFirstRequestContentType()).pathParamsPayload(data.getPathParamsPayload()).build());

src/main/java/com/endava/cats/fuzzer/fields/ZeroWidthCharsInNamesFieldsFuzzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ private void process(FuzzingData data, String fuzzedField, String fuzzValue) {
6464
fuzzedField, FuzzingStrategy.formatValue(fuzzValue));
6565
testCaseListener.addExpectedResult(logger, "Should get a [{}] response code", ResponseCodeFamilyPredefined.FOURXX.asString());
6666

67+
if (!testCaseListener.shouldContinueExecution(logger, ResponseCodeFamilyPredefined.FOURXX)) {
68+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
69+
return;
70+
}
71+
6772
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders())
6873
.payload(fuzzedPayload).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).contractPath(data.getContractPath())
6974
.contentType(data.getFirstRequestContentType()).pathParamsPayload(data.getPathParamsPayload())

src/main/java/com/endava/cats/fuzzer/fields/base/BaseFieldsFuzzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ protected void process(FuzzingData data, String fuzzedField, FuzzingStrategy fuz
110110

111111
testCaseListener.addExpectedResult(logger, "Should return [{}]", expectedResponseCodeBasedOnConstraints.asString());
112112

113+
if (!testCaseListener.shouldContinueExecution(logger, expectedResponseCodeBasedOnConstraints)) {
114+
testCaseListener.skipTest(logger, "Test skipped due to response code filtering");
115+
return;
116+
}
117+
113118
CatsResponse response = serviceCaller.call(serviceData);
114119

115120
testCaseListener.reportResult(logger, data, response, expectedResponseCodeBasedOnConstraints, this.shouldMatchResponseSchema(data), this.shouldMatchContentType(data));

0 commit comments

Comments
 (0)