@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() ); // } } }
public static List<String> getType(XmlTreeNode node, List<String> restrictionsList) { String baseType = null; for (int i = 0; i < node.getChildCount(); i++) { XmlTreeNode mynode = node.getChild(i); if (mynode.getNodeName().equals("@base")) { baseType = mynode.getNodeText(); if (baseType.contains(":")) { baseType = baseType.substring(baseType.indexOf(":") + 1); } restrictionsList.add("type = " + baseType); } getType(mynode, restrictionsList); } return restrictionsList; }
public static List<String> extractEnums(XmlTreeNode node) { List<String> restrictionsList = new ArrayList<String>(); for (XmlAnySimpleType s : node.getSchemaType().getEnumerationValues()) { if (restrictionsList.isEmpty()) { restrictionsList.add("For type enumeration values are: "); } restrictionsList.add(s.getStringValue()); } return restrictionsList; }
public static List<String> getRestrictions(XmlTreeNode node, List<String> restrictionsList) { String baseType = null; for (int i = 0; i < node.getChildCount(); i++) { XmlTreeNode mynode = node.getChild(i); if ("xsd:restriction".equals(mynode.getParent().getNodeName())) { if (mynode.getNodeName().equals("@base")) { baseType = mynode.getNodeText(); restrictionsList.add("type = " + baseType); } else { String nodeName = mynode.getNodeName(); String nodeValue = mynode.getChild(0).getNodeText(); restrictionsList.add(nodeName + " = " + nodeValue); } } getRestrictions(mynode, restrictionsList); } return restrictionsList; }