This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/commons-secure-xml.git
commit 3ff2206cdf2fe699a6b02937db37677498ae01a3 Author: Gary Gregory <[email protected]> AuthorDate: Sat Nov 14 14:24:05 2026 -0500 Sort members --- .../java/org/apache/commons/xml/osgi/OsgiIT.java | 52 +++++++++++----------- .../secure/SecureDocumentBuilderFactoryTest.java | 20 ++++----- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/apache/commons/xml/osgi/OsgiIT.java b/src/test/java/org/apache/commons/xml/osgi/OsgiIT.java index 746ed70..d62f9c6 100644 --- a/src/test/java/org/apache/commons/xml/osgi/OsgiIT.java +++ b/src/test/java/org/apache/commons/xml/osgi/OsgiIT.java @@ -148,6 +148,32 @@ private static Path requiredPath(final String property) { return Paths.get(value).toAbsolutePath(); } + /** + * Runs one test class, loaded through the library bundle, and fails with the inner failures if any. + */ + private static void runTestClass(final Class<?> testClass) { + final SummaryGeneratingListener listener = new SummaryGeneratingListener(); + final PostDiscoveryFilter notInOsgi = descriptor -> descriptor.getSource() + .filter(MethodSource.class::isInstance) + .map(MethodSource.class::cast) + .filter(source -> METHODS_NOT_IN_OSGI.contains(source.getJavaClass().getSimpleName() + "#" + source.getMethodName())) + .map(source -> FilterResult.excluded("cannot run inside an OSGi framework")) + .orElseGet(() -> FilterResult.included(null)); + // The context class loader stays the class path's, as in a plain framework launcher. + LauncherFactory.create().execute(LauncherDiscoveryRequestBuilder.request() + .selectors(DiscoverySelectors.selectClass(testClass)) + // Same exclusion as the test-stockjdk execution: xpath3 needs Saxon. + .filters(TagFilter.excludeTags("xpath3"), notInOsgi) + .build(), listener); + final TestExecutionSummary summary = listener.getSummary(); + if (summary.getTotalFailureCount() > 0) { + final StringWriter failures = new StringWriter(); + summary.printFailuresTo(new PrintWriter(failures), 25); + throw new AssertionError(summary.getTotalFailureCount() + " failure(s) in " + testClass.getName() + " under " + framework.getSymbolicName() + + System.lineSeparator() + failures); + } + } + @BeforeAll static void startFramework() throws Exception { final List<FrameworkFactory> factories = new ArrayList<>(); @@ -189,32 +215,6 @@ static void stopFramework() throws Exception { } } - /** - * Runs one test class, loaded through the library bundle, and fails with the inner failures if any. - */ - private static void runTestClass(final Class<?> testClass) { - final SummaryGeneratingListener listener = new SummaryGeneratingListener(); - final PostDiscoveryFilter notInOsgi = descriptor -> descriptor.getSource() - .filter(MethodSource.class::isInstance) - .map(MethodSource.class::cast) - .filter(source -> METHODS_NOT_IN_OSGI.contains(source.getJavaClass().getSimpleName() + "#" + source.getMethodName())) - .map(source -> FilterResult.excluded("cannot run inside an OSGi framework")) - .orElseGet(() -> FilterResult.included(null)); - // The context class loader stays the class path's, as in a plain framework launcher. - LauncherFactory.create().execute(LauncherDiscoveryRequestBuilder.request() - .selectors(DiscoverySelectors.selectClass(testClass)) - // Same exclusion as the test-stockjdk execution: xpath3 needs Saxon. - .filters(TagFilter.excludeTags("xpath3"), notInOsgi) - .build(), listener); - final TestExecutionSummary summary = listener.getSummary(); - if (summary.getTotalFailureCount() > 0) { - final StringWriter failures = new StringWriter(); - summary.printFailuresTo(new PrintWriter(failures), 25); - throw new AssertionError(summary.getTotalFailureCount() + " failure(s) in " + testClass.getName() + " under " + framework.getSymbolicName() - + System.lineSeparator() + failures); - } - } - /** * Checks that the default factories do not depend on the context class loader, with the library bundle's class loader as one. * diff --git a/src/test/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactoryTest.java b/src/test/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactoryTest.java index 0a21f05..539b6c7 100644 --- a/src/test/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactoryTest.java @@ -201,6 +201,16 @@ void newNSInstanceFollowsParserSelection() throws Exception { } } + @Test + void xincludeFalseWithFile() throws Exception { + Assumptions.assumeTrue(AttackTestSupport.DOM_SUPPORTS_XINCLUDE, "the platform DOM does not support XInclude"); + final DocumentBuilderFactory factory = SecureDocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setXIncludeAware(false); + final Document document = factory.newDocumentBuilder().parse(AttackTestSupport.resourceUrl("with-xinclude.xml").toString()); + assertEquals("", document.getDocumentElement().getTextContent().trim()); + } + @Test void xincludeTrueWithFile() throws Exception { Assumptions.assumeTrue(AttackTestSupport.DOM_SUPPORTS_XINCLUDE, "the platform DOM does not support XInclude"); @@ -215,14 +225,4 @@ void xincludeTrueWithFile() throws Exception { assertEquals("All your base are belong to us", document.getDocumentElement().getTextContent().trim()); } - @Test - void xincludeFalseWithFile() throws Exception { - Assumptions.assumeTrue(AttackTestSupport.DOM_SUPPORTS_XINCLUDE, "the platform DOM does not support XInclude"); - final DocumentBuilderFactory factory = SecureDocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setXIncludeAware(false); - final Document document = factory.newDocumentBuilder().parse(AttackTestSupport.resourceUrl("with-xinclude.xml").toString()); - assertEquals("", document.getDocumentElement().getTextContent().trim()); - } - }
