Skip to content

Commit

Permalink
Merge pull request #36 from CYS4srl/testing
Browse files Browse the repository at this point in the history
Unit testing
  • Loading branch information
beryxz authored Feb 26, 2024
2 parents d44ebd2 + b0c8355 commit baad70e
Show file tree
Hide file tree
Showing 23 changed files with 1,827 additions and 151 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/maven-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Maven Tests

on:
push:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Test with Maven
run: mvn -B -Dmaven.test.failure.ignore=true test

- name: Surefire Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Maven Tests
path: target/surefire-reports/*.xml
reporter: java-junit
fail-on-error: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ buildNumber.properties
.classpath

# manually added
.attach_pid*
out/
*.iml
src/build/
Expand Down
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -98,6 +116,10 @@
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.3</version>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BurpExtender implements IBurpExtender {
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) {
try {
MainUI mainUI = new MainUI(callbacks);
mainUI.initialize();
mainUI.initializeUI();

callbacks.setExtensionName(mainUI.getNameExtension());

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/cys4/sensitivediscoverer/MainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public class MainUI implements ITab {
private final Properties configProperties;
private final ScannerOptions scannerOptions;
private JTabbedPane mainPanel;
private boolean interfaceInitialized;

public MainUI(IBurpExtenderCallbacks callbacks) throws Exception {
this.interfaceInitialized = false;
this.callbacks = callbacks;

// setup stdout/stderr
Expand All @@ -50,18 +52,22 @@ public MainUI(IBurpExtenderCallbacks callbacks) throws Exception {
this.extensionsRegexList = RegexSeeder.getExtensionRegexes();
}

public boolean isInterfaceInitialized() {
return interfaceInitialized;
}

public ScannerOptions getScannerOptions() {
return scannerOptions;
}

/**
* Main function that initializes the extension and creates the UI, asynchronously
*/
public void initialize() {
SwingUtilities.invokeLater(this::_initialize);
public void initializeUI() {
SwingUtilities.invokeLater(this::_initializeUI);
}

private void _initialize() {
private void _initializeUI() {
mainPanel = new JTabbedPane();
LoggerTab loggerTab = new LoggerTab(this);
mainPanel.addTab(loggerTab.getTabName(), loggerTab.getPanel());
Expand All @@ -72,6 +78,8 @@ private void _initialize() {

callbacks.customizeUiComponent(mainPanel);
callbacks.addSuiteTab(MainUI.this);

this.interfaceInitialized = true;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/cys4/sensitivediscoverer/RegexSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private static List<RegexEntity> fill(String[] regexFiles) {
element.getDescription(),
element.getRegex(),
element.isActive(),
ProxyItemSection.deserializeSections(element.getSections())))
ProxyItemSection.deserializeSections(element.getSections()),
element.getTests()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class JsonRegexEntity {
private String regex;
private String description;
private List<String> sections;
private List<String> tests;

public JsonRegexEntity() {
}
Expand All @@ -33,4 +34,8 @@ public String getDescription() {
public List<String> getSections() {
return sections;
}

public List<String> getTests() {
return tests;
}
}
22 changes: 17 additions & 5 deletions src/main/java/com/cys4/sensitivediscoverer/model/RegexEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.cys4.sensitivediscoverer.model;

import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -20,27 +21,34 @@ public class RegexEntity {
private final transient Pattern regexCompiled;
private final String description;
private final EnumSet<ProxyItemSection> sections;
private final List<String> tests;
private boolean active;

public RegexEntity(String description, String regex) throws IllegalArgumentException {
this(description, regex, true, ProxyItemSection.getDefault());
this(description, regex, true, ProxyItemSection.getDefault(), null);
}

public RegexEntity(String description, String regex, boolean active) throws IllegalArgumentException {
this(description, regex, active, ProxyItemSection.getDefault());
this(description, regex, active, ProxyItemSection.getDefault(), null);
}

public RegexEntity(String description, String regex, boolean active, EnumSet<ProxyItemSection> sections) {
if (regex == null || regex.isBlank())
this(description, regex, active, sections, null);
}

public RegexEntity(String description, String regex, boolean active, EnumSet<ProxyItemSection> sections, List<String> tests) {
if (regex == null || regex.isBlank()) {
throw new IllegalArgumentException(getLocaleString("exception-invalidRegex"));
if (sections == null)
}
if (sections == null) {
throw new IllegalArgumentException(getLocaleString("exception-invalidSections"));
}

this.active = active;
this.description = description;
this.regex = regex;
this.regexCompiled = Pattern.compile(regex);
this.sections = sections;
this.tests = tests;
}

public RegexEntity(RegexEntity entity) throws IllegalArgumentException {
Expand All @@ -59,6 +67,10 @@ public static Matcher checkRegexEntityFromCSV(String input) {
.matcher(input);
}

public List<String> getTests() {
return tests;
}

public boolean isActive() {
return this.active;
}
Expand Down
Loading

0 comments on commit baad70e

Please sign in to comment.