This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new 4e03ebfc1 Test that STANDALONE configuration doesn't fetch external
resources
4e03ebfc1 is described below
commit 4e03ebfc14a29c43a0eabc40587a09bf5246df7e
Author: Claude <[email protected]>
AuthorDate: Wed Nov 11 07:19:26 2026 +0000
Test that STANDALONE configuration doesn't fetch external resources
Add two dialect tests that run against every StAX implementation and use
DummyHTTPServer to assert that a parser configured with
StAXParserConfiguration.STANDALONE never attempts to load an external DTD
subset or an external parsed entity.
Note that Woodstox rejects references to external parsed entities with an
exception instead of replacing them with empty content; the test accepts
both outcomes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01F8HaVVneQSFiq7x8Zq28wr
---
.../axiom/util/stax/dialect/DialectTestSuite.java | 2 +
...tStandaloneConfigurationWithExternalEntity.java | 71 ++++++++++++++++++++++
...tStandaloneConfigurationWithExternalSubset.java | 60 ++++++++++++++++++
3 files changed, 133 insertions(+)
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
index 6f5923c3c..bc4d5a0ca 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
@@ -234,6 +234,8 @@ public class DialectTestSuite {
new MatrixTest(TestIsStandalone.class),
new MatrixTest(TestNextAfterEndDocument.class),
new MatrixTest(TestSetPrefixScope.class),
+ new
MatrixTest(TestStandaloneConfigurationWithExternalEntity.class),
+ new
MatrixTest(TestStandaloneConfigurationWithExternalSubset.class),
new MatrixTest(TestStandaloneSet.class),
new
MatrixTest(TestWriteStartDocumentWithNullEncoding.class)));
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalEntity.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalEntity.java
new file mode 100644
index 000000000..4fae199f5
--- /dev/null
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalEntity.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.StringReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+
+/**
+ * Tests that a parser configured with {@link
StAXParserConfiguration#STANDALONE} never attempts to
+ * load an external parsed entity. Depending on the parser, the entity
reference is either replaced
+ * by empty content or rejected with an exception (Woodstox); both outcomes
are acceptable.
+ */
+public class TestStandaloneConfigurationWithExternalEntity extends
DialectTestCase {
+ @Override
+ public void execute() throws Throwable {
+ XMLInputFactory factory = StAXParserConfiguration.STANDALONE.configure(
+ staxImpl.newNormalizedXMLInputFactory(),
staxImpl.getDialect());
+ DummyHTTPServer server = new DummyHTTPServer();
+ server.start();
+ try {
+ StringBuilder text = new StringBuilder();
+ boolean gotException = false;
+ try {
+ XMLStreamReader reader = factory.createXMLStreamReader(new
StringReader("<?xml version='1.0'?>"
+ + "<!DOCTYPE root [<!ENTITY ext SYSTEM '" +
server.getBaseURL() + "entity.xml'>]>"
+ + "<root>a&ext;b</root>"));
+ try {
+ while (reader.hasNext()) {
+ if (reader.next() == XMLStreamConstants.CHARACTERS) {
+ text.append(reader.getText());
+ }
+ }
+ } finally {
+ reader.close();
+ }
+ } catch (XMLStreamException | RuntimeException ex) {
+ gotException = true;
+ }
+ // Assert that the parser didn't try to load the external entity
+ assertThat(server.isRequestReceived()).isFalse();
+ if (!gotException) {
+ // The reference to the external entity must have been
replaced by empty content
+ assertThat(text.toString()).isEqualTo("ab");
+ }
+ } finally {
+ server.stop();
+ }
+ }
+}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalSubset.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalSubset.java
new file mode 100644
index 000000000..6e7b71a9d
--- /dev/null
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneConfigurationWithExternalSubset.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.StringReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+
+/**
+ * Tests that a parser configured with {@link
StAXParserConfiguration#STANDALONE} processes a
+ * document with an external DTD subset without attempting to load that subset.
+ */
+public class TestStandaloneConfigurationWithExternalSubset extends
DialectTestCase {
+ @Override
+ public void execute() throws Throwable {
+ XMLInputFactory factory = StAXParserConfiguration.STANDALONE.configure(
+ staxImpl.newNormalizedXMLInputFactory(),
staxImpl.getDialect());
+ DummyHTTPServer server = new DummyHTTPServer();
+ server.start();
+ try {
+ XMLStreamReader reader = factory.createXMLStreamReader(new
StringReader(
+ "<?xml version='1.0'?><!DOCTYPE root SYSTEM '" +
server.getBaseURL() + "dummy.dtd'><root/>"));
+ boolean reachedDocumentElement = false;
+ try {
+ while (reader.hasNext()) {
+ if (reader.next() == XMLStreamConstants.START_ELEMENT) {
+ reachedDocumentElement = true;
+ }
+ }
+ } finally {
+ reader.close();
+ }
+ assertThat(reachedDocumentElement).isTrue();
+ // Assert that the parser didn't try to load the external DTD
subset
+ assertThat(server.isRequestReceived()).isFalse();
+ } finally {
+ server.stop();
+ }
+ }
+}