mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-02 04:59:51 +08:00
增加job db密码加解密测试用例
This commit is contained in:
parent
6ed98bf09a
commit
348dc19ffb
@ -23,7 +23,7 @@ public class JobDataBasePwdDecryptUtil {
|
||||
//加密key
|
||||
String key = SecretUtil.getSecurityProperties().getProperty(CoreConstant.DB_ENCRYPT_KEY);
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
LOG.warn("{} is empty,use original password,", CoreConstant.DB_ENCRYPT_KEY);
|
||||
LOG.warn("{} is empty,use original password", CoreConstant.DB_ENCRYPT_KEY);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(readerPwd)) {
|
||||
|
@ -1,4 +1,7 @@
|
||||
import com.alibaba.datax.common.util.Configuration;
|
||||
import com.alibaba.datax.core.util.JobDataBasePwdDecryptUtil;
|
||||
import com.alibaba.datax.core.util.SecretUtil;
|
||||
import com.alibaba.datax.core.util.container.CoreConstant;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -10,9 +13,27 @@ import java.io.File;
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ConfigurationTest {
|
||||
String key = "1qaz2wsx";
|
||||
String nativePassword = "12345678";
|
||||
|
||||
/**
|
||||
* 测试密码解密
|
||||
*/
|
||||
@Test
|
||||
public void configParseTest(){
|
||||
Configuration configuration=Configuration.from(new File("/Users/weizhao.dong/Documents/soft/datax_install_d/script/dwd_g2park_inout_report_s.json"));
|
||||
System.out.println(JSON.toJSONString(configuration));
|
||||
public void dbEncryptPasswrdTest() {
|
||||
System.setProperty("datax.home",System.getProperty("user.dir")+"/src/test/resources");
|
||||
Configuration configuration = Configuration.from(new File("src/test/resources/dwd_g2park_inout_report_s.json"));
|
||||
JobDataBasePwdDecryptUtil.decrypt(configuration);
|
||||
assert configuration.getString(CoreConstant.DATA_JOB_READER_PARAMETER_PASSWORD).equals(nativePassword);
|
||||
assert configuration.getString(CoreConstant.DATA_JOB_WRITER_PARAMETER_PASSWORD).equals(nativePassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成加密密码
|
||||
*/
|
||||
@Test
|
||||
public void generateEncryptPassword() {
|
||||
//密码为:ZnOZROJwLiMeI3FQluEhHg==
|
||||
System.out.println(SecretUtil.encrypt3DES(nativePassword, key));
|
||||
}
|
||||
}
|
||||
|
9
core/src/test/resources/conf/.secret.properties
Executable file
9
core/src/test/resources/conf/.secret.properties
Executable file
@ -0,0 +1,9 @@
|
||||
#ds basicAuth config
|
||||
auth.user=
|
||||
auth.pass=
|
||||
current.keyVersion=
|
||||
current.publicKey=
|
||||
current.privateKey=
|
||||
current.service.username=
|
||||
current.service.password=
|
||||
db.encrypt.key=1qaz2wsx
|
55
core/src/test/resources/dwd_g2park_inout_report_s.json
Normal file
55
core/src/test/resources/dwd_g2park_inout_report_s.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"job": {
|
||||
"content": [
|
||||
{
|
||||
"reader": {
|
||||
"name": "mysqlreader",
|
||||
"parameter": {
|
||||
"column": [
|
||||
"1 AS inout_type","i.enter_time AS report_date","i.create_time as create_time","i.park_code AS park_code","i.inout_id as inout_id","i.enter_time as enter_time","i.depart_time as depart_time","CAST( YEAR ( i.enter_time ) AS SIGNED ) AS report_year","CAST( MONTH ( i.enter_time ) AS SIGNED ) AS report_month","CAST( HOUR ( i.enter_time ) AS SIGNED ) AS report_hour","(CASE WHEN CHAR_LENGTH(i.client_no) = 0 OR i.client_no IS NULL THEN '0' ELSE i.client_no END) AS client_no","IFNULL(i.in_gateway, '0') AS gateway_no","1 AS total_num","( CASE WHEN i.vehicle_category = 1 THEN 1 ELSE 0 END ) AS big_car_num","( CASE WHEN i.vehicle_category <> 1 THEN 1 ELSE 0 END ) AS small_car_num","( CASE WHEN (i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_car_num","( CASE WHEN i.in_label = 2 OR i.in_label = 3 THEN 1 ELSE 0 END ) AS reserve_num","( CASE WHEN i.in_label = 1 THEN 1 ELSE 0 END ) AS white_list_num","( CASE WHEN i.vehicle_category = 1 AND ( i.in_label = 2 OR i.in_label = 3 ) THEN 1 ELSE 0 END ) AS big_car_reserve_num","( CASE WHEN i.vehicle_category = 1 AND i.in_label = 1 THEN 1 ELSE 0 END ) AS big_car_white_list_num","( CASE WHEN i.vehicle_category <> 1 AND ( i.in_label = 2 OR i.in_label = 3 ) THEN 1 ELSE 0 END ) AS small_car_reserve_num","( CASE WHEN i.vehicle_category <> 1 AND i.in_label = 1 THEN 1 ELSE 0 END ) AS small_car_white_list_num","( CASE WHEN ( i.in_label = 2 OR i.in_label = 3 ) AND ( i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_reserve_num","( CASE WHEN i.in_label = 1 AND ( i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_white_list_num"," i.deleted","CURRENT_TIMESTAMP AS update_time"
|
||||
],
|
||||
"splitPk": "inout_id",
|
||||
"connection": [
|
||||
{
|
||||
"jdbcUrl": ["jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&allowMultiQueries=true"],
|
||||
"table": ["g2park_inout_record i"]
|
||||
}
|
||||
],
|
||||
"password": "ZnOZROJwLiMeI3FQluEhHg==",
|
||||
"username": "root",
|
||||
"where": "i.enter_time is not null and update_time > '${updateTime}' "
|
||||
}
|
||||
},
|
||||
"writer": {
|
||||
"name": "mysqlwriter",
|
||||
"parameter": {
|
||||
"writeMode": "replace",
|
||||
"column": [
|
||||
"inout_type","report_date","create_time","park_code","inout_id","enter_time","depart_time","report_year","report_month","report_hour","client_no","gateway_no","total_num","big_car_num","small_car_num","new_power_car_num","reserve_num","white_list_num","big_car_reserve_num","big_car_white_list_num","small_car_reserve_num","small_car_white_list_num","new_power_reserve_num","new_power_white_list_num","deleted","update_time"
|
||||
],
|
||||
"connection": [
|
||||
{
|
||||
"jdbcUrl": "jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&allowMultiQueries=true",
|
||||
"table": ["dwd_g2park_inout_report_s"]
|
||||
}
|
||||
],
|
||||
"password": "ZnOZROJwLiMeI3FQluEhHg==",
|
||||
"username": "root",
|
||||
"preSql": [],
|
||||
"session": [
|
||||
"set session sql_mode='ANSI'"
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"setting": {
|
||||
"speed": {
|
||||
"channel": "2"
|
||||
},
|
||||
"passwdEncrypt":true
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user