Skip to content

Commit 4c17896

Browse files
committed
Fix MenuUpdaterTest to not break on Windows. Move Categories static initializer into that class.
Tweak expected results parser to allow for white space between entries in CSV file.
1 parent 0862b3b commit 4c17896

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

.mvn/jvm.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
2+

library/src/main/java/org/owasp/benchmarkutils/helpers/Categories.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public class Categories {
4646

4747
private static Categories _instance; // The Singleton instance of this class
4848

49+
// Statically load the categories definitions from the config file to instantiate the Category
50+
// singleton
51+
static {
52+
try {
53+
InputStream categoriesFileStream =
54+
Categories.class.getClassLoader().getResourceAsStream(Categories.FILENAME);
55+
new Categories(categoriesFileStream);
56+
} catch (ParserConfigurationException | SAXException | IOException e1) {
57+
System.out.println("ERROR: couldn't load categories from categories config file.");
58+
e1.printStackTrace();
59+
System.exit(-1);
60+
}
61+
}
62+
4963
/**
5064
* Initialize all the categories from the InputStream connected to the target XML file.
5165
*

plugin/src/main/java/org/owasp/benchmarkutils/score/BenchmarkScore.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Set;
3737
import java.util.TreeMap;
3838
import java.util.TreeSet;
39-
import javax.xml.parsers.ParserConfigurationException;
4039
import org.apache.commons.io.FileUtils;
4140
import org.apache.commons.io.IOUtils;
4241
import org.apache.maven.plugin.AbstractMojo;
@@ -58,7 +57,6 @@
5857
import org.owasp.benchmarkutils.score.report.html.VulnerabilityStatsTable;
5958
import org.owasp.benchmarkutils.score.service.ExpectedResultsProvider;
6059
import org.owasp.benchmarkutils.score.service.ResultsFileCreator;
61-
import org.xml.sax.SAXException;
6260

6361
@Mojo(name = "create-scorecard", requiresProject = false, defaultPhase = LifecyclePhase.COMPILE)
6462
public class BenchmarkScore extends AbstractMojo {
@@ -161,17 +159,6 @@ public static void main(String[] args) {
161159
System.exit(-1);
162160
}
163161

164-
// Load in the categories definitions from the config file.
165-
try {
166-
InputStream categoriesFileStream =
167-
BenchmarkScore.class.getClassLoader().getResourceAsStream(Categories.FILENAME);
168-
new Categories(categoriesFileStream);
169-
} catch (ParserConfigurationException | SAXException | IOException e1) {
170-
System.out.println("ERROR: couldn't load categories from categories config file.");
171-
e1.printStackTrace();
172-
System.exit(-1);
173-
}
174-
175162
// Step 0: Make sure the results file or directory exists before doing anything.
176163
File resultsFileOrDir = new File(config.resultsFileOrDirName);
177164
if (!resultsFileOrDir.exists()) {

plugin/src/main/java/org/owasp/benchmarkutils/score/service/ExpectedResultsProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public static TestSuiteResults parse(ResultFile resultFile) throws IOException {
5555
if (record.get(TEST_NAME).startsWith(tr.getTestSuiteName() + BenchmarkScore.TEST)) {
5656
TestCaseResult tcr = new TestCaseResult();
5757

58-
tcr.setTestCaseName(record.get(TEST_NAME));
59-
tcr.setCategory(record.get(CATEGORY));
60-
tcr.setTruePositive(parseBoolean(record.get(REAL_VULNERABILITY)));
61-
tcr.setCWE(parseInt(record.get(CWE)));
62-
tcr.setNumber(testNumber(record.get(TEST_NAME), testCaseName));
58+
tcr.setTestCaseName(record.get(TEST_NAME).trim());
59+
tcr.setCategory(record.get(CATEGORY).trim());
60+
tcr.setTruePositive(parseBoolean(record.get(REAL_VULNERABILITY).trim()));
61+
tcr.setCWE(parseInt(record.get(CWE).trim()));
62+
tcr.setNumber(testNumber(record.get(TEST_NAME).trim(), testCaseName));
6363

6464
if (isExtendedResultsFile(parser)) {
65-
tcr.setSource(record.get(SOURCE));
66-
tcr.setDataFlow(record.get(DATA_FLOW));
67-
tcr.setSink(record.get(SINK));
65+
tcr.setSource(record.get(SOURCE).trim());
66+
tcr.setDataFlow(record.get(DATA_FLOW).trim());
67+
tcr.setSink(record.get(SINK).trim());
6868
}
6969

7070
tr.put(tcr);

plugin/src/test/java/org/owasp/benchmarkutils/score/report/html/MenuUpdaterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public String filenameFor(Tool tool) {
114114
assertFalse(file.contains("${vulnmenu}"));
115115
assertTrue(
116116
file.contains(
117-
"<li><a href=\"Benchmark_v1.2_Scorecard_for_Path_Traversal.html\">Path Traversal</a></li>\n"));
117+
"<li><a href=\"Benchmark_v1.2_Scorecard_for_Path_Traversal.html\">Path Traversal</a></li>"));
118118
assertTrue(
119119
file.contains(
120-
"<li><a href=\"Benchmark_v1.2_Scorecard_for_Command_Injection.html\">Command Injection</a></li>\n"));
120+
"<li><a href=\"Benchmark_v1.2_Scorecard_for_Command_Injection.html\">Command Injection</a></li>"));
121121

122122
assertFalse(file.contains("${testsuite}"));
123123
assertTrue(file.contains("testsuite=OWASP Benchmark"));

0 commit comments

Comments
 (0)