Skip to content

Commit

Permalink
fix: Fix issue with progress not being displayed when request payload…
Browse files Browse the repository at this point in the history
… contained many fields
  • Loading branch information
en-milie committed Jun 6, 2024
1 parent 67c1ead commit 04aaac4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/endava/cats/command/CatsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private void runFuzzers(List<FuzzingData> fuzzingDataListWithHttpMethodsFiltered
filteredData.forEach(data -> {
logger.start("Starting Fuzzer {}, http method {}, path {}", ansi().fgGreen().a(fuzzer.toString()).reset(), data.getMethod(), data.getPath());
logger.debug("Fuzzing payload: {}", data.getPayload());
testCaseListener.beforeFuzz(fuzzer.getClass());
testCaseListener.beforeFuzz(fuzzer.getClass(), data.getContractPath(), data.getMethod().name());
fuzzer.fuzz(data);
if (!(fuzzer instanceof FunctionalFuzzer)) {
testCaseListener.afterFuzz(data.getContractPath(), data.getMethod().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void run() {
.targetFields(fieldsToFuzz)
.build();

beforeFuzz();
beforeFuzz(fuzzingData.getContractPath(), fuzzingData.getMethod().name());
templateFuzzer.fuzz(fuzzingData);
afterFuzz(fuzzingData.getContractPath(), fuzzingData.getMethod().name());
} catch (IOException e) {
Expand Down Expand Up @@ -189,9 +189,9 @@ private void afterFuzz(String path, String method) {
testCaseListener.endSession();
}

private void beforeFuzz() throws IOException {
private void beforeFuzz(String path, String method) throws IOException {
testCaseListener.initReportingPath();
testCaseListener.beforeFuzz(templateFuzzer.getClass());
testCaseListener.beforeFuzz(templateFuzzer.getClass(), path, method);
}

private Set<CatsHeader> getHeaders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void executeCustomFuzzerTests() {
for (Map.Entry<String, Map<String, Object>> entry : filesArguments.getCustomFuzzerDetails().entrySet()) {
executions.stream().filter(customFuzzerExecution -> customFuzzerExecution.getFuzzingData().getContractPath().equalsIgnoreCase(entry.getKey()))
.forEach(customFuzzerExecution -> {
testCaseListener.beforeFuzz(this.getClass());
testCaseListener.beforeFuzz(this.getClass(), customFuzzerExecution.getFuzzingData().getContractPath(), customFuzzerExecution.getFuzzingData().getMethod().name());
customFuzzerUtil.executeTestCases(customFuzzerExecution.getFuzzingData(), customFuzzerExecution.getTestId(),
customFuzzerExecution.getTestEntry(), this);
testCaseListener.afterFuzz(customFuzzerExecution.getFuzzingData().getContractPath(), customFuzzerExecution.getFuzzingData().getMethod().name());
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/endava/cats/report/TestCaseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ private String getKeyDefault() {
*
* @param fuzzer the class representing the fuzzer
*/
public void beforeFuzz(Class<?> fuzzer) {
public void beforeFuzz(Class<?> fuzzer, String path, String method) {
String clazz = ConsoleUtils.removeTrimSanitize(fuzzer.getSimpleName()).replaceAll("[a-z]", "");
MDC.put(FUZZER, ConsoleUtils.centerWithAnsiColor(clazz, getKeyDefault().length(), Ansi.Color.MAGENTA));
MDC.put(FUZZER_KEY, ConsoleUtils.removeTrimSanitize(fuzzer.getSimpleName()));
this.notifySummaryObservers(path, method, 1);

}

/**
Expand Down Expand Up @@ -439,7 +441,7 @@ public void endSession() {
}

/**
* Renders a FUZZING header is logging is SUMMARY.
* Renders a FUZZING header if logging is SUMMARY.
*/
public void renderFuzzingHeader() {
if (reportingArguments.isSummaryInConsole()) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/endava/cats/command/CatsCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void givenContractAndServerParameter_whenStartingCats_thenParametersAreProcessed
Mockito.verify(testCaseListener, Mockito.times(1)).startSession();
Mockito.verify(testCaseListener, Mockito.times(1)).endSession();
Mockito.verify(testCaseListener, Mockito.times(20)).afterFuzz(Mockito.any(), Mockito.any());
Mockito.verify(testCaseListener, Mockito.times(10)).beforeFuzz(PathTagsLinterFuzzer.class);
Mockito.verify(testCaseListener, Mockito.times(10)).beforeFuzz(Mockito.eq(PathTagsLinterFuzzer.class), Mockito.any(), Mockito.any());

ReflectionTestUtils.setField(apiArguments, "contract", "empty");
ReflectionTestUtils.setField(apiArguments, "server", "empty");
Expand Down Expand Up @@ -170,8 +170,8 @@ void givenAnOpenApiContract_whenStartingCats_thenTheContractIsCorrectlyParsed()
Mockito.verify(fuzzingDataFactory).fromPathItem(Mockito.eq("/pet"), Mockito.any(), Mockito.any());
Mockito.verify(fuzzingDataFactory, Mockito.times(0)).fromPathItem(Mockito.eq("/petss"), Mockito.any(), Mockito.any());
Mockito.verify(testCaseListener, Mockito.times(13)).afterFuzz(Mockito.any(), Mockito.any());
Mockito.verify(testCaseListener, Mockito.times(9)).beforeFuzz(PathTagsLinterFuzzer.class);
Mockito.verify(testCaseListener, Mockito.times(4)).beforeFuzz(CheckDeletedResourcesNotAvailableFuzzer.class);
Mockito.verify(testCaseListener, Mockito.times(9)).beforeFuzz(Mockito.eq(PathTagsLinterFuzzer.class), Mockito.anyString(), Mockito.anyString());
Mockito.verify(testCaseListener, Mockito.times(4)).beforeFuzz(Mockito.eq(CheckDeletedResourcesNotAvailableFuzzer.class), Mockito.any(), Mockito.any());

ReflectionTestUtils.setField(apiArguments, "contract", "empty");
ReflectionTestUtils.setField(apiArguments, "server", "empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ void shouldReturnCurrentTestNumber() {

@Test
void shouldReturnCurrentFuzzer() {
testCaseListener.beforeFuzz(RandomResourcesFuzzer.class);
testCaseListener.beforeFuzz(RandomResourcesFuzzer.class, "test", "post");
String currentFuzzer = testCaseListener.getCurrentFuzzer();
Assertions.assertThat(currentFuzzer).isEqualTo("RandomResources");
}
Expand Down

0 comments on commit 04aaac4

Please sign in to comment.