@Override protected boolean hasNext(TestStep testStep, SecurityTestRunContext context) { if (!context.hasProperty(PARAMETERS_INITIALIZED)) { parameters = new StringToStringMap(); initParameters(parameters); context.put(PARAMETERS_INITIALIZED, "true"); hasNext = true; } if (!hasNext) { context.remove(PARAMETERS_INITIALIZED); scriptEngine.clearVariables(); } return hasNext; }
@Override protected void execute( SecurityTestRunner securityTestRunner, TestStep testStep, SecurityTestRunContext context) { scriptEngine.setScript(groovyscc.getExecuteScript().getStringValue()); scriptEngine.setVariable("context", context); scriptEngine.setVariable("testStep", testStep); scriptEngine.setVariable("securityScan", this); scriptEngine.setVariable("parameters", parameters); scriptEngine.setVariable("log", SoapUI.ensureGroovyLog()); try { scriptResult = scriptEngine.run(); hasNext = castResultToBoolean(scriptResult); XmlObjectTreeModel model = null; for (SecurityCheckedParameter scp : getParameterHolder().getParameterList()) { if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) != null) { if (scp.isChecked() && scp.getXpath().trim().length() > 0) { model = SecurityScanUtil.getXmlObjectTreeModel(testStep, scp); XmlTreeNode[] treeNodes = null; treeNodes = model.selectTreeNodes(context.expand(scp.getXpath())); if (treeNodes.length > 0) { XmlTreeNode mynode = treeNodes[0]; mynode.setValue(1, parameters.get(scp.getLabel())); } updateRequestProperty(testStep, scp.getName(), model.getXmlObject().toString()); } else { updateRequestProperty(testStep, scp.getName(), parameters.get(scp.getLabel())); } } else if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) == null) { // clears null values form parameters parameters.remove(scp.getLabel()); } } MessageExchange message = (MessageExchange) testStep.run((TestCaseRunner) securityTestRunner, context); createMessageExchange(clearNullValues(parameters), message, context); } catch (Exception e) { SoapUI.logError(e); hasNext = false; } finally { // if( scriptResult != null ) // { // getTestStep().getProperty( "Request" ).setValue( ( String // )scriptResult ); // // getTestStep().run( ( TestCaseRunner )securityTestRunner, // ( TestCaseRunContext )securityTestRunner.getRunContext() ); // } } }
@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); }