Skip to content

Commit

Permalink
fix: Fix for #140 NPE when running cats fuzz sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Sep 27, 2024
1 parent 0fb862b commit 6e84eac
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/com/endava/cats/command/TemplateFuzzCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import com.endava.cats.args.AuthArguments;
import com.endava.cats.args.IgnoreArguments;
import com.endava.cats.args.MatchArguments;
import com.endava.cats.args.ProcessingArguments;
import com.endava.cats.args.ReportingArguments;
import com.endava.cats.args.UserArguments;
import com.endava.cats.context.CatsConfiguration;
import com.endava.cats.context.CatsGlobalContext;
import com.endava.cats.dsl.CatsDSLParser;
import com.endava.cats.fuzzer.special.TemplateFuzzer;
import com.endava.cats.http.HttpMethod;
Expand All @@ -19,6 +22,8 @@
import io.github.ludovicianul.prettylogger.PrettyLogger;
import io.github.ludovicianul.prettylogger.PrettyLoggerFactory;
import io.quarkus.arc.Unremovable;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import jakarta.inject.Inject;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -29,7 +34,9 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -106,6 +113,9 @@ public class TemplateFuzzCommand implements Runnable {
@Inject
TestCaseListener testCaseListener;

@Inject
CatsGlobalContext catsGlobalContext;

@Getter
@ConfigProperty(name = "quarkus.application.version", defaultValue = "1.0.0")
String appVersion;
Expand All @@ -126,6 +136,8 @@ public class TemplateFuzzCommand implements Runnable {
@CommandLine.Option(names = {"--targetFields", "-t"},
description = "A comma separated list of fully qualified request fields, HTTP headers, path and/or query parameters that the Fuzzers will apply to", split = ",")
Set<String> targetFields;
@Inject
ProcessingArguments processingArguments;

@Override
public void run() {
Expand Down Expand Up @@ -157,6 +169,12 @@ private void init() {
ConsoleUtils.initTerminalWidth(spec);
validateRequiredFields();
testCaseListener.renderFuzzingHeader();
initCatsGlobalContext();
}

private void initCatsGlobalContext() {
CatsConfiguration catsConfiguration = new CatsConfiguration(appVersion, "template", url, List.of(httpMethod), 1, 1, 1);
catsGlobalContext.init(new OpenAPI().components(new Components()), List.of(), new Properties(), catsConfiguration);
}

private Set<String> getFieldsToFuzz(String payload, String url) {
Expand All @@ -170,7 +188,7 @@ private Set<String> getFieldsToFuzz(String payload, String url) {
return new HashSet<>(JsonUtils.getAllFieldsOf(payload));
}
//When FUZZ keyword is supplied, set simple replace to true in order to do a simple replace(FUZZ, fuzzValue)
userArguments.setSimpleReplace(true);
userArguments.setNameReplace(true);
return Set.of(fuzzKeyword);
}
return targetFields;
Expand Down

0 comments on commit 6e84eac

Please sign in to comment.