44
44
import java .util .TreeMap ;
45
45
import java .util .TreeSet ;
46
46
47
- import javax .resource .NotSupportedException ;
48
47
import javax .xml .parsers .DocumentBuilder ;
49
48
import javax .xml .parsers .DocumentBuilderFactory ;
50
49
67
66
import org .owasp .benchmark .score .parsers .NoisyCricketReader ;
68
67
import org .owasp .benchmark .score .parsers .Rapid7Reader ;
69
68
import org .owasp .benchmark .score .parsers .SonarQubeReader ;
69
+ import org .owasp .benchmark .score .parsers .SourceMeterReader ;
70
70
import org .owasp .benchmark .score .parsers .TestCaseResult ;
71
71
import org .owasp .benchmark .score .parsers .TestResults ;
72
72
import org .owasp .benchmark .score .parsers .VeracodeReader ;
73
73
import org .owasp .benchmark .score .parsers .WebInspectReader ;
74
+ import org .owasp .benchmark .score .parsers .XanitizerReader ;
74
75
import org .owasp .benchmark .score .parsers .ZapReader ;
75
76
import org .owasp .benchmark .score .report .Report ;
76
77
import org .owasp .benchmark .score .report .ScatterHome ;
@@ -387,7 +388,8 @@ private static void process(File f, TestResults expectedResults, Set<Report> too
387
388
//System.out.println("Computed actual results for tool: " + actualResults.getTool());
388
389
389
390
if ( expectedResults != null && actualResults != null ) {
390
- // note: side effect is that "pass/fail" value is set for each expected result
391
+ // note: side effect is that "pass/fail" value is set for each expected result so it
392
+ // can be used to produce scorecard for this tool
391
393
analyze ( expectedResults , actualResults );
392
394
393
395
// Produce a .csv results file of the actual results, except if its a commercial tool,
@@ -619,13 +621,23 @@ else if ( filename.endsWith(".json" ) ) {
619
621
}
620
622
}
621
623
624
+ else if ( filename .endsWith ( ".txt" ) ) {
625
+ String line1 = getLine ( fileToParse , 0 );
626
+ if ( line1 .startsWith ( "Possible " ) ) {
627
+ tr = new SourceMeterReader ().parse ( fileToParse );
628
+ }
629
+ }
622
630
else if ( filename .endsWith ( ".xml" ) ) {
623
631
String line1 = getLine ( fileToParse , 0 );
624
632
String line2 = getLine ( fileToParse , 1 );
625
633
if ( line2 .startsWith ( "<pmd" )) {
626
634
tr = new PMDReader ().parse ( fileToParse );
627
635
}
628
636
637
+ else if (line2 .startsWith ("<XanitizerFindingsList" )) {
638
+ tr = new XanitizerReader ().parse (fileToParse );
639
+ }
640
+
629
641
else if ( line2 .startsWith ( "<BugCollection" )) {
630
642
tr = new FindbugsReader ().parse ( fileToParse );
631
643
@@ -890,7 +902,12 @@ private static TestResults readExpectedResults(File f1) throws Exception {
890
902
line = fr .readLine ();
891
903
reading = line != null ;
892
904
if ( reading ) {
893
- String [] parts = line .split ("," );
905
+ // Normally, each line contains: test name, category, real vulnerability, cwe #
906
+
907
+ // String[] parts = line.split(",");
908
+ // regex from http://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes
909
+ // This regex needed because some 'full details' entries contain comma's inside quoted strings
910
+ String [] parts = line .split (",(?=([^\" ]*\" [^\" ]*\" )*[^\" ]*$)" );
894
911
if ( parts [0 ] != null && parts [0 ].startsWith ("Bench" ) ) {
895
912
TestCaseResult tcr = new TestCaseResult ();
896
913
tcr .setTestCaseName (parts [0 ]);
@@ -901,6 +918,16 @@ private static TestResults readExpectedResults(File f1) throws Exception {
901
918
String tcname = parts [0 ].substring ( "BenchmarkTest" .length () );
902
919
tcr .setNumber ( Integer .parseInt (tcname ));
903
920
921
+ // Handle situation where expected results has full details
922
+ // Sometimes, it also has: source, data flow, data flow filename, sink
923
+
924
+ if (parts .length > 4 ) {
925
+ tcr .setSource (parts [4 ]);
926
+ tcr .setDataFlow (parts [5 ]);
927
+ tcr .setDataFlowFile (parts [6 ]);
928
+ tcr .setSink (parts [7 ]);
929
+ }
930
+
904
931
tr .put ( tcr );
905
932
}
906
933
}
@@ -932,30 +959,37 @@ private static String produceResultsFile( TestResults actual ) {
932
959
FileOutputStream fos = new FileOutputStream (resultsFile , false );
933
960
ps = new PrintStream (fos );
934
961
935
- // Write actual results header
936
- ps .print ("# test name, category, real vulnerability, CWE, identified by tool, pass/fail" );
962
+ Set <Integer > testCaseKeys = actual .keySet ();
937
963
938
- // Add the version # inside the file as well
939
- ps .print (", Benchmark version: " + benchmarkVersion );
964
+ boolean fulldetails = (actual .get (testCaseKeys .iterator ().next ()).get (0 ).getSource () != null );
965
+
966
+ // Write actual results header
967
+ ps .print ("# test name, category, CWE, " );
968
+ if (fulldetails ) ps .print ("source, data flow, data flow filename, sink, " );
969
+ ps .print ("real vulnerability, identified by tool, pass/fail, Benchmark version: " + benchmarkVersion );
940
970
941
971
// Append the date YYYY-MM-DD to the header in each .csv file
942
972
Calendar c = Calendar .getInstance ();
943
973
String s = String .format ("%1$tY-%1$tm-%1$te" , c );
944
974
ps .println (", Actual results generated: " + s );
945
975
946
- Set <Integer > testCaseKeys = actual .keySet ();
947
-
948
976
for (Integer expectedResultsKey : testCaseKeys ) {
949
977
// Write meta data to file here.
950
978
TestCaseResult actualResult = actual .get (expectedResultsKey .intValue ()).get (0 );
951
979
ps .print (actualResult .getName ());
952
980
ps .print (", " + actualResult .getCategory ());
981
+ ps .print (", " + actualResult .getCWE ());
982
+ if (fulldetails ) {
983
+ ps .print ("," + actualResult .getSource ());
984
+ ps .print ("," + actualResult .getDataFlow ());
985
+ ps .print (", " + actualResult .getDataFlowFile ());
986
+ ps .print ("," + actualResult .getSink ());
987
+ }
953
988
boolean isreal = actualResult .isReal ();
954
989
ps .print (", " + isreal );
955
- ps .print (", " + actualResult .getCWE ());
956
990
boolean passed = actualResult .isPassed ();
957
991
boolean toolresult = !(isreal ^passed );
958
- ps .print (", " + toolresult );
992
+ ps .print (", " + toolresult );
959
993
ps .println (", " + (passed ? "pass" : "fail" ));
960
994
}
961
995
0 commit comments