Skip to content

Commit dbce0f2

Browse files
Write the verifyFix output to a file and fix a bug that broke determining wasBroken.
1 parent 5b44190 commit dbce0f2

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

plugin/src/main/java/org/owasp/benchmarkutils/tools/BenchmarkCrawlerVerification.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
*/
1818
package org.owasp.benchmarkutils.tools;
1919

20+
import java.io.BufferedWriter;
2021
import java.io.File;
2122
import java.io.FileNotFoundException;
23+
import java.io.FileWriter;
2224
import java.io.IOException;
2325
import java.util.ArrayList;
2426
import java.util.Date;
@@ -77,6 +79,7 @@ public class BenchmarkCrawlerVerification extends BenchmarkCrawler {
7779
private static final String FILENAME_UNVERIFIABLE_LOG = "unverifiableTestCases.txt";
7880
// FIXME: This constant is also used by RegressionUtils and should not be duplicated.
7981
private static final String FILENAME_TC_VERIF_RESULTS_JSON = "testCaseVerificationResults.json";
82+
private static final String FILENAME_VERIFY_FIX_RESULT = "verifyFixedResult.json";
8083
// The following is reconfigurable via parameters to main()
8184
// private String CRAWLER_DATA_DIR = Utils.DATA_DIR; // default data dir
8285

@@ -496,7 +499,15 @@ protected void handleResponse(TestCaseVerificationResults results)
496499
loadTestCaseVerificationResults(beforeFixOutputDirectory);
497500
TestCaseVerificationResults beforeFixResults =
498501
beforeFixResultsCollection.getResultsObjects().get(0);
499-
verifyFix(beforeFixResults, results);
502+
if (beforeFixResults.getTestCase().getName().equals(results.getTestCase().getName())) {
503+
verifyFix(beforeFixResults, results);
504+
} else {
505+
System.out.println(
506+
"WARNING: After fix testcase is "
507+
+ results.getTestCase().getName()
508+
+ " but before fix testcase is "
509+
+ beforeFixResults.getTestCase().getName());
510+
}
500511
}
501512
}
502513

@@ -548,20 +559,26 @@ private boolean verifyFix(
548559
!beforeFixResults
549560
.getResponseToSafeValue()
550561
.getResponseString()
551-
.equals(afterFixResults.getResponseToAttackValue().getResponseString());
562+
.equals(afterFixResults.getResponseToSafeValue().getResponseString());
552563
if (wasExploited) {
553564
System.out.println("NOT FIXED: Vulnerability was exploited");
554565
}
555566
if (wasBroken) {
556567
System.out.println("NOT FIXED: Functionality was broken");
557568
}
558569

559-
try {
570+
File verifyFixResultFile = new File(getOutputDirectory(), FILENAME_VERIFY_FIX_RESULT);
571+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(verifyFixResultFile))) {
560572
VerifyFixOutput verifyFixOutput = new VerifyFixOutput();
561573
verifyFixOutput.setWasExploited(wasExploited);
562574
verifyFixOutput.setWasBroken(wasBroken);
563575
String output = Utils.objectToJson(verifyFixOutput);
564-
System.out.println(output);
576+
// System.out.println(output);
577+
writer.write(output);
578+
} catch (IOException e) {
579+
System.out.println(
580+
"ERROR: Could not write VerifyFixOutput to file " + verifyFixResultFile);
581+
e.printStackTrace();
565582
} catch (JAXBException e) {
566583
System.out.println("ERROR: Could not marshall VerifyFixOutput to JSON");
567584
e.printStackTrace();

0 commit comments

Comments
 (0)