From cb5317f7ca154e84280086839c5b2a3a5db0765b Mon Sep 17 00:00:00 2001 From: AliceXiaoLu Date: Mon, 15 Jan 2024 09:33:08 +0800 Subject: [PATCH] [bug] Exception when using host in ipv6 format (#14040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * DB2 edit again, no username. * [bug] db2's jdbcUrl should be like this "jdbc:db2://localhost:50000/sample:currentSchema=DB2INST1;characterEncoding=UTF-8;".should be ":" * Update Db2DataSourceProcessor.java * Update Db2DataSourceProcessorTest.java * 【Bug】OracleSource edit again, ConnectionType is null * when user inputs ipv6,checkhost will return "!IPV4_PATTERN.matcher(host).matches()"; I think we should use isInetAddress to check the host is isValid * Update AbstractDataSourceProcessor.java * Update DatabendDataSourceProcessorTest.java last week other modified this * Update MySQLDataSourceProcessorTest.java * Update DataSourceUtilsTest.java * Update MySQLDataSourceProcessorTest.java * Update KyuubiDataSourceProcessorTest.java * Update AbstractDataSourceProcessor.java if host is ipv6 or ipv4 will OK; if not check other * Update AbstractDataSourceProcessor.java * Update AbstractDataSourceProcessor.java * Update DataSourceUtilsTest.java 增加ipv6数据源验证 * [Bug] [dolphinscheduler-api] queryDataSource'password should be hidden. --------- Co-authored-by: xiangzihao <460888207@qq.com> Co-authored-by: Rick Cheng --- .../api/service/impl/DataSourceServiceImpl.java | 1 + .../datasource/AbstractDataSourceProcessor.java | 3 ++- .../mysql/utils/DataSourceUtilsTest.java | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java index 0ac7763ba7..a030762457 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java @@ -213,6 +213,7 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource baseDataSourceParamDTO.setId(dataSource.getId()); baseDataSourceParamDTO.setName(dataSource.getName()); baseDataSourceParamDTO.setNote(dataSource.getNote()); + baseDataSourceParamDTO.setPassword(getHiddenPassword()); return baseDataSourceParamDTO; } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/datasource/AbstractDataSourceProcessor.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/datasource/AbstractDataSourceProcessor.java index 856ae1c9e9..db357e9d5c 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/datasource/AbstractDataSourceProcessor.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/datasource/AbstractDataSourceProcessor.java @@ -69,7 +69,8 @@ public abstract class AbstractDataSourceProcessor implements DataSourceProcessor * @param host datasource host */ protected void checkHost(String host) { - if (!IPV4_PATTERN.matcher(host).matches() || !IPV6_PATTERN.matcher(host).matches()) { + if (com.google.common.net.InetAddresses.isInetAddress(host)) { + } else if (!IPV4_PATTERN.matcher(host).matches() || !IPV6_PATTERN.matcher(host).matches()) { throw new IllegalArgumentException("datasource host illegal"); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java index 71f1b77449..7f3133d170 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java @@ -47,7 +47,20 @@ public class DataSourceUtilsTest { @Test public void testCheckDatasourceParam() { MySQLDataSourceParamDTO mysqlDatasourceParamDTO = new MySQLDataSourceParamDTO(); - mysqlDatasourceParamDTO.setHost("localhost"); + mysqlDatasourceParamDTO.setHost("0.0.0.0"); + mysqlDatasourceParamDTO.setDatabase("default"); + Map other = new HashMap<>(); + other.put("serverTimezone", "Asia/Shanghai"); + other.put("queryTimeout", "-1"); + other.put("characterEncoding", "utf8"); + mysqlDatasourceParamDTO.setOther(other); + DataSourceUtils.checkDatasourceParam(mysqlDatasourceParamDTO); + Assertions.assertTrue(true); + } + @Test + public void testCheckIpv6DatasourceParam() { + MySQLDataSourceParamDTO mysqlDatasourceParamDTO = new MySQLDataSourceParamDTO(); + mysqlDatasourceParamDTO.setHost("0000:0000:0000::0000"); mysqlDatasourceParamDTO.setDatabase("default"); Map other = new HashMap<>(); other.put("serverTimezone", "Asia/Shanghai"); @@ -57,7 +70,6 @@ public class DataSourceUtilsTest { DataSourceUtils.checkDatasourceParam(mysqlDatasourceParamDTO); Assertions.assertTrue(true); } - @Test public void testBuildConnectionParams() { MySQLDataSourceParamDTO mysqlDatasourceParamDTO = new MySQLDataSourceParamDTO();