RegionMetadataParser { public static RegionMetadata parse(final InputStream input) throws IOException { return new RegionMetadata(internalParse(input, false)); } @Deprecated  RegionMetadataParser(); static RegionMetadata parse(final InputStream input); @Deprecated List<Region> parseRegionMetadata(InputStream input); @Deprecated List<Region> parseRegionMetadata(final InputStream input,
                                            final boolean endpointVerification);  }
@Test public void testExternalEntity() throws IOException { TestHttpServer server = new TestHttpServer("secret"); try { String xml = String.format( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE oops [\n" + " <!ENTITY foo SYSTEM \"%s\" >\n" + "]>\n" + "<oops>&foo;</oops>", server.url()); parse(xml); } catch (IOException e) { } finally { server.stop(); } if (server.accepted()) { fail("Oops! The server has been reached!"); } }
@Test public void testExternalSchema() throws IOException { TestHttpServer server = new TestHttpServer("secret"); try { String xml = String.format( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE oops SYSTEM \"%s\">\n" + "<oops></oops>", server.url()); parse(xml); } catch (IOException e) { } finally { server.stop(); } if (server.accepted()) { fail("Oops! The server has been reached!"); } }
@Test public void testExternalEntityParameter() throws IOException { TestHttpServer server = new TestHttpServer("secret"); try { String xml = String.format( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE oops [\n" + " <!ENTITY %% sp SYSTEM \"%s\">\n" + "%%sp;" + "]>\n" + "<oops></oops>", server.url()); parse(xml); } catch (IOException e) { } finally { server.stop(); } if (server.accepted()) { fail("Oops! The server has been reached!"); } }
@Test(expected = IOException.class) public void billionLaughs() throws IOException { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENTITY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<lolz>&lol9;</lolz>"; parse(xml); }