Tboy
5 years ago
committed by
GitHub
39 changed files with 1361 additions and 254 deletions
@ -0,0 +1,130 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 org.apache.dolphinscheduler.common.utils; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.commons.lang.time.DateUtils; |
||||||
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
||||||
|
import org.apache.dolphinscheduler.common.enums.DataType; |
||||||
|
import org.apache.dolphinscheduler.common.enums.Direct; |
||||||
|
import org.apache.dolphinscheduler.common.process.Property; |
||||||
|
import org.apache.dolphinscheduler.common.utils.placeholder.PlaceholderUtils; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import java.util.*; |
||||||
|
import static org.apache.dolphinscheduler.common.Constants.PARAMETER_FORMAT_TIME; |
||||||
|
import static org.apache.dolphinscheduler.common.utils.placeholder.TimePlaceholderUtils.replacePlaceholders; |
||||||
|
|
||||||
|
|
||||||
|
public class ParameterUtilsTest { |
||||||
|
public static final Logger logger = LoggerFactory.getLogger(ParameterUtilsTest.class); |
||||||
|
|
||||||
|
/** |
||||||
|
* Test convertParameterPlaceholders |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testConvertParameterPlaceholders() throws Exception { |
||||||
|
// parameterString,parameterMap is null
|
||||||
|
Assert.assertNull(ParameterUtils.convertParameterPlaceholders(null, null)); |
||||||
|
|
||||||
|
// parameterString is null,parameterMap is not null
|
||||||
|
Map<String, String> parameterMap = new HashMap<String,String>(); |
||||||
|
parameterMap.put("testParameter","testParameter"); |
||||||
|
Assert.assertNull(ParameterUtils.convertParameterPlaceholders(null, parameterMap)); |
||||||
|
|
||||||
|
// parameterString、parameterMap is not null
|
||||||
|
String parameterString = "test_parameter"; |
||||||
|
Assert.assertEquals(parameterString, ParameterUtils.convertParameterPlaceholders(parameterString, parameterMap)); |
||||||
|
|
||||||
|
//replace variable ${} form
|
||||||
|
parameterMap.put("testParameter2","${testParameter}"); |
||||||
|
Assert.assertEquals(parameterString,PlaceholderUtils.replacePlaceholders(parameterString, parameterMap, true)); |
||||||
|
|
||||||
|
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||||
|
Date cronTime = new Date(); |
||||||
|
Assert.assertEquals(parameterString, replacePlaceholders(parameterString, cronTime, true)); |
||||||
|
|
||||||
|
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||||
|
Date cronTimeStr = DateUtils.parseDate("20191220145900", new String[]{PARAMETER_FORMAT_TIME}); |
||||||
|
Assert.assertEquals(parameterString, replacePlaceholders(parameterString, cronTimeStr, true)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Test curingGlobalParams |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testCuringGlobalParams() throws Exception { |
||||||
|
//define globalMap
|
||||||
|
Map<String, String> globalParamMap = new HashMap<>(); |
||||||
|
globalParamMap.put("globalParams1","Params1"); |
||||||
|
|
||||||
|
//define globalParamList
|
||||||
|
List<Property> globalParamList = new ArrayList<>(); |
||||||
|
|
||||||
|
//define scheduleTime
|
||||||
|
Date scheduleTime = DateUtils.parseDate("20191220145900", new String[]{PARAMETER_FORMAT_TIME}); |
||||||
|
|
||||||
|
//test globalParamList is null
|
||||||
|
String result = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, CommandType.START_CURRENT_TASK_PROCESS, scheduleTime); |
||||||
|
Assert.assertNull(result); |
||||||
|
Assert.assertNull(ParameterUtils.curingGlobalParams(null,null,CommandType.START_CURRENT_TASK_PROCESS,null)); |
||||||
|
Assert.assertNull(ParameterUtils.curingGlobalParams(globalParamMap,null,CommandType.START_CURRENT_TASK_PROCESS,scheduleTime)); |
||||||
|
|
||||||
|
//test globalParamList is not null
|
||||||
|
Property property=new Property("testGlobalParam", Direct.IN, DataType.VARCHAR,"testGlobalParam"); |
||||||
|
globalParamList.add(property); |
||||||
|
|
||||||
|
String result2 = ParameterUtils.curingGlobalParams(null,globalParamList,CommandType.START_CURRENT_TASK_PROCESS,scheduleTime); |
||||||
|
Assert.assertEquals(result2, JSONObject.toJSONString(globalParamList)); |
||||||
|
|
||||||
|
String result3 = ParameterUtils.curingGlobalParams(globalParamMap,globalParamList,CommandType.START_CURRENT_TASK_PROCESS,null); |
||||||
|
Assert.assertEquals(result3, JSONObject.toJSONString(globalParamList)); |
||||||
|
|
||||||
|
String result4 = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, CommandType.START_CURRENT_TASK_PROCESS, scheduleTime); |
||||||
|
Assert.assertEquals(result4, JSONObject.toJSONString(globalParamList)); |
||||||
|
|
||||||
|
//test var $ startsWith
|
||||||
|
globalParamMap.put("bizDate","${system.biz.date}"); |
||||||
|
globalParamMap.put("b1zCurdate","${system.biz.curdate}"); |
||||||
|
|
||||||
|
|
||||||
|
Property property2=new Property("testParamList1", Direct.IN, DataType.VARCHAR,"testParamList"); |
||||||
|
Property property3=new Property("testParamList2", Direct.IN, DataType.VARCHAR,"{testParamList1}"); |
||||||
|
Property property4=new Property("testParamList3", Direct.IN, DataType.VARCHAR,"${b1zCurdate}"); |
||||||
|
|
||||||
|
globalParamList.add(property2); |
||||||
|
globalParamList.add(property3); |
||||||
|
globalParamList.add(property4); |
||||||
|
|
||||||
|
String result5 = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, CommandType.START_CURRENT_TASK_PROCESS, scheduleTime); |
||||||
|
Assert.assertEquals(result5,JSONUtils.toJsonString(globalParamList)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Test handleEscapes |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testHandleEscapes() throws Exception { |
||||||
|
Assert.assertNull(ParameterUtils.handleEscapes(null)); |
||||||
|
Assert.assertEquals("",ParameterUtils.handleEscapes("")); |
||||||
|
Assert.assertEquals("test Parameter",ParameterUtils.handleEscapes("test Parameter")); |
||||||
|
Assert.assertEquals("////%test////%Parameter",ParameterUtils.handleEscapes("%test%Parameter")); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,236 @@ |
|||||||
|
<!-- |
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
~ contributor license agreements. See the NOTICE file distributed with |
||||||
|
~ this work for additional information regarding copyright ownership. |
||||||
|
~ The ASF licenses this file to You 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. |
||||||
|
--> |
||||||
|
|
||||||
|
<assembly |
||||||
|
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> |
||||||
|
<id>dolphinscheduler-nginx</id> |
||||||
|
<formats> |
||||||
|
<format>tar.gz</format> |
||||||
|
</formats> |
||||||
|
<includeBaseDirectory>true</includeBaseDirectory> |
||||||
|
<baseDirectory>${project.build.finalName}-dolphinscheduler-bin</baseDirectory> |
||||||
|
|
||||||
|
<fileSets> |
||||||
|
<!--alert start--> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-alert/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
<include>**/*.ftl</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<!--alert end--> |
||||||
|
|
||||||
|
<!--api start--> |
||||||
|
<fileSet> |
||||||
|
<directory>src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-common/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-common/src/main/resources/bin</directory> |
||||||
|
<includes> |
||||||
|
<include>*.*</include> |
||||||
|
</includes> |
||||||
|
<directoryMode>755</directoryMode> |
||||||
|
<outputDirectory>bin</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-dao/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-api/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<!--api end--> |
||||||
|
|
||||||
|
<!--server start--> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-server/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
<include>config/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-common/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-common/src/main/resources/bin</directory> |
||||||
|
<includes> |
||||||
|
<include>*.*</include> |
||||||
|
</includes> |
||||||
|
<directoryMode>755</directoryMode> |
||||||
|
<outputDirectory>bin</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-dao/src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.properties</include> |
||||||
|
<include>**/*.xml</include> |
||||||
|
<include>**/*.json</include> |
||||||
|
<include>**/*.yml</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
<!--server end--> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-server/target/dolphinscheduler-server-${project.version}</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>.</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-api/target/dolphinscheduler-api-${project.version}</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>.</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-alert/target/dolphinscheduler-alert-${project.version}</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>.</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-ui/dist</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./ui/dist</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../dolphinscheduler-ui</directory> |
||||||
|
<includes> |
||||||
|
<include>install-dolphinscheduler-ui.sh</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./ui</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../sql</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./sql</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../script</directory> |
||||||
|
<includes> |
||||||
|
<include>*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./script</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../script</directory> |
||||||
|
<includes> |
||||||
|
<include>env/*.*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./conf</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/../script</directory> |
||||||
|
<includes> |
||||||
|
<include>start-all.sh</include> |
||||||
|
<include>stop-all.sh</include> |
||||||
|
<include>dolphinscheduler-daemon.sh</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>./bin</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/.././</directory> |
||||||
|
<includes> |
||||||
|
<include>*.sh</include> |
||||||
|
<include>*.py</include> |
||||||
|
<include>DISCLAIMER</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>.</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
<fileSet> |
||||||
|
<directory>${basedir}/release-docs</directory> |
||||||
|
<useDefaultExcludes>true</useDefaultExcludes> |
||||||
|
<includes> |
||||||
|
<include>**/*</include> |
||||||
|
</includes> |
||||||
|
<outputDirectory>.</outputDirectory> |
||||||
|
</fileSet> |
||||||
|
|
||||||
|
</fileSets> |
||||||
|
|
||||||
|
<dependencySets> |
||||||
|
<dependencySet> |
||||||
|
<outputDirectory>lib</outputDirectory> |
||||||
|
<useProjectArtifact>true</useProjectArtifact> |
||||||
|
<excludes> |
||||||
|
<exclude>javax.servlet:servlet-api</exclude> |
||||||
|
<exclude>org.eclipse.jetty.aggregate:jetty-all</exclude> |
||||||
|
<exclude>org.slf4j:slf4j-log4j12</exclude> |
||||||
|
</excludes> |
||||||
|
</dependencySet> |
||||||
|
</dependencySets> |
||||||
|
</assembly> |
@ -0,0 +1,92 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 org.apache.dolphinscheduler.server.worker.log; |
||||||
|
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.pattern.MessageConverter; |
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.server.utils.SensitiveLogUtil; |
||||||
|
|
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* sensitive data log converter |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
public class SensitiveDataConverter extends MessageConverter { |
||||||
|
|
||||||
|
/** |
||||||
|
* password pattern |
||||||
|
*/ |
||||||
|
private final Pattern pwdPattern = Pattern.compile(Constants.DATASOURCE_PASSWORD_REGEX); |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public String convert(ILoggingEvent event) { |
||||||
|
|
||||||
|
// get original log
|
||||||
|
String requestLogMsg = event.getFormattedMessage(); |
||||||
|
|
||||||
|
// desensitization log
|
||||||
|
return convertMsg(requestLogMsg); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* deal with sensitive log |
||||||
|
* |
||||||
|
* @param oriLogMsg original log |
||||||
|
*/ |
||||||
|
private String convertMsg(final String oriLogMsg) { |
||||||
|
|
||||||
|
String tempLogMsg = oriLogMsg; |
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(tempLogMsg)) { |
||||||
|
tempLogMsg = passwordHandler(pwdPattern, tempLogMsg); |
||||||
|
} |
||||||
|
return tempLogMsg; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* password regex |
||||||
|
* |
||||||
|
* @param logMsg original log |
||||||
|
*/ |
||||||
|
private String passwordHandler(Pattern pwdPattern, String logMsg) { |
||||||
|
|
||||||
|
Matcher matcher = pwdPattern.matcher(logMsg); |
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer(logMsg.length()); |
||||||
|
|
||||||
|
while (matcher.find()) { |
||||||
|
|
||||||
|
String password = matcher.group(); |
||||||
|
|
||||||
|
String maskPassword = SensitiveLogUtil.maskDataSourcePwd(password); |
||||||
|
|
||||||
|
matcher.appendReplacement(sb, maskPassword); |
||||||
|
} |
||||||
|
matcher.appendTail(sb); |
||||||
|
|
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 org.apache.dolphinscheduler.server.utils; |
||||||
|
|
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
|
||||||
|
public class SensitiveLogUtilTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testMaskDataSourcePwd() { |
||||||
|
|
||||||
|
String password = "123456"; |
||||||
|
String emptyPassword = ""; |
||||||
|
|
||||||
|
Assert.assertEquals(Constants.PASSWORD_DEFAULT, SensitiveLogUtil.maskDataSourcePwd(password)); |
||||||
|
Assert.assertEquals("", SensitiveLogUtil.maskDataSourcePwd(emptyPassword)); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,92 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 org.apache.dolphinscheduler.server.worker.log; |
||||||
|
|
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.server.utils.SensitiveLogUtil; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
public class SensitiveDataConverterTest { |
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(SensitiveDataConverterTest.class); |
||||||
|
|
||||||
|
/** |
||||||
|
* password pattern |
||||||
|
*/ |
||||||
|
private final Pattern pwdPattern = Pattern.compile(Constants.DATASOURCE_PASSWORD_REGEX); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* mask sensitive logMsg - sql task datasource password |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void testPwdLogMsgConverter() { |
||||||
|
|
||||||
|
String logMsg = "{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," + |
||||||
|
"\"database\":\"carbond\"," + |
||||||
|
"\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," + |
||||||
|
"\"user\":\"view\"," + |
||||||
|
"\"password\":\"view1\"}"; |
||||||
|
|
||||||
|
String maskLogMsg = "{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," + |
||||||
|
"\"database\":\"carbond\"," + |
||||||
|
"\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," + |
||||||
|
"\"user\":\"view\"," + |
||||||
|
"\"password\":\"******\"}"; |
||||||
|
|
||||||
|
|
||||||
|
logger.info("parameter : {}", logMsg); |
||||||
|
logger.info("parameter : {}", passwordHandler(pwdPattern, logMsg)); |
||||||
|
|
||||||
|
Assert.assertNotEquals(logMsg, passwordHandler(pwdPattern, logMsg)); |
||||||
|
Assert.assertEquals(maskLogMsg, passwordHandler(pwdPattern, logMsg)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* password regex test |
||||||
|
* |
||||||
|
* @param logMsg original log |
||||||
|
*/ |
||||||
|
private static String passwordHandler(Pattern pattern, String logMsg) { |
||||||
|
|
||||||
|
Matcher matcher = pattern.matcher(logMsg); |
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer(logMsg.length()); |
||||||
|
|
||||||
|
while (matcher.find()) { |
||||||
|
|
||||||
|
String password = matcher.group(); |
||||||
|
|
||||||
|
String maskPassword = SensitiveLogUtil.maskDataSourcePwd(password); |
||||||
|
|
||||||
|
matcher.appendReplacement(sb, maskPassword); |
||||||
|
} |
||||||
|
matcher.appendTail(sb); |
||||||
|
|
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue