XActionImportHandler extends RepositoryFileImportFileHandler implements IPlatformImportHandler { @VisibleForTesting Document getImportBundleDocument( InputStream is ) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse( is ); } XActionImportHandler( List<IMimeType> mimeTypes ); @Override void importFile( IPlatformImportBundle bundle );  }
@Test( timeout = 2000, expected = SAXException.class ) public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException { handler.getImportBundleDocument( 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( handler.getImportBundleDocument( new StringBufferInputStream( xml ) ) ); }