LocaleImportHandler extends RepositoryFileImportFileHandler implements IPlatformImportHandler { @VisibleForTesting Document getLocalBundleDocument( InputStream is ) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory builderFactory = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse( is ); } LocaleImportHandler( List<IMimeType> mimeTypes, List<String> artifacts ); void importFile( IPlatformImportBundle bundle );  }
@Test( timeout = 2000, expected = SAXException.class ) public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException { LocaleImportHandler lih = new LocaleImportHandler( Collections.emptyList(), null ); lih.getLocalBundleDocument( 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>"; LocaleImportHandler lih = new LocaleImportHandler( Collections.emptyList(), null ); assertNotNull( lih.getLocalBundleDocument( new StringBufferInputStream( xml ) ) ); }