From b47e119c5331ffe82c18d6c7a550f1969c66c695 Mon Sep 17 00:00:00 2001 From: Vamsi Manohar Date: Thu, 21 Sep 2023 16:53:50 -0700 Subject: [PATCH] Removed Domain Validation Signed-off-by: Vamsi Manohar --- .../utils/DatasourceValidationUtils.java | 13 ------ .../utils/DatasourceValidationUtilsTest.java | 14 ------ .../storage/PrometheusStorageFactoryTest.java | 44 ------------------- 3 files changed, 71 deletions(-) diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtils.java b/datasources/src/main/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtils.java index ba7458d0b4..e779e8e04d 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtils.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtils.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Set; import lombok.experimental.UtilityClass; -import org.apache.commons.validator.routines.DomainValidator; import org.opensearch.sql.common.utils.URIValidationUtils; /** Common Validation methods for all datasource connectors. */ @@ -19,7 +18,6 @@ public class DatasourceValidationUtils { public static void validateHost(String uriString, List denyHostList) throws URISyntaxException, UnknownHostException { - validateDomain(uriString); if (!URIValidationUtils.validateURIHost(new URI(uriString).getHost(), denyHostList)) { throw new IllegalArgumentException( "Disallowed hostname in the uri. " @@ -54,15 +52,4 @@ public static void validateLengthAndRequiredFields( throw new IllegalArgumentException(errorStringBuilder.toString()); } } - - private static void validateDomain(String uriString) throws URISyntaxException { - URI uri = new URI(uriString); - String host = uri.getHost(); - if (host == null - || (!(DomainValidator.getInstance().isValid(host) - || DomainValidator.getInstance().isValidLocalTld(host)))) { - throw new IllegalArgumentException( - String.format("Invalid hostname in the uri: %s", uriString)); - } - } } diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java index 836c61f647..15e921e72a 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java @@ -37,20 +37,6 @@ public void testValidateHostWithSuccess() { "http://localhost:9090", Collections.singletonList("192.168.0.0/8"))); } - @SneakyThrows - @Test - public void testValidateHostWithInvalidDomain() { - IllegalArgumentException illegalArgumentException = - Assertions.assertThrows( - IllegalArgumentException.class, - () -> - DatasourceValidationUtils.validateHost( - "http:://prometheus:9090", Collections.singletonList("127.0.0.0/8"))); - Assertions.assertEquals( - "Invalid hostname in the uri: http:://prometheus:9090", - illegalArgumentException.getMessage()); - } - @Test public void testValidateLengthAndRequiredFieldsWithAbsentField() { HashMap config = new HashMap<>(); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java index 46658699ca..41d439d120 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java @@ -209,50 +209,6 @@ void createDataSourceSuccessWithLocalhost() { Assertions.assertTrue(dataSource.getStorageEngine() instanceof PrometheusStorageEngine); } - @Test - void createDataSourceWithInvalidHostname() { - HashMap properties = new HashMap<>(); - properties.put("prometheus.uri", "http://dummyprometheus:9090"); - properties.put("prometheus.auth.type", "basicauth"); - properties.put("prometheus.auth.username", "admin"); - properties.put("prometheus.auth.password", "admin"); - - DataSourceMetadata metadata = new DataSourceMetadata(); - metadata.setName("prometheus"); - metadata.setConnector(DataSourceType.PROMETHEUS); - metadata.setProperties(properties); - - PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); - RuntimeException exception = - Assertions.assertThrows( - RuntimeException.class, () -> prometheusStorageFactory.createDataSource(metadata)); - Assertions.assertTrue( - exception - .getMessage() - .contains("Invalid hostname in the uri: http://dummyprometheus:9090")); - } - - @Test - void createDataSourceWithInvalidIp() { - HashMap properties = new HashMap<>(); - properties.put("prometheus.uri", "http://231.54.11.987:9090"); - properties.put("prometheus.auth.type", "basicauth"); - properties.put("prometheus.auth.username", "admin"); - properties.put("prometheus.auth.password", "admin"); - - DataSourceMetadata metadata = new DataSourceMetadata(); - metadata.setName("prometheus"); - metadata.setConnector(DataSourceType.PROMETHEUS); - metadata.setProperties(properties); - - PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); - RuntimeException exception = - Assertions.assertThrows( - RuntimeException.class, () -> prometheusStorageFactory.createDataSource(metadata)); - Assertions.assertTrue( - exception.getMessage().contains("Invalid hostname in the uri: http://231.54.11.987:9090")); - } - @Test void createDataSourceWithHostnameNotMatchingWithAllowHostsConfig() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST))