XPathAnalyser { public boolean isFastXPath() { for ( Step step : xpath.getRelativeLocationPaths() ) { if ( !step.getAxisSpecifier().getAxisName().toFullString().equals( "child" ) ) { return false; } if ( step.getAxisSpecifier().getNodeType() != null ) { return false; } if ( step.getAxisSpecifier().getNodeName() == null ) { return false; } if ( step.getAxisSpecifier().getNodeName().getNodeName().isEmpty() ) { return false; } List<Predicate> predicates = step.getPredicates(); if ( predicates.isEmpty() || predicates.size() > 2 ) { return false; } int positions = 0; int attributes = 0; for ( Predicate pred : step.getPredicates() ) { if ( pred.getOrExpressions().size() != 1 ) { return false; } if ( pred.getOrExpressions().get( 0 ).getAndExpressions().size() != 1 ) { return false; } AndExpression and = pred.getOrExpressions().get( 0 ).getAndExpressions().get( 0 ); if ( and instanceof PositionAndExpression ) { ++positions; } else if ( and instanceof AttributeAndExpression ) { ++attributes; } } if ( positions > 1 || attributes > 1 || ( attributes + positions ) == 0 ) { return false; } } return true; } XPathAnalyser( ReferringElementInterface ref, SignedElement signedElement, PayloadElement payloadElement,
                          SchemaAnalyzer schemaAnalyzer );  XPathAnalyser( String xpath, SignedElement signedElement, PayloadElement payloadElement,
                          SchemaAnalyzer schemaAnalyser ); List<XPathWeaknessInterface> getWeaknesses(); AbsoluteLocationPath getXPath(); int getMaxPossibilites(); void abuseWeakness( int possibility, SignedElement signedElement, PayloadElement payloadElement ); boolean isFastXPath(); boolean isPrefixfreeTransformedFastXPath(); static XPathWeaknessFactoryInterface xpathWeaknessFactory; }
@Test public void fastXPathTest() { XPathAnalyser a; String xpath; xpath = "/Envelope[1]/Body[1]/function[1]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); xpath = "/Envelope[1]/Header[1]/Security[1][@role=\"next\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); xpath = " a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[1]/Body/Function"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[1]/Header[1]/Security[1][@role=\"next\" or @mustUnderstand=\"true\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[@attr='/etc/passwd']"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); xpath = "/Envelope[@attr=\"/etc/passwd\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); xpath = "/Envelope[@attr='/etc/passwd']/Body[@attr=\"/etc/shadow\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); xpath = "/Envelope[1 and 0]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[1[2]3]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[1][2][3]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[1][2]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/Envelope[@foo='1'][@bar='2']"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isFastXPath() ); xpath = "/soapenv:Envelope[1]/soapenv:Body[1]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isFastXPath() ); }