gnodet commented on code in PR #13882:
URL: https://github.com/apache/maven/pull/13882#discussion_r4592897449
##########
impl/maven-support/src/test/java/org/apache/maven/model/v4/MavenStaxReaderTest.java:
##########
@@ -281,6 +283,69 @@ void testLocationReportingForListElements() throws
Exception {
assertEquals(5, module3Location.getColumnNumber(), "Module 3 should
start at column 5");
}
+ @Test
+ void testRandomRootNamespaceIsRejectedInStrictMode() {
+ // https://github.com/apache/maven/issues/10985
+ String xml = pomWithNamespace("https://ff.com");
+
+ XMLStreamException ex = assertThrows(XMLStreamException.class, () ->
fromXml(xml));
+ assertTrue(
+ ex.getMessage().contains("Unrecognized namespace
'https://ff.com' for root element 'project'"),
+ ex.getMessage());
+
assertTrue(ex.getMessage().contains("http://maven.apache.org/POM/4.0.0"),
ex.getMessage());
+ assertNotNull(ex.getLocation());
+ assertEquals(1, ex.getLocation().getLineNumber());
+ }
+
+ @Test
+ void testUnknownRootNamespacesAreRejectedInStrictMode() {
+ assertAll(Stream.of(
Review Comment:
Parameterized junit tests would be better here.
##########
impl/maven-support/src/test/java/org/apache/maven/model/v4/MavenStaxReaderTest.java:
##########
@@ -281,6 +283,69 @@ void testLocationReportingForListElements() throws
Exception {
assertEquals(5, module3Location.getColumnNumber(), "Module 3 should
start at column 5");
}
+ @Test
+ void testRandomRootNamespaceIsRejectedInStrictMode() {
+ // https://github.com/apache/maven/issues/10985
+ String xml = pomWithNamespace("https://ff.com");
+
+ XMLStreamException ex = assertThrows(XMLStreamException.class, () ->
fromXml(xml));
+ assertTrue(
+ ex.getMessage().contains("Unrecognized namespace
'https://ff.com' for root element 'project'"),
+ ex.getMessage());
+
assertTrue(ex.getMessage().contains("http://maven.apache.org/POM/4.0.0"),
ex.getMessage());
+ assertNotNull(ex.getLocation());
+ assertEquals(1, ex.getLocation().getLineNumber());
+ }
+
+ @Test
+ void testUnknownRootNamespacesAreRejectedInStrictMode() {
+ assertAll(Stream.of(
+ // only exact matches are accepted, no prefix matching
+ "http://maven.apache.org/POM/",
+ "http://maven.apache.org/POM/4.0",
+ "http://maven.apache.org/POM/4.0.0/",
+ "http://maven.apache.org/POM/9.9.9",
+ // namespaces are case-sensitive and the scheme is
part of the namespace name
+ "https://maven.apache.org/POM/4.0.0",
+ "http://maven.apache.org/pom/4.0.0",
+ // namespaces of other Maven models are not valid for
a POM
+ "http://maven.apache.org/METADATA/1.1.0",
+ "http://maven.apache.org/SETTINGS/1.0.0")
+ .map(ns -> () -> {
+ XMLStreamException ex =
+ assertThrows(XMLStreamException.class, () ->
fromXml(pomWithNamespace(ns)), ns);
+ assertTrue(ex.getMessage().contains("Unrecognized
namespace '" + ns + "'"), ex.getMessage());
+ }));
+ }
+
+ @Test
+ void testKnownRootNamespacesAreAcceptedInStrictMode() {
+ assertAll(Stream.of(
Review Comment:
Parameterized junit tests would be better here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]