From 59dacdcbe30902d35e00cc4e16952568f9be0909 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:14:17 -0700 Subject: [PATCH] Removed Domain Validation (#2130) (#2136) (cherry picked from commit fe80b5c74281fc1b27366f42a5938558aa9b0938) Signed-off-by: Vamsi Manohar Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../utils/DatasourceValidationUtils.java | 13 ------ .../utils/DatasourceValidationUtilsTest.java | 14 ------ .../sql/datasource/DataSourceAPIsIT.java | 20 --------- .../storage/PrometheusStorageFactoryTest.java | 44 ------------------- 4 files changed, 91 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/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java index e1d071d522..c2857a2bc1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java @@ -112,26 +112,6 @@ public void updateDataSourceAPITest() { // Datasource is not immediately updated. so introducing a sleep of 2s. Thread.sleep(2000); - // update datasource with invalid URI - updateDSM = - new DataSourceMetadata( - "update_prometheus", - DataSourceType.PROMETHEUS, - ImmutableList.of(), - ImmutableMap.of("prometheus.uri", "https://randomtest:9090")); - final Request illFormedUpdateRequest = getUpdateDataSourceRequest(updateDSM); - ResponseException updateResponseException = - Assert.assertThrows( - ResponseException.class, () -> client().performRequest(illFormedUpdateRequest)); - Assert.assertEquals(400, updateResponseException.getResponse().getStatusLine().getStatusCode()); - updateResponseString = getResponseBody(updateResponseException.getResponse()); - JsonObject errorMessage = new Gson().fromJson(updateResponseString, JsonObject.class); - Assert.assertEquals( - "Invalid hostname in the uri: https://randomtest:9090", - errorMessage.get("error").getAsJsonObject().get("details").getAsString()); - - Thread.sleep(2000); - // get datasource to validate the modification. // get datasource Request getRequest = getFetchDataSourceRequest("update_prometheus"); 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))