29
29
import java .nio .file .Path ;
30
30
import java .nio .file .Paths ;
31
31
import java .security .SecureRandom ;
32
- import java .text .DecimalFormat ;
33
32
import java .util .ArrayList ;
34
33
import java .util .Calendar ;
35
34
import java .util .HashMap ;
54
53
import org .owasp .benchmarkutils .score .report .ScatterHome ;
55
54
import org .owasp .benchmarkutils .score .report .ScatterInterpretation ;
56
55
import org .owasp .benchmarkutils .score .report .ScatterVulns ;
56
+ import org .owasp .benchmarkutils .score .report .html .CommercialAveragesTable ;
57
57
import org .owasp .benchmarkutils .score .report .html .OverallStatsTable ;
58
58
import org .owasp .benchmarkutils .score .report .html .ToolScorecard ;
59
59
import org .owasp .benchmarkutils .score .report .html .VulnerabilityStatsTable ;
@@ -265,7 +265,6 @@ public static void main(String[] args) {
265
265
// Steps 4 & 5: Read the expected results so we know what each tool 'should do' and each
266
266
// tool's results file. a) is for 'mixed' mode, and b) is for normal mode
267
267
try {
268
-
269
268
if (config .mixedMode ) {
270
269
271
270
if (!resultsFileOrDir .isDirectory ()) {
@@ -581,8 +580,6 @@ private static void process(
581
580
ToolResults metrics = calculateMetrics (scores );
582
581
metrics .setScanTime (rawToolResults .getTime ());
583
582
584
- // This has the side effect of also generating the tool's report in the
585
- // scoreCardDir.
586
583
Tool tool =
587
584
new Tool (
588
585
rawToolResults ,
@@ -983,13 +980,7 @@ private static String produceResultsFile(TestSuiteResults actual, File scoreCard
983
980
*/
984
981
private static void generateVulnerabilityScorecards (
985
982
Set <Tool > tools , Set <String > catSet , File scoreCardDir ) {
986
- StringBuilder htmlForCommercialAverages = null ;
987
-
988
- int commercialToolTotal = 0 ;
989
- int numberOfVulnCategories = 0 ;
990
- int commercialLowTotal = 0 ;
991
- int commercialAveTotal = 0 ;
992
- int commercialHighTotal = 0 ;
983
+ CommercialAveragesTable commercialAveragesTable = new CommercialAveragesTable ();
993
984
994
985
// A side effect of this method is to calculate these averages
995
986
averageCommercialToolResults = new HashMap <String , CategoryResults >();
@@ -1003,7 +994,6 @@ private static void generateVulnerabilityScorecards(
1003
994
1004
995
for (String cat : catSet ) {
1005
996
try {
1006
-
1007
997
// Generate a comparison chart for all tools for this vuln category. When
1008
998
// constructed, scatter contains the Overall, Non-commercial, and Commercial stats
1009
999
// for this category across all tools.
@@ -1065,88 +1055,22 @@ private static void generateVulnerabilityScorecards(
1065
1055
1066
1056
Files .write (htmlFile .toPath (), html .getBytes ());
1067
1057
1068
- // Now build up the commercial stats scorecard if there are at 2+ commercial tools
1058
+ // Only build commercial stats scorecard if there are at 2+ commercial tools
1069
1059
if (scatter .getCommercialToolCount () > 1 ) {
1070
- if (htmlForCommercialAverages == null ) {
1071
- commercialToolTotal = scatter .getCommercialToolCount ();
1072
- htmlForCommercialAverages = new StringBuilder ();
1073
- htmlForCommercialAverages .append ("<table class=\" table\" >\n " );
1074
- htmlForCommercialAverages .append ("<tr>" );
1075
- htmlForCommercialAverages .append ("<th>Vulnerability Category</th>" );
1076
- htmlForCommercialAverages .append ("<th>Low Tool Type</th>" );
1077
- htmlForCommercialAverages .append ("<th>Low Score</th>" );
1078
- htmlForCommercialAverages .append ("<th>Ave Score</th>" );
1079
- htmlForCommercialAverages .append ("<th>High Score</th>" );
1080
- htmlForCommercialAverages .append ("<th>High Tool Type</th>" );
1081
- htmlForCommercialAverages .append ("</tr>\n " );
1082
- } // if 1st time through
1083
-
1084
- numberOfVulnCategories ++;
1085
-
1086
- String style = "" ;
1087
- htmlForCommercialAverages .append ("<tr>" );
1088
- htmlForCommercialAverages .append ("<td>" + cat + "</td>" );
1089
- htmlForCommercialAverages .append (
1090
- "<td>" + scatter .getCommercialLowToolType () + "</td>" );
1091
- if (scatter .getCommercialLow () <= 10 ) style = "class=\" danger\" " ;
1092
- else if (scatter .getCommercialLow () >= 50 ) style = "class=\" success\" " ;
1093
- htmlForCommercialAverages .append (
1094
- "<td " + style + ">" + scatter .getCommercialLow () + "</td>" );
1095
- commercialLowTotal += scatter .getCommercialLow ();
1096
- htmlForCommercialAverages .append ("<td>" + scatter .getCommercialAve () + "</td>" );
1097
- commercialAveTotal += scatter .getCommercialAve ();
1098
- if (scatter .getCommercialHigh () <= 10 ) style = "class=\" danger\" " ;
1099
- else if (scatter .getCommercialHigh () >= 50 ) style = "class=\" success\" " ;
1100
- htmlForCommercialAverages .append (
1101
- "<td " + style + ">" + scatter .getCommercialHigh () + "</td>" );
1102
- commercialHighTotal += scatter .getCommercialHigh ();
1103
- htmlForCommercialAverages .append (
1104
- "<td>" + scatter .getCommercialHighToolType () + "</td>" );
1105
- htmlForCommercialAverages .append ("</tr>\n " );
1106
- } // if more than 1 commercial tool
1060
+ commercialAveragesTable .add (scatter );
1061
+ }
1107
1062
1108
1063
} catch (IOException e ) {
1109
1064
System .out .println ("Error generating vulnerability summaries: " + e .getMessage ());
1110
1065
e .printStackTrace ();
1111
1066
}
1112
1067
} // end for loop
1113
1068
1114
- // if we computed a commercial average, then add the last row to the table AND create the
1115
- // file and write the HTML to it.
1116
- if (htmlForCommercialAverages != null ) {
1117
-
1118
- htmlForCommercialAverages .append ("<tr>" );
1119
- htmlForCommercialAverages .append (
1120
- "<td>Average across all categories for " + commercialToolTotal + " tools</td>" );
1121
- htmlForCommercialAverages .append ("<td></td>" );
1122
- htmlForCommercialAverages .append (
1123
- "<td>"
1124
- + new DecimalFormat ("0.0" )
1125
- .format (
1126
- (float ) commercialLowTotal
1127
- / (float ) numberOfVulnCategories )
1128
- + "</td>" );
1129
- htmlForCommercialAverages .append (
1130
- "<td>"
1131
- + new DecimalFormat ("0.0" )
1132
- .format (
1133
- (float ) commercialAveTotal
1134
- / (float ) numberOfVulnCategories )
1135
- + "</td>" );
1136
- htmlForCommercialAverages .append (
1137
- "<td>"
1138
- + new DecimalFormat ("0.0" )
1139
- .format (
1140
- (float ) commercialHighTotal
1141
- / (float ) numberOfVulnCategories )
1142
- + "</td>" );
1143
- htmlForCommercialAverages .append ("<td></td>" );
1144
- htmlForCommercialAverages .append ("</tr>\n " );
1145
- htmlForCommercialAverages .append ("</table>\n " );
1146
-
1069
+ if (commercialAveragesTable .hasEntries ()) {
1147
1070
try {
1148
1071
commercialAveScorecardFilename =
1149
1072
TESTSUITE + "_v" + TESTSUITEVERSION + "_Scorecard_for_Commercial_Tools" ;
1073
+
1150
1074
Path htmlfile =
1151
1075
Paths .get (
1152
1076
scoreCardDir .getAbsolutePath ()
@@ -1164,8 +1088,7 @@ private static void generateVulnerabilityScorecards(
1164
1088
html = html .replace ("${version}" , TESTSUITEVERSION );
1165
1089
html = html .replace ("${projectlink}" , BenchmarkScore .PROJECTLINKENTRY );
1166
1090
1167
- String table = htmlForCommercialAverages .toString ();
1168
- html = html .replace ("${table}" , table );
1091
+ html = html .replace ("${table}" , commercialAveragesTable .render ());
1169
1092
html = html .replace ("${tprlabel}" , config .tprLabel );
1170
1093
html =
1171
1094
html .replace (
0 commit comments