|
|
@ -19,6 +19,8 @@ package org.apache.dolphinscheduler.common.log; |
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.common.constants.Constants.K8S_CONFIG_REGEX; |
|
|
|
import static org.apache.dolphinscheduler.common.constants.Constants.K8S_CONFIG_REGEX; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
@ -28,30 +30,61 @@ public class SensitiveDataConverterTest { |
|
|
|
|
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(SensitiveDataConverterTest.class); |
|
|
|
private final Logger logger = LoggerFactory.getLogger(SensitiveDataConverterTest.class); |
|
|
|
|
|
|
|
|
|
|
|
private final String logMsg = "{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," |
|
|
|
/** |
|
|
|
|
|
|
|
* mask sensitive logMsg - sql task datasource password |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testPwdLogMsgConverter() { |
|
|
|
|
|
|
|
HashMap<String, String> tcs = new HashMap<>(); |
|
|
|
|
|
|
|
tcs.put("{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," |
|
|
|
+ "\"database\":\"carbond\"," |
|
|
|
+ "\"database\":\"carbond\"," |
|
|
|
+ "\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," |
|
|
|
+ "\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," |
|
|
|
+ "\"user\":\"view\"," |
|
|
|
+ "\"user\":\"view\"," |
|
|
|
+ "\"password\":\"view1\"}"; |
|
|
|
+ "\"password\":\"view1\"}", |
|
|
|
|
|
|
|
|
|
|
|
private final String maskLogMsg = "{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," |
|
|
|
"{\"address\":\"jdbc:mysql://192.168.xx.xx:3306\"," |
|
|
|
+ "\"database\":\"carbond\"," |
|
|
|
+ "\"database\":\"carbond\"," |
|
|
|
+ "\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," |
|
|
|
+ "\"jdbcUrl\":\"jdbc:mysql://192.168.xx.xx:3306/ods\"," |
|
|
|
+ "\"user\":\"view\"," |
|
|
|
+ "\"user\":\"view\"," |
|
|
|
+ "\"password\":\"*****\"}"; |
|
|
|
+ "\"password\":\"*****\"}"); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
tcs.put("End initialize task {\n" + |
|
|
|
* mask sensitive logMsg - sql task datasource password |
|
|
|
" \"resourceParametersHelper\" : {\n" + |
|
|
|
*/ |
|
|
|
" \"resourceMap\" : {\n" + |
|
|
|
@Test |
|
|
|
" \"DATASOURCE\" : {\n" + |
|
|
|
public void testPwdLogMsgConverter() { |
|
|
|
" \"1\" : {\n" + |
|
|
|
final String maskedLog = SensitiveDataConverter.maskSensitiveData(logMsg); |
|
|
|
" \"resourceType\" : \"DATASOURCE\",\n" + |
|
|
|
|
|
|
|
" \"type\" : \"ORACLE\",\n" + |
|
|
|
|
|
|
|
" \"connectionParams\" : \"{\\\"user\\\":\\\"user\\\",\\\"password\\\":\\\"view1\\\"}\",\n" + |
|
|
|
|
|
|
|
" \"DATASOURCE\" : null\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
"}", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"End initialize task {\n" + |
|
|
|
|
|
|
|
" \"resourceParametersHelper\" : {\n" + |
|
|
|
|
|
|
|
" \"resourceMap\" : {\n" + |
|
|
|
|
|
|
|
" \"DATASOURCE\" : {\n" + |
|
|
|
|
|
|
|
" \"1\" : {\n" + |
|
|
|
|
|
|
|
" \"resourceType\" : \"DATASOURCE\",\n" + |
|
|
|
|
|
|
|
" \"type\" : \"ORACLE\",\n" + |
|
|
|
|
|
|
|
" \"connectionParams\" : \"{\\\"user\\\":\\\"user\\\",\\\"password\\\":\\\"*****\\\"}\",\n" |
|
|
|
|
|
|
|
+ |
|
|
|
|
|
|
|
" \"DATASOURCE\" : null\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
"}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String logMsg : tcs.keySet()) { |
|
|
|
|
|
|
|
String maskedLog = SensitiveDataConverter.maskSensitiveData(logMsg); |
|
|
|
logger.info("original parameter : {}", logMsg); |
|
|
|
logger.info("original parameter : {}", logMsg); |
|
|
|
logger.info("masked parameter : {}", maskedLog); |
|
|
|
logger.info("masked parameter : {}", maskedLog); |
|
|
|
|
|
|
|
Assertions.assertEquals(tcs.get(logMsg), maskedLog); |
|
|
|
Assertions.assertEquals(maskLogMsg, maskedLog); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|