Skip to content

Commit

Permalink
automation: Initialise default values
Browse files Browse the repository at this point in the history
Signed-off-by: ricekot <git@ricekot.com>
  • Loading branch information
ricekot committed Oct 16, 2024
1 parent 0ac0036 commit dbe25f3
Show file tree
Hide file tree
Showing 40 changed files with 291 additions and 1,596 deletions.
4 changes: 3 additions & 1 deletion addOns/addOns.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ subprojects {

tasks.withType<JavaCompile>().configureEach {
if (JavaVersion.current().getMajorVersion() >= "21") {
options.compilerArgs = options.compilerArgs + "-Xlint:-this-escape"
options.compilerArgs = options.compilerArgs + "-Xlint:-this-escape,-processing"
} else {
options.compilerArgs = options.compilerArgs + "-Xlint:-processing"
}
}

Expand Down
3 changes: 2 additions & 1 deletion addOns/alertFilters/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Changed
- Fields with default or missing values are omitted for the `alertFilter` job in saved Automation Framework plans.

## [22] - 2024-10-07
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.parosproxy.paros.CommandLine;
import org.parosproxy.paros.Constant;
Expand Down Expand Up @@ -419,7 +421,7 @@ protected int getAlertFilterCount() {
}

public static class Data extends JobData {
private List<AlertFilterData> alertFilters;
private List<AlertFilterData> alertFilters = new ArrayList<>();
private Parameters parameters = new Parameters();

public Data(AutomationJob job) {
Expand All @@ -446,136 +448,28 @@ public void addAlertFilters(AlertFilterData alertFilter) {
}
}

@Getter
@Setter
public static class Parameters extends AutomationData {
private Boolean deleteGlobalAlerts;

public Boolean getDeleteGlobalAlerts() {
return deleteGlobalAlerts;
}

public void setDeleteGlobalAlerts(Boolean deleteGlobalAlerts) {
this.deleteGlobalAlerts = deleteGlobalAlerts;
}
private Boolean deleteGlobalAlerts = false;
}

@Getter
@Setter
public static class AlertFilterData extends AutomationData {
private String ruleId;
private String ruleName;
private String context;
private String ruleName = "";
private String context = "";
private String newRisk;
private String parameter;
private Boolean parameterRegex;
private String url;
private Boolean urlRegex;
private String attack;
private Boolean attackRegex;
private String evidence;
private Boolean evidenceRegex;
private List<String> methods;

public AlertFilterData() {
methods = List.of();
}

public String getRuleId() {
return ruleId;
}

public void setRuleId(String ruleId) {
this.ruleId = ruleId;
}

public String getRuleName() {
return ruleName;
}

public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}

public String getContext() {
return context;
}

public void setContext(String context) {
this.context = context;
}

public String getNewRisk() {
return newRisk;
}

public void setNewRisk(String newRisk) {
this.newRisk = newRisk;
}

public String getParameter() {
return parameter;
}

public void setParameter(String parameter) {
this.parameter = parameter;
}

public Boolean getParameterRegex() {
return parameterRegex;
}

public void setParameterRegex(Boolean isParameterRegex) {
this.parameterRegex = isParameterRegex;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public Boolean getUrlRegex() {
return urlRegex;
}

public void setUrlRegex(Boolean isUrlRegex) {
this.urlRegex = isUrlRegex;
}

public String getAttack() {
return attack;
}

public void setAttack(String attack) {
this.attack = attack;
}

public Boolean getAttackRegex() {
return attackRegex;
}

public void setAttackRegex(Boolean isAttackRegex) {
this.attackRegex = isAttackRegex;
}

public String getEvidence() {
return evidence;
}

public void setEvidence(String evidence) {
this.evidence = evidence;
}

public Boolean getEvidenceRegex() {
return evidenceRegex;
}

public void setEvidenceRegex(Boolean isEvidenceRegex) {
this.evidenceRegex = isEvidenceRegex;
}

public List<String> getMethods() {
return methods;
}
private String parameter = "";
private Boolean parameterRegex = false;
private String url = "";
private Boolean urlRegex = false;
private String attack = "";
private Boolean attackRegex = false;
private String evidence = "";
private Boolean evidenceRegex = false;
private List<String> methods = List.of();

public void setMethods(List<String> methods) {
this.methods = Objects.requireNonNullElse(methods, List.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -75,8 +76,8 @@ void shouldReturnDefaultFields() {
assertThat(job.getParamMethodObject(), is(nullValue()));
assertThat(job.getParamMethodName(), is(nullValue()));
assertThat(job.getAlertFilterCount(), is(equalTo(0)));
assertThat(job.getData().getAlertFilters(), is(nullValue()));
assertThat(job.getParameters().getDeleteGlobalAlerts(), is(nullValue()));
assertThat(job.getData().getAlertFilters(), is(equalTo(List.of())));
assertThat(job.getParameters().getDeleteGlobalAlerts(), is(false));
}

@Test
Expand Down
6 changes: 5 additions & 1 deletion addOns/automation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Changed
- Fields with default or missing values are omitted for the following automation jobs in saved plans:
- `activeScan`
- `delay`
- `requestor`

## [0.43.0] - 2024-10-07
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -414,88 +416,18 @@ private ExtensionUserManagement getExtUserMgmt() {
return extUserMgmt;
}

@Getter
@Setter
public static class Data extends AutomationData {
private String name;
private List<String> urls = new ArrayList<>();
private List<String> includePaths;
private List<String> excludePaths;
private List<String> includePaths = new ArrayList<>();
private List<String> excludePaths = new ArrayList<>();
private AuthenticationData authentication;
private SessionManagementData sessionManagement;
private TechnologyData technology;
private StructureData structure;
private List<UserData> users;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<String> getUrls() {
return urls;
}

public void setUrls(List<String> urls) {
this.urls = urls;
}

public List<String> getIncludePaths() {
return includePaths;
}

public void setIncludePaths(List<String> includePaths) {
this.includePaths = includePaths;
}

public List<String> getExcludePaths() {
return excludePaths;
}

public void setExcludePaths(List<String> excludePaths) {
this.excludePaths = excludePaths;
}

public AuthenticationData getAuthentication() {
return authentication;
}

public void setAuthentication(AuthenticationData authentication) {
this.authentication = authentication;
}

public SessionManagementData getSessionManagement() {
return sessionManagement;
}

public void setSessionManagement(SessionManagementData sessionManagement) {
this.sessionManagement = sessionManagement;
}

public TechnologyData getTechnology() {
return technology;
}

public void setTechnology(TechnologyData technology) {
this.technology = technology;
}

public List<UserData> getUsers() {
return users;
}

public void setUsers(List<UserData> users) {
this.users = users;
}

public StructureData getStructure() {
return structure;
}

public void setStructure(StructureData structure) {
this.structure = structure;
}
private List<UserData> users = new ArrayList<>();
}

public static class UserData extends AutomationData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import java.util.Collection;

public class DefaultPropertyFilter extends SimpleBeanPropertyFilter {

Expand All @@ -35,11 +34,8 @@ public void serializeAsField(
Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer)
throws Exception {
if (include(writer)) {
Object value = writer.getMember().getValue(pojo);
if (value == null
|| (value instanceof Collection && ((Collection<?>) value).isEmpty())
|| (pojo instanceof AutomationData
&& ((AutomationData) pojo).isDefaultValue(writer.getName()))) {
if (pojo instanceof AutomationData
&& ((AutomationData) pojo).isDefaultValue(writer.getName())) {
return;
}
writer.serializeAsField(pojo, jgen, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public List<String> getExclude() {
public void setExclude(List<String> exclude) {
this.exclude = exclude;
// Exclude takes precedence.
this.include = null;
this.include = List.of();
}

private void setExclude(TechSet techSet) {
Expand Down
Loading

0 comments on commit dbe25f3

Please sign in to comment.