[java-metadata-aggregator] branch dev/MDA-299 updated: WIP: add host and port validators

Ian Young ian at iay.org.uk
Tue Jan 30 17:58:41 UTC 2024


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch dev/MDA-299
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=d729aa9c6f56f7c9091e640428d42fd6575dd106

The following commit(s) were added to refs/heads/dev/MDA-299 by this push:
     new d729aa9  WIP: add host and port validators
d729aa9 is described below

commit d729aa9c6f56f7c9091e640428d42fd6575dd106
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Jan 30 17:58:32 2024 +0000

    WIP: add host and port validators
---
 .../validate/url/EmptyPortURLValidator.java        | 44 ++++++++++++++++++++++
 .../validate/url/MissingHostURLValidator.java      | 41 ++++++++++++++++++++
 .../metadata/validate/url/package-info.java        | 20 ++++++++++
 .../resources/net/shibboleth/metadata/beans.xml    | 10 +++++
 .../string/AsURLStringValidatorLitmusTest.java     |  8 ++--
 .../validate/string/AsURLStringValidatorTest.java  | 28 +++-----------
 .../AsURLStringValidatorLitmusTest-config.xml      |  3 +-
 7 files changed, 126 insertions(+), 28 deletions(-)

diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/EmptyPortURLValidator.java b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/EmptyPortURLValidator.java
new file mode 100644
index 0000000..78955b1
--- /dev/null
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/EmptyPortURLValidator.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed 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 net.shibboleth.metadata.validate.url;
+
+import java.net.URL;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.pipeline.StageProcessingException;
+import net.shibboleth.metadata.validate.BaseValidator;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * Validates that a {@link URL} does not contain an empty port component.
+ */
+public class EmptyPortURLValidator extends BaseValidator implements Validator<URL> {
+
+    @Override
+    public @Nonnull Action validate(final @Nonnull URL url, final @Nonnull Item<?> item,
+            final @Nonnull String stageId) throws StageProcessingException {
+        final String authority = url.getAuthority();
+        if (authority != null) {
+            if (authority.charAt(authority.length() - 1) == ':') {
+                addError("libxml2: port present but empty", item, stageId);
+                return Action.DONE;
+            }
+        }
+        return Action.CONTINUE;
+    }
+
+}
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/MissingHostURLValidator.java b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/MissingHostURLValidator.java
new file mode 100644
index 0000000..b540795
--- /dev/null
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/MissingHostURLValidator.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed 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 net.shibboleth.metadata.validate.url;
+
+import java.net.URL;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.pipeline.StageProcessingException;
+import net.shibboleth.metadata.validate.BaseValidator;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * Validates that a {@link URL} has a host component.
+ */
+public class MissingHostURLValidator extends BaseValidator implements Validator<URL> {
+
+    @Override
+    public @Nonnull Action validate(final @Nonnull URL url, final @Nonnull Item<?> item,
+            final @Nonnull String stageId) throws StageProcessingException {
+        if ("".equals(url.getHost())) {
+            addError("host name not present", item, stageId);
+            return Action.DONE;
+        }
+        return Action.CONTINUE;
+    }
+
+}
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/package-info.java b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/package-info.java
new file mode 100644
index 0000000..1ee5c8c
--- /dev/null
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/validate/url/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Licensed 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.
+ */
+
+/**
+ * Validation classes for {@link java.net.URL} values.
+ *
+ * @since 0.10.0
+ */
+package net.shibboleth.metadata.validate.url;
diff --git a/mda-framework/src/main/resources/net/shibboleth/metadata/beans.xml b/mda-framework/src/main/resources/net/shibboleth/metadata/beans.xml
index 9e040c7..0a455df 100644
--- a/mda-framework/src/main/resources/net/shibboleth/metadata/beans.xml
+++ b/mda-framework/src/main/resources/net/shibboleth/metadata/beans.xml
@@ -347,6 +347,16 @@
     <bean id="mda.RejectStringValueValidator" abstract="true" parent="mda.validator_parent"
         class="net.shibboleth.metadata.validate.string.RejectStringValueValidator"/>
 
+    <!--
+        net.shibboleth.metadata.validate.url
+    -->
+
+    <bean id="mda.EmptyPortURLValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.url.EmptyPortURLValidator"/>
+    
+    <bean id="mda.MissingHostURLValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.url.MissingHostURLValidator"/>
+
     <!--
         net.shibboleth.metadata.validate.x509
     -->
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest.java
index 96e2115..ac696f4 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest.java
@@ -32,7 +32,7 @@ public class AsURLStringValidatorLitmusTest extends AbstractTestNGSpringContextT
         validator = makeValidator();
     }
 
-    /** Acquire the configured validator from the Spring context. */
+    // Acquire the configured validator from the Spring context.
     private AsURLStringValidator makeValidator() throws Exception {
         assert applicationContext != null;
         final AsURLStringValidator validator = applicationContext.getBean("litmusTest", AsURLStringValidator.class);
@@ -90,10 +90,10 @@ public class AsURLStringValidatorLitmusTest extends AbstractTestNGSpringContextT
          * This is valid by the specification, but is regarded as invalid by
          * libxml2's xs:anyURI checker.
          */
-        //bad("http://example.org:/example/");
+        bad("http://example.org:/example/");
         
         // Doubled scheme looks like empty port field
-        //bad("http://http://example.org/example/");
+        bad("http://http://example.org/example/");
         
         // Bare domain
         bad("www.example.org");
@@ -102,7 +102,7 @@ public class AsURLStringValidatorLitmusTest extends AbstractTestNGSpringContextT
         bad("");
         
         // Missing authority caused by extra slash
-        //bad("http:///foo/");
+        bad("http:///foo/");
         
         // Import transform artifact
         bad("http://*** FILL IN ***/");
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java
index f26515e..2fc812f 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java
@@ -18,6 +18,8 @@ public class AsURLStringValidatorTest {
     /**
      * Generic test for a good URL.
      *
+     * @param value the URL to be tested, as a string
+     * @return the URL
      * @throws Exception if something goes wrong
      */
     private @Nonnull URL good(@Nonnull final String value) throws Exception {
@@ -49,7 +51,9 @@ public class AsURLStringValidatorTest {
     /**
      * Generic test for a bad URL.
      * 
-     * @param bad   bad URL to test
+     * @param value bad URL to test
+     * @return an {@link ErrorStatus} resulting from the validation
+     * @throws Exception if something goes wrong
      */
     private @Nonnull ErrorStatus badURL(@Nonnull String value) throws Exception {
         final var item = new MockItem("item");
@@ -72,23 +76,6 @@ public class AsURLStringValidatorTest {
         badURL(bad);
     }
 
-    
-    /**
-     * Test the case where the authority's port field is present but empty.
-     * 
-     * This is valid by the specification, but is regarded as invalid by
-     * libxml2's xs:anyURI checker.
-     */
-//    @Test
-//    public void testEmptyPort() throws Exception {
-//        badURL("http://example.org:/example/");
-//    }
-    
-//    @Test
-//    public void testDoubleScheme() throws Exception {
-//        badURL("http://http://example.org/example/");
-//    }
-    
     @Test
     public void testBareDomain() throws Exception {
         badURL("www.example.org");
@@ -99,11 +86,6 @@ public class AsURLStringValidatorTest {
         badURL("");
     }
 
-//    @Test
-//    public void testEmptyAuthority() throws Exception {
-//        badURL("http:///foo/");
-//    }
-    
     @Test
     public void testFillInHostName() throws Exception {
         badURL("http://*** FILL IN ***/");
diff --git a/mda-framework/src/test/resources/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest-config.xml b/mda-framework/src/test/resources/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest-config.xml
index 9d8f920..1daf6f0 100644
--- a/mda-framework/src/test/resources/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest-config.xml
+++ b/mda-framework/src/test/resources/net/shibboleth/metadata/validate/string/AsURLStringValidatorLitmusTest-config.xml
@@ -15,7 +15,8 @@
     <bean id="litmusTest" parent="mda.AsURLStringValidator">
         <property name="validators">
             <list>
-                <!-- URL validators go here -->
+                <bean id="host" parent="mda.MissingHostURLValidator"/>
+                <bean id="port" parent="mda.EmptyPortURLValidator"/>
             </list>
         </property>
     </bean>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list