|
17 | 17 | */
|
18 | 18 | package org.owasp.benchmarkutils.tools;
|
19 | 19 |
|
| 20 | +import java.io.BufferedWriter; |
20 | 21 | import java.io.File;
|
21 | 22 | import java.io.FileNotFoundException;
|
| 23 | +import java.io.FileWriter; |
22 | 24 | import java.io.IOException;
|
23 | 25 | import java.util.ArrayList;
|
24 | 26 | import java.util.Date;
|
@@ -77,6 +79,7 @@ public class BenchmarkCrawlerVerification extends BenchmarkCrawler {
|
77 | 79 | private static final String FILENAME_UNVERIFIABLE_LOG = "unverifiableTestCases.txt";
|
78 | 80 | // FIXME: This constant is also used by RegressionUtils and should not be duplicated.
|
79 | 81 | private static final String FILENAME_TC_VERIF_RESULTS_JSON = "testCaseVerificationResults.json";
|
| 82 | + private static final String FILENAME_VERIFY_FIX_RESULT = "verifyFixedResult.json"; |
80 | 83 | // The following is reconfigurable via parameters to main()
|
81 | 84 | // private String CRAWLER_DATA_DIR = Utils.DATA_DIR; // default data dir
|
82 | 85 |
|
@@ -496,7 +499,15 @@ protected void handleResponse(TestCaseVerificationResults results)
|
496 | 499 | loadTestCaseVerificationResults(beforeFixOutputDirectory);
|
497 | 500 | TestCaseVerificationResults beforeFixResults =
|
498 | 501 | 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 | + } |
500 | 511 | }
|
501 | 512 | }
|
502 | 513 |
|
@@ -548,20 +559,26 @@ private boolean verifyFix(
|
548 | 559 | !beforeFixResults
|
549 | 560 | .getResponseToSafeValue()
|
550 | 561 | .getResponseString()
|
551 |
| - .equals(afterFixResults.getResponseToAttackValue().getResponseString()); |
| 562 | + .equals(afterFixResults.getResponseToSafeValue().getResponseString()); |
552 | 563 | if (wasExploited) {
|
553 | 564 | System.out.println("NOT FIXED: Vulnerability was exploited");
|
554 | 565 | }
|
555 | 566 | if (wasBroken) {
|
556 | 567 | System.out.println("NOT FIXED: Functionality was broken");
|
557 | 568 | }
|
558 | 569 |
|
559 |
| - try { |
| 570 | + File verifyFixResultFile = new File(getOutputDirectory(), FILENAME_VERIFY_FIX_RESULT); |
| 571 | + try (BufferedWriter writer = new BufferedWriter(new FileWriter(verifyFixResultFile))) { |
560 | 572 | VerifyFixOutput verifyFixOutput = new VerifyFixOutput();
|
561 | 573 | verifyFixOutput.setWasExploited(wasExploited);
|
562 | 574 | verifyFixOutput.setWasBroken(wasBroken);
|
563 | 575 | 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(); |
565 | 582 | } catch (JAXBException e) {
|
566 | 583 | System.out.println("ERROR: Could not marshall VerifyFixOutput to JSON");
|
567 | 584 | e.printStackTrace();
|
|
0 commit comments