コード例 #1
0
  @Override
  public void afterRun(TestCaseRunner testRunner, SecurityTestRunContext runContext) {
    TestCase testCase = testRunner.getTestCase();

    SecurityTest securityTest = ((SecurityTestRunner) testRunner).getSecurityTest();

    JUnitReport report = new JUnitReport();
    report.setIncludeTestProperties(includeTestPropertiesInReport);

    String reportName = securityTest.getName();
    report.setTestSuiteName(reportName);
    report.setPackage(testCase.getTestSuite().getProject().getName());
    int errorCount = 0;

    for (TestStep ts : testCase.getTestStepList()) {
      SecurityTestStepResult secuTestStepResult =
          securityTest.getSecurityTestStepResultMap().get(ts);
      if (secuTestStepResult != null) {
        for (SecurityScanResult scanResult : secuTestStepResult.getSecurityScanResultList()) {

          HashMap<String, String> testProperties = getTestPropertiesAsHashMap(securityTest);

          List<SecurityScanRequestResult> resultList = scanResult.getSecurityRequestResultList();
          Testcase secTestCase =
              report.addTestCase(
                  ts.getName() + " - " + scanResult.getSecurityScanName(),
                  scanResult.getTimeTaken(),
                  testProperties);

          secTestCase.setPackage(testCase.getTestSuite().getProject().getName());

          for (int i = 0; i < resultList.size(); i++) {
            SecurityScanRequestResult scanRequestResult = resultList.get(i);
            if (scanRequestResult.getStatus() == ResultStatus.FAILED) {
              StringBuffer result = new StringBuffer();
              result
                  .append("<pre>")
                  .append(XmlUtils.entitize(scanRequestResult.getChangedParamsInfo(i + 1)))
                  .append("</pre>");

              for (String message : scanRequestResult.getMessages()) {
                result.append("<pre>").append(XmlUtils.entitize(message)).append("</pre>");
              }

              secTestCase.addNewError().setStringValue(result.toString());
              errorCount++;
            }
          }
        }
      }

      report.setNoofErrorsInTestSuite(errorCount);
      report.setTotalTime(testRunner.getTimeTaken());

      reports.put(reportName, report);
    }
  }
コード例 #2
0
    public void afterSecurityScan(
        TestCaseRunner testRunner,
        SecurityTestRunContext runContext,
        SecurityScanResult securityCheckResult) {

      if (securityCheckResult.getSecurityScan().getTestStep().getId().equals(testStep.getId())) {

        if (securityCheckResult.getStatus() == ResultStatus.CANCELED) {
          progressBar.setString(STATE_CANCEL);
          progressBar.setBackground(UNKNOWN_COLOR);
        } else
        // progressbar can change its color only if not missing
        // assertions or parameters
        if (securityCheckResult.getStatus() == ResultStatus.FAILED) {
          progressBar.setForeground(FAILED_COLOR);
        } else if (securityCheckResult.getStatus() == ResultStatus.OK) {
          SecurityScan securityScan = securityCheckResult.getSecurityScan();
          if (securityScan.getAssertionCount() == 0) {
            if (!progressBar.getForeground().equals(FAILED_COLOR))
              progressBar.setForeground(MISSING_ASSERTION_COLOR);
            progressBar.setString(STATE_MISSING_ASSERTIONS);
          }
          // or if there is no parameters.
          if (securityScan instanceof AbstractSecurityScanWithProperties
              && ((AbstractSecurityScanWithProperties) securityScan)
                      .getParameterHolder()
                      .getParameterList()
                      .size()
                  == 0) {
            if (!progressBar.getForeground().equals(FAILED_COLOR))
              progressBar.setForeground(MISSING_ASSERTION_COLOR);
            if (!progressBar.getString().equals(STATE_MISSING_ASSERTIONS))
              progressBar.setString(STATE_MISSING_PARAMETERS);
          }

          // can not change to OK color if any of previous scans
          // failed or missing assertions/parameters
          if (!progressBar.getForeground().equals(FAILED_COLOR)
              && !progressBar.getForeground().equals(MISSING_ASSERTION_COLOR)) {
            progressBar.setForeground(OK_COLOR);
          }
        }

        progressBar.setValue(((SecurityTestRunContext) runContext).getCurrentScanIndex() + 1);
        ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
      }
    }
コード例 #3
0
    @Override
    public void afterStep(
        TestCaseRunner testRunner,
        SecurityTestRunContext runContext,
        SecurityTestStepResult result) {
      if (runContext.getCurrentStep().getId().equals(testStep.getId())) {
        if (!(progressBar.getString().equals(STATE_CANCEL)
                || progressBar.getString().equals(STATE_MISSING_ASSERTIONS)
                || progressBar.getString().equals(STATE_MISSING_PARAMETERS))
            && securityTest.getSecurityTestStepResultMap().get(testStep) != null) {
          SecurityTestStepResult results =
              securityTest.getSecurityTestStepResultMap().get(testStep);
          /*
           * This is hack since SecurityTestStepResult.getStatus() do not
           * returns real state of execution.
           *
           * SKIPPED state overides all except FAILED , which is wrong.
           */
          boolean skipped = results.getSecurityScanResultList().size() > 0;

          for (SecurityScanResult res : results.getSecurityScanResultList()) {
            if (res.getStatus() == ResultStatus.SKIPPED) continue;
            else {
              skipped = false;
              break;
            }
          }
          if (skipped) {
            progressBar.setString("SKIPPED");
            progressBar.setForeground(UNKNOWN_COLOR);
          } else {
            progressBar.setString(STATE_DONE);
          }
        }
      } else progressBar.setBackground(UNKNOWN_COLOR);
      progressBar.setValue(progressBar.getMaximum() == 0 ? 1 : progressBar.getMaximum());
      ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
    }