From 342b5849c864971e7993d2ff30a6ad4bd961cf05 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sat, 11 Jan 2025 23:25:25 +0100 Subject: [PATCH 1/3] Upgrade xml resolver library, revise/refactor tests --- ...ectionConfigurationValidationModeTest.java | 175 ++++++++++++------ exist-parent/pom.xml | 3 +- 2 files changed, 124 insertions(+), 54 deletions(-) diff --git a/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java b/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java index 49bd6725d58..7cd5a55a69f 100644 --- a/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java +++ b/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java @@ -24,12 +24,13 @@ import org.exist.test.ExistXmldbEmbeddedServer; - -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; import org.xmldb.api.base.Collection; -import org.xmldb.api.base.XMLDBException; - import org.xmldb.api.base.ResourceSet; +import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.CollectionManagementService; import static org.exist.collections.CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE; @@ -44,14 +45,103 @@ public class CollectionConfigurationValidationModeTest { @ClassRule public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(false, true, true); - private static final String valid = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; - private static final String invalid = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; - private static final String anonymous = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; - private static final String different = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; - - private static final String xconf_yes = ""; - private static final String xconf_no = ""; - private static final String xconf_auto = ""; + private static final String VALID_XSD = + """ + + + + + + + + + + + + + + + + + + """; + + private static final String INVALID_XSD = """ + + + + + + + + + + + + + + + + + + """; + private static final String ANONYMOUS_XSD = """ + + + + + + + + + + + + + + + + + + """; + + private static final String DIFFERENT_XSD = """ + + + + + + + + + + + + + + + + + + """; + private static final String XCONF_YES = """ + + + + """; + private static final String XCONF_NO = """ + + + + """; + private static final String XCONF_AUTO = """ + + + + """; @AfterClass public static void tearDownClass() throws Exception { @@ -87,104 +177,83 @@ private void storeDocument(final String collection, final String name, final Str @Test public void insertModeFalse() throws XMLDBException { createCollection("/db/false"); - storeCollectionXconf("/db/system/config/db/false", xconf_no); + storeCollectionXconf("/db/system/config/db/false", XCONF_NO); // namespace provided, valid document; should pass - storeDocument("/db/false", "valid.xml", valid); + storeDocument("/db/false", "valid.xml", VALID_XSD); // namespace provided, invalid document; should pass - storeDocument("/db/false", "invalid.xml", invalid); + storeDocument("/db/false", "invalid.xml", INVALID_XSD); // no namespace provided, should pass - storeDocument("/db/false", "anonymous.xml", anonymous); + storeDocument("/db/false", "anonymous.xml", ANONYMOUS_XSD); // non resolvable namespace provided, should pass - storeDocument("/db/false", "different.xml", different); + storeDocument("/db/false", "different.xml", DIFFERENT_XSD); } @Test public void insertModeTrue() throws XMLDBException { createCollection("/db/true"); - storeCollectionXconf("/db/system/config/db/true", xconf_yes); + storeCollectionXconf("/db/system/config/db/true", XCONF_YES); // namespace provided, valid document; should pass - storeDocument("/db/true", "valid.xml", valid); + storeDocument("/db/true", "valid.xml", VALID_XSD); // namespace provided, invalid document; should fail try { - storeDocument("/db/true", "invalid.xml", invalid); + storeDocument("/db/true", "invalid.xml", INVALID_XSD); fail("should have failed"); } catch (XMLDBException ex) { String msg = ex.getMessage(); - if (!msg.contains("cvc-complex-type.2.4.a: Invalid content was found")) { - fail(msg); - } + assertTrue(msg.contains("cvc-complex-type.2.4.a: Invalid content was found")); } // no namespace provided; should fail try { - storeDocument("/db/true", "anonymous.xml", anonymous); + storeDocument("/db/true", "anonymous.xml", ANONYMOUS_XSD); fail("should have failed"); } catch (XMLDBException ex) { String msg = ex.getMessage(); - if (!msg.contains("Cannot find the declaration of element 'schema'.")) { - fail(msg); - } + assertTrue(msg.contains("cvc-elt.1.a: Cannot find the declaration of element 'schema'.")); } - // non resolvable namespace provided, should fail try { - storeDocument("/db/true", "different.xml", different); + storeDocument("/db/true", "different.xml", DIFFERENT_XSD); fail("should have failed"); } catch (XMLDBException ex) { String msg = ex.getMessage(); - if (!msg.contains("schema_reference.4: Failed to read schema document")) { - fail(msg); - } + assertTrue(msg.contains("schema_reference.4: Failed to read schema document")); } - } @Test public void insertModeAuto() throws XMLDBException { createCollection("/db/auto"); - storeCollectionXconf("/db/system/config/db/auto", xconf_auto); + storeCollectionXconf("/db/system/config/db/auto", XCONF_AUTO); // namespace provided, valid document; should pass - storeDocument("/db/auto", "valid.xml", valid); - + storeDocument("/db/auto", "valid.xml", VALID_XSD); // namespace provided, invalid document, should fail try { - storeDocument("/db/auto", "invalid.xml", invalid); + storeDocument("/db/auto", "invalid.xml", INVALID_XSD); fail("should have failed"); } catch (XMLDBException ex) { String msg = ex.getMessage(); - if (!msg.contains("cvc-complex-type.2.4.a: Invalid content was found")) { - fail(msg); - } + assertTrue(msg.contains("cvc-complex-type.2.4.a: Invalid content was found")); } // no namespace reference, should pass - try { - storeDocument("/db/auto", "anonymous.xml", anonymous); - } catch (XMLDBException ex) { - String msg = ex.getMessage(); - if (!msg.contains("Cannot find the declaration of element 'schema'.")) { - fail(msg); - } - } + storeDocument("/db/auto", "anonymous.xml", ANONYMOUS_XSD); // non resolvable namespace provided, should fail try { - storeDocument("/db/auto", "different.xml", different); - fail("should have failed"); + storeDocument("/db/auto", "different.xml", DIFFERENT_XSD); } catch (XMLDBException ex) { String msg = ex.getMessage(); - if (!msg.contains("schema_reference.4: Failed to read schema document")) { - fail(msg); - } + assertTrue(msg.contains("schema_reference.4: Failed to read schema document")); } } } \ No newline at end of file diff --git a/exist-parent/pom.xml b/exist-parent/pom.xml index a8f2cee2404..5a6fcebf732 100644 --- a/exist-parent/pom.xml +++ b/exist-parent/pom.xml @@ -120,7 +120,7 @@ 1.8.1.3-jakarta5 2.1.3 9.9.1-8 - 5.2.3 + 6.0.11 2.10.0 4.13.2 1.11.4 @@ -855,6 +855,7 @@ JRE,CLDR,SPI ${project.build.testOutputDirectory}/log4j2.xml false + false From 8701ca3c512423a333166a09a1ca0e402d792347 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sat, 11 Jan 2025 23:40:24 +0100 Subject: [PATCH 2/3] Repair test --- .../validation/CollectionConfigurationValidationModeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java b/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java index 7cd5a55a69f..d5cb1252da1 100644 --- a/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java +++ b/exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java @@ -224,7 +224,7 @@ public void insertModeTrue() throws XMLDBException { fail("should have failed"); } catch (XMLDBException ex) { String msg = ex.getMessage(); - assertTrue(msg.contains("schema_reference.4: Failed to read schema document")); + assertTrue(msg.contains("cvc-elt.1.a: Cannot find the declaration of element 'xsd:schema'")); } } From a1090add422116f3b281ba2c13f0ea1f1fbf18f3 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sat, 11 Jan 2025 23:40:41 +0100 Subject: [PATCH 3/3] Set system property, see https://xmlresolver.org/ch06.html#xml.catalog.alwaysResolve --- exist-start/src/main/java/org/exist/start/Main.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exist-start/src/main/java/org/exist/start/Main.java b/exist-start/src/main/java/org/exist/start/Main.java index 22640f049ff..a9e1a5024aa 100644 --- a/exist-start/src/main/java/org/exist/start/Main.java +++ b/exist-start/src/main/java/org/exist/start/Main.java @@ -66,6 +66,7 @@ public class Main { public static final String STANDARD_ENABLED_JETTY_CONFIGS = "standard.enabled-jetty-configs"; public static final String STANDALONE_ENABLED_JETTY_CONFIGS = "standalone.enabled-jetty-configs"; public static final String PROP_LOG4J_DISABLEJMX = "log4j2.disableJmx"; + public static final String PROP_XML_CATALOG_ALWAYS_RESOLVE = "xml.catalog.alwaysResolve"; private static final int ERROR_CODE_GENERAL = 1; private static final int ERROR_CODE_NO_JETTY_CONFIG = 7; @@ -85,7 +86,6 @@ public class Main { public static final String ENV_EXIST_HOME = "EXIST_HOME"; public static final String ENV_JETTY_HOME = "JETTY_HOME"; - private static Main exist; private String _mode = "jetty"; @@ -274,6 +274,9 @@ public void runEx(String[] args) throws StartException { // Enable JXM support log4j since v2.24.0 [2024] System.setProperty(PROP_LOG4J_DISABLEJMX, "false"); + // Modify behavior XML resolver for > 5.x [2024] + System.setProperty(PROP_XML_CATALOG_ALWAYS_RESOLVE,"false"); + // clean up tempdir for Jetty... try { final Path tmpdir = Paths.get(System.getProperty(PROP_JAVA_TEMP_DIR)).toAbsolutePath();