Skip to content

Commit

Permalink
Merge pull request #5604 from dizzzz/library/upgrade_xmlresolver_ndw
Browse files Browse the repository at this point in the history
[library] bump version of xmlresolver to 6.0.x
  • Loading branch information
duncdrum authored Jan 13, 2025
2 parents f81dbba + a1090ad commit 9e32eca
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,14 +45,103 @@ public class CollectionConfigurationValidationModeTest {
@ClassRule
public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(false, true, true);

private static final String valid = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://jmvanel.free.fr/xsd/addressBook\" elementFormDefault=\"qualified\">" + "<xsd:attribute name=\"uselessAttribute\" type=\"xsd:string\"/>" + "<xsd:complexType name=\"record\">" + "<xsd:sequence>" + "<xsd:element name=\"cname\" type=\"xsd:string\"/>" + "<xsd:element name=\"email\" type=\"xsd:string\"/>" + "</xsd:sequence>" + "</xsd:complexType>" + "<xsd:element name=\"addressBook\">" + "<xsd:complexType>" + "<xsd:sequence>" + "<xsd:element name=\"owner\" type=\"record\"/>" + "<xsd:element name=\"person\" type=\"record\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>" + "</xsd:sequence>" + "</xsd:complexType>" + "</xsd:element>" + "</xsd:schema>";
private static final String invalid = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://jmvanel.free.fr/xsd/addressBook\" elementFormDefault=\"qualified\">" + "<xsd:attribute name=\"uselessAttribute\" type=\"xsd:string\"/>" + "<xsd:complexType name=\"record\">" + "<xsd:sequence>" + "<xsd:elementa name=\"cname\" type=\"xsd:string\"/>" + "<xsd:elementb name=\"email\" type=\"xsd:string\"/>" + "</xsd:sequence>" + "</xsd:complexType>" + "<xsd:element name=\"addressBook\">" + "<xsd:complexType>" + "<xsd:sequence>" + "<xsd:element name=\"owner\" type=\"record\"/>" + "<xsd:element name=\"person\" type=\"record\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>" + "</xsd:sequence>" + "</xsd:complexType>" + "</xsd:element>" + "</xsd:schema>";
private static final String anonymous = "<schema elementFormDefault=\"qualified\">" + "<attribute name=\"uselessAttribute\" type=\"string\"/>" + "<complexType name=\"record\">" + "<sequence>" + "<elementa name=\"cname\" type=\"string\"/>" + "<elementb name=\"email\" type=\"string\"/>" + "</sequence>" + "</complexType>" + "<element name=\"addressBook\">" + "<complexType>" + "<sequence>" + "<element name=\"owner\" type=\"record\"/>" + "<element name=\"person\" type=\"record\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>" + "</sequence>" + "</complexType>" + "</element>" + "</schema>";
private static final String different = "<asd:schema xmlns:asd=\"https://www.w3.org/2001/XMLSchemaschema\" targetNamespace=\"http://jmvanel.free.fr/xsd/addressBookbook\" elementFormDefault=\"qualified\">" + "<asd:attribute name=\"uselessAttribute\" type=\"asd:string\"/>" + "<asd:complexType name=\"record\">" + "<asd:sequence>" + "<asd:element name=\"cname\" type=\"asd:string\"/>" + "<asd:element name=\"email\" type=\"asd:string\"/>" + "</asd:sequence>" + "</asd:complexType>" + "<asd:element name=\"addressBook\">" + "<asd:complexType>" + "<asd:sequence>" + "<asd:element name=\"owner\" type=\"record\"/>" + "<asd:element name=\"person\" type=\"record\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>" + "</asd:sequence>" + "</asd:complexType>" + "</asd:element>" + "</asd:schema>";

private static final String xconf_yes = "<collection xmlns=\"http://exist-db.org/collection-config/1.0\"><validation mode=\"yes\"/></collection>";
private static final String xconf_no = "<collection xmlns=\"http://exist-db.org/collection-config/1.0\"><validation mode=\"no\"/></collection>";
private static final String xconf_auto = "<collection xmlns=\"http://exist-db.org/collection-config/1.0\"><validation mode=\"auto\"/></collection>";
private static final String VALID_XSD =
"""
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://jmvanel.free.fr/xsd/addressBook" elementFormDefault="qualified">
<xsd:attribute name="uselessAttribute" type="xsd:string"/>
<xsd:complexType name="record">
<xsd:sequence>
<xsd:element name="cname" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="addressBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="owner" type="record"/>
<xsd:element name="person" type="record" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
""";

private static final String INVALID_XSD = """
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://jmvanel.free.fr/xsd/addressBook" elementFormDefault="qualified">
<xsd:attribute name="uselessAttribute" type="xsd:string"/>
<xsd:complexType name="record">
<xsd:sequence>
<xsd:elementa name="cname" type="xsd:string"/>
<xsd:elementb name="email" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="addressBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="owner" type="record"/>
<xsd:element name="person" type="record" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
""";
private static final String ANONYMOUS_XSD = """
<schema elementFormDefault="qualified">
<attribute name="uselessAttribute" type="string"/>
<complexType name="record">
<sequence>
<elementa name="cname" type="string"/>
<elementb name="email" type="string"/>
</sequence>
</complexType>
<element name="addressBook">
<complexType>
<sequence>
<element name="owner" type="record"/>
<element name="person" type="record" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
""";

private static final String DIFFERENT_XSD = """
<xsd:schema xmlns:xsd="https://www.w3.org/2001/XMLSchemaschema"
targetNamespace="http://jmvanel.free.fr/xsd/addressBookbook" elementFormDefault="qualified">
<xsd:attribute name="uselessAttribute" type="xsd:string"/>
<xsd:complexType name="record">
<xsd:sequence>
<xsd:element name="cname" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="addressBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="owner" type="record"/>
<xsd:element name="person" type="record" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
""";
private static final String XCONF_YES = """
<collection xmlns="http://exist-db.org/collection-config/1.0">
<validation mode="yes"/>
</collection>
""";
private static final String XCONF_NO = """
<collection xmlns="http://exist-db.org/collection-config/1.0">
<validation mode="no"/>
</collection>
""";
private static final String XCONF_AUTO = """
<collection xmlns="http://exist-db.org/collection-config/1.0">
<validation mode="auto"/>
</collection>
""";

@AfterClass
public static void tearDownClass() throws Exception {
Expand Down Expand Up @@ -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("cvc-elt.1.a: Cannot find the declaration of element 'xsd:schema'"));
}

}

@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"));
}
}
}
3 changes: 2 additions & 1 deletion exist-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<milton.servlet.version>1.8.1.3-jakarta5</milton.servlet.version>
<nekohtml.version>2.1.3</nekohtml.version>
<saxon.version>9.9.1-8</saxon.version>
<xmlresolver.version>5.2.3</xmlresolver.version>
<xmlresolver.version>6.0.11</xmlresolver.version>
<xmlunit.version>2.10.0</xmlunit.version>
<junit.version>4.13.2</junit.version>
<junit.platform.version>1.11.4</junit.platform.version>
Expand Down Expand Up @@ -855,6 +855,7 @@
<java.locale.providers>JRE,CLDR,SPI</java.locale.providers>
<log4j.configurationFile>${project.build.testOutputDirectory}/log4j2.xml</log4j.configurationFile>
<log4j2.disableJmx>false</log4j2.disableJmx>
<xml.catalog.alwaysResolve>false</xml.catalog.alwaysResolve>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
5 changes: 4 additions & 1 deletion exist-start/src/main/java/org/exist/start/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9e32eca

Please sign in to comment.