Skip to content
/ cats Public
forked from Endava/cats

Commit f452404

Browse files
committed
Introduce a generic way to handle errors when communicating with the service endpoints
There was an inconsistency in the way Fuzzers were treating error cases. Some Fuzzers were ignoring RuntimeExceptions causing the entire run to fail, rather than an individual test case. This is now handled commonly in the TestCaseListener#createAndExecuteTest()
1 parent bbf9deb commit f452404

17 files changed

+186
-249
lines changed

CODE_OF_CONDUCT.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
## Our Standards
10+
11+
Examples of behavior that contributes to a positive environment for our community include:
12+
13+
* Demonstrating empathy and kindness toward other people
14+
* Being respectful of differing opinions, viewpoints, and experiences
15+
* Giving and gracefully accepting constructive feedback
16+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the overall community
18+
19+
Examples of unacceptable behavior include:
20+
21+
* The use of sexualized language or imagery, and sexual attention or
22+
advances of any kind
23+
* Trolling, insulting or derogatory comments, and personal or political attacks
24+
* Public or private harassment
25+
* Publishing others' private information, such as a physical or email
26+
address, without their explicit permission
27+
* Other conduct which could reasonably be considered inappropriate in a
28+
professional setting
29+
30+
## Enforcement Responsibilities
31+
32+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33+
34+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35+
36+
## Scope
37+
38+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39+
40+
## Enforcement
41+
42+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [[email protected]]([email protected]). All complaints will be reviewed and investigated promptly and fairly.
43+
44+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45+
46+
## Enforcement Guidelines
47+
48+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49+
50+
### 1. Correction
51+
52+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53+
54+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55+
56+
### 2. Warning
57+
58+
**Community Impact**: A violation through a single incident or series of actions.
59+
60+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61+
62+
### 3. Temporary Ban
63+
64+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65+
66+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67+
68+
### 4. Permanent Ban
69+
70+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71+
72+
**Consequence**: A permanent ban from any sort of public interaction within the community.
73+
74+
## Attribution
75+
76+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78+
79+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80+
81+
[homepage]: https://www.contributor-covenant.org
82+
83+
For answers to common questions about this code of conduct, see the FAQ at
84+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

CONTRIBUTING.md

+1-82
Original file line numberDiff line numberDiff line change
@@ -67,85 +67,4 @@ This document was adapted from the open-source contribution guidelines for [Face
6767

6868
# Code of Conduct
6969

70-
## Our Pledge
71-
72-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
73-
74-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
75-
76-
## Our Standards
77-
78-
Examples of behavior that contributes to a positive environment for our community include:
79-
80-
* Demonstrating empathy and kindness toward other people
81-
* Being respectful of differing opinions, viewpoints, and experiences
82-
* Giving and gracefully accepting constructive feedback
83-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
84-
* Focusing on what is best not just for us as individuals, but for the overall community
85-
86-
Examples of unacceptable behavior include:
87-
88-
* The use of sexualized language or imagery, and sexual attention or
89-
advances of any kind
90-
* Trolling, insulting or derogatory comments, and personal or political attacks
91-
* Public or private harassment
92-
* Publishing others' private information, such as a physical or email
93-
address, without their explicit permission
94-
* Other conduct which could reasonably be considered inappropriate in a
95-
professional setting
96-
97-
## Enforcement Responsibilities
98-
99-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
100-
101-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
102-
103-
## Scope
104-
105-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
106-
107-
## Enforcement
108-
109-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [[email protected]]([email protected]). All complaints will be reviewed and investigated promptly and fairly.
110-
111-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
112-
113-
## Enforcement Guidelines
114-
115-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
116-
117-
### 1. Correction
118-
119-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
120-
121-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
122-
123-
### 2. Warning
124-
125-
**Community Impact**: A violation through a single incident or series of actions.
126-
127-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
128-
129-
### 3. Temporary Ban
130-
131-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
132-
133-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
134-
135-
### 4. Permanent Ban
136-
137-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
138-
139-
**Consequence**: A permanent ban from any sort of public interaction within the community.
140-
141-
## Attribution
142-
143-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
144-
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
145-
146-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
147-
148-
[homepage]: https://www.contributor-covenant.org
149-
150-
For answers to common questions about this code of conduct, see the FAQ at
151-
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
70+
Please refer to [Code of Conduct](CODE_OF_CONDUCT.md)

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ The following logging levels are used (in both the console and the test report)
1616
- `WARN` will report normal but undocumented behaviour or some misalignment between the contract and the service. This will **ideally** be actioned.
1717
- `ERROR` will report abnormal/unexpected behaviour. This **must** be actioned.
1818

19+
20+
# How the Fuzzing works
21+
CATS will iterate through all endpoints, all HTTP methods and all the associated requests bodies and parameters and `fuzz` their data models fields values according to their defined data type and constraints. The actual fuzzing depends on the specific `Fuzzer` executed. Please see the list of fuzzers and their behaviour.
22+
There are also differences on how the fuzzing works depending on the HTTP method:
23+
24+
- for methods with request bodies like POST, PUT the fuzzing will be applied at the request body data models level
25+
- for methods without request bodies like GET, DELETE the fuzzing will be applied at the URL parameters level
26+
27+
This means that for methods with request bodies you need to supply the `path` parameters via `urlParams` or the `referenceData` file as failure to do so will result in `Illegal character in path at index ...` errors.
28+
29+
1930
# Build
2031

2132
You can use the following Maven command to build the project:

src/main/java/com/endava/cats/fuzzer/HappyFuzzer.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,15 @@ public HappyFuzzer(ServiceCaller sc, TestCaseListener lr) {
2828
}
2929

3030
public void fuzz(FuzzingData data) {
31-
testCaseListener.createAndExecuteTest(() ->
32-
process(data)
33-
);
31+
testCaseListener.createAndExecuteTest(LOGGER, this, () -> process(data));
3432
}
3533

3634
private void process(FuzzingData data) {
37-
try {
38-
testCaseListener.addScenario(LOGGER, "Scenario: send a 'happy' flow request will all fields and all headers in");
39-
testCaseListener.addExpectedResult(LOGGER, "Expected result: should get a 2XX response code");
40-
CatsResponse response = serviceCaller.call(data.getMethod(), ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(data.getPayload()).build());
41-
42-
testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.TWOXX);
43-
} catch (Exception e) {
44-
testCaseListener.reportError(LOGGER, "Fuzzer [{}] failed due to [{}]", this.getClass().getSimpleName(), e.getMessage());
45-
}
35+
testCaseListener.addScenario(LOGGER, "Scenario: send a 'happy' flow request will all fields and all headers in");
36+
testCaseListener.addExpectedResult(LOGGER, "Expected result: should get a 2XX response code");
37+
CatsResponse response = serviceCaller.call(data.getMethod(), ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(data.getPayload()).build());
38+
39+
testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.TWOXX);
4640
}
4741

4842
public String toString() {

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

+9-14
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public void fuzz(FuzzingData data) {
4040
logger.info("All fields {}", data.getAllFieldsAsSingleSet());
4141

4242
for (String fuzzedField : data.getAllFieldsAsSingleSet()) {
43-
testCaseListener.createAndExecuteTest(() ->
44-
process(data, fuzzedField)
45-
);
43+
testCaseListener.createAndExecuteTest(logger, this, () -> process(data, fuzzedField));
4644
}
4745
}
4846

@@ -58,19 +56,16 @@ protected void process(FuzzingData data, String fuzzedField) {
5856
FuzzingResult fuzzingResult = catsUtil.replaceFieldWithFuzzedValue(data.getPayload(), fuzzedField, fuzzingStrategy);
5957
boolean isFuzzedValueMatchingPattern = this.isFuzzedValueMatchingPattern(fuzzingResult.getFuzzedValue(), data, fuzzedField);
6058

61-
try {
62-
ServiceData serviceData = ServiceData.builder().relativePath(data.getPath())
63-
.headers(data.getHeaders()).payload(fuzzingResult.getJson().toString())
64-
.fuzzedField(fuzzedField).build();
65-
CatsResponse response = serviceCaller.call(data.getMethod(), serviceData);
6659

67-
ResponseCodeFamily expectedResponseCodeBasedOnConstraints = this.getExpectedResponseCodeBasedOnConstraints(isFuzzedValueMatchingPattern, fuzzingConstraints);
60+
ServiceData serviceData = ServiceData.builder().relativePath(data.getPath())
61+
.headers(data.getHeaders()).payload(fuzzingResult.getJson().toString())
62+
.fuzzedField(fuzzedField).build();
63+
CatsResponse response = serviceCaller.call(data.getMethod(), serviceData);
6864

69-
testCaseListener.addExpectedResult(logger, "Expected result: should return [{}]", expectedResponseCodeBasedOnConstraints.asString());
70-
testCaseListener.reportResult(logger, data, response, expectedResponseCodeBasedOnConstraints);
71-
} catch (Exception e) {
72-
testCaseListener.reportError(logger, "Fuzzer [{}] failed due to [{}]", this.getClass().getSimpleName(), e.getMessage());
73-
}
65+
ResponseCodeFamily expectedResponseCodeBasedOnConstraints = this.getExpectedResponseCodeBasedOnConstraints(isFuzzedValueMatchingPattern, fuzzingConstraints);
66+
67+
testCaseListener.addExpectedResult(logger, "Expected result: should return [{}]", expectedResponseCodeBasedOnConstraints.asString());
68+
testCaseListener.reportResult(logger, data, response, expectedResponseCodeBasedOnConstraints);
7469
} else {
7570
FuzzingStrategy strategy = this.createSkipStrategy(fuzzingStrategy);
7671
testCaseListener.skipTest(logger, strategy.process(""));

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

+8-13
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ protected void processCustomFuzzerFile(FuzzingData data) {
6161

6262
private void executeTestCases(FuzzingData data, String key, Object value) {
6363
LOGGER.info("Path [{}] has the following custom data [{}]", data.getPath(), value);
64-
if (this.entryIsValid((Map<String, Object>) value)) {
6564

65+
if (this.entryIsValid((Map<String, Object>) value)) {
6666
List<Map<String, String>> individualTestCases = this.createIndividualRequest((Map<String, Object>) value);
6767
for (Map<String, String> individualTestCase : individualTestCases) {
68-
testCaseListener.createAndExecuteTest(() -> process(data, key, individualTestCase));
68+
testCaseListener.createAndExecuteTest(LOGGER, this, () -> process(data, key, individualTestCase));
6969
}
7070
} else {
7171
LOGGER.warn("Skipping path [{}] as not valid. It either doesn't contain a valid expectedResponseCode or there is more than one list of values for a specific field", data.getPath());
@@ -74,18 +74,13 @@ private void executeTestCases(FuzzingData data, String key, Object value) {
7474

7575
private void process(FuzzingData data, String testName, Map<String, String> currentPathValues) {
7676
testCaseListener.addScenario(LOGGER, "Scenario: send request with custom values supplied. Test key [{}]", testName);
77-
try {
78-
String expectedResponseCode = String.valueOf(currentPathValues.get(EXPECTED_RESPONSE_CODE));
79-
testCaseListener.addExpectedResult(LOGGER, "Expected result: should return [{}]", expectedResponseCode);
77+
String expectedResponseCode = String.valueOf(currentPathValues.get(EXPECTED_RESPONSE_CODE));
78+
testCaseListener.addExpectedResult(LOGGER, "Expected result: should return [{}]", expectedResponseCode);
8079

81-
String payloadWithCustomValuesReplaced = this.getStringWithCustomValuesFromFile(data, currentPathValues);
82-
CatsResponse response = serviceCaller.call(data.getMethod(), ServiceData.builder().relativePath(data.getPath()).replaceRefData(false)
83-
.headers(data.getHeaders()).payload(payloadWithCustomValuesReplaced).build());
84-
testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.from(expectedResponseCode));
85-
86-
} catch (Exception e) {
87-
testCaseListener.reportError(LOGGER, "Fuzzer [{}] failed due to [{}]", this.getClass().getSimpleName(), e.getMessage());
88-
}
80+
String payloadWithCustomValuesReplaced = this.getStringWithCustomValuesFromFile(data, currentPathValues);
81+
CatsResponse response = serviceCaller.call(data.getMethod(), ServiceData.builder().relativePath(data.getPath()).replaceRefData(false)
82+
.headers(data.getHeaders()).payload(payloadWithCustomValuesReplaced).build());
83+
testCaseListener.reportResult(LOGGER, data, response, ResponseCodeFamily.from(expectedResponseCode));
8984
}
9085

9186
private String getStringWithCustomValuesFromFile(FuzzingData data, Map<String, String> currentPathValues) {

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public NewFieldsFuzzer(ServiceCaller sc, TestCaseListener lr, CatsUtil cu) {
3535

3636
@Override
3737
public void fuzz(FuzzingData data) {
38-
testCaseListener.createAndExecuteTest(() ->
39-
process(data)
40-
);
38+
testCaseListener.createAndExecuteTest(LOGGER, this, () -> process(data));
4139
}
4240

4341
private void process(FuzzingData data) {

0 commit comments

Comments
 (0)