PentahoSolutionSpringApplicationContext extends XmlWebApplicationContext { @VisibleForTesting Document getResourceDocument( InputStream is ) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dFactory = XMLParserFactoryProducer.createSecureDocBuilderFactory(); dFactory.setNamespaceAware( true ); DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); return dBuilder.parse( is ); }    }
@Test( timeout = 2000, expected = SAXException.class ) public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException { appContext.getResourceDocument( new StringBufferInputStream( XmlTestConstants.MALICIOUS_XML ) ); fail(); }
@Test public void shouldNotFailAndReturnNotNullWhenLegalXmlIsGiven() throws Exception { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<slave_config>" + "</slave_config>"; assertNotNull( appContext.getResourceDocument( new StringBufferInputStream( xml ) ) ); }