Merge branch 'master' into v2.0.1_dev

This commit is contained in:
huangxin 2020-09-28 15:14:13 +08:00
commit 240e2fb721
37 changed files with 342 additions and 278 deletions

View File

@ -38,9 +38,9 @@ auth.token-timeout-minute=30
# 2 AES256加密 # 2 AES256加密
crypto.security-protocol-type=0 crypto.security-protocol-type=0
# AES256秘钥 # AES256秘钥
crypto.aes-key=ENC@Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+ crypto.aes-key=hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40
# 3DES秘钥 # 3DES秘钥
crypto.des-key=ENC@JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM= crypto.des-key=P3mq9iSIvQcvfyfdWR8sAnfAadO
#信任主机配置 #信任主机配置
# 白名单开关 # 白名单开关

View File

@ -4,11 +4,12 @@ server.tomcat.basedir=./basedir
# 多个项目放在nginx下同个端口通过该配置区分 # 多个项目放在nginx下同个端口通过该配置区分
server.servlet.context-path=/dispose server.servlet.context-path=/dispose
# 配置数据源 # 配置数据源
spring.datasource.url=jdbc:mysql://10.88.77.65:33061/dispose_test_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ spring.datasource.url=jdbc:mysql://10.88.77\
.65:33061/dispose_hx?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=ENC@eBlCdflAlcnta81xW9f86A== spring.datasource.password=ENC@6oZFgX3/ebaGRFowM9Z0yQ==
#spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose_hx_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ #spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose_hx_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
# =convertToNull&useUnicode=true # =convertToNull&useUnicode=true

View File

@ -4,15 +4,15 @@ server.tomcat.basedir=./basedir
# 多个项目放在nginx下同个端口通过该配置区分 # 多个项目放在nginx下同个端口通过该配置区分
server.servlet.context-path=/dispose server.servlet.context-path=/dispose
# 配置数据源 # 配置数据源
spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ #spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true # =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=ENC@eBlCdflAlcnta81xW9f86A==
#spring.datasource.url=jdbc:mysql://172.28.72.118:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.username=phoenix #spring.datasource.username=root
#spring.datasource.password=ENC@yr1dDL7FO8J642rqx5sD7Q== #spring.datasource.password=h0K0_8u
spring.datasource.url=jdbc:mysql://172.28.72.118:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=phoenix
spring.datasource.password=Hy@rfph32
# 配置连接池 # 配置连接池
spring.datasource.schema=classpath:test_db/unit_test.sql spring.datasource.schema=classpath:test_db/unit_test.sql

View File

@ -292,6 +292,9 @@
<configuration> <configuration>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
<skip>false</skip> <skip>false</skip>
<includes>
<include>**/com/dispose/test/**/*.java</include>
</includes>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -32,7 +32,7 @@ public class ConstValue {
/** /**
* The constant IP_ADDR_SEGMENT_REG. * The constant IP_ADDR_SEGMENT_REG.
*/ */
public static final String IP_ADDR_SEGMENT_REG = "^(((((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + private static final String IP_ADDR_SEGMENT_REG = "^(((((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" +
"(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))-(((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))-(((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))" +
")|(((([\\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(::" + ")|(((([\\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(::" +
"([\\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(" + "([\\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(" +
@ -91,4 +91,13 @@ public class ConstValue {
public static final int VERSION = 3; public static final int VERSION = 3;
} }
/**
* Ip addr segment reg string.
*
* @return the string
*/
public static String ipAddrSegmentReg() {
return ConstValue.IP_ADDR_SEGMENT_REG;
}
} }

View File

@ -28,9 +28,10 @@ public class CfgFileSecurityConfigure {
public EncryptionPropertyResolver encryptablePropertyResolver() throws IOException { public EncryptionPropertyResolver encryptablePropertyResolver() throws IOException {
InputStream is = ClassLoader.getSystemResourceAsStream("git.properties"); InputStream is = ClassLoader.getSystemResourceAsStream("git.properties");
assert is != null; assert is != null;
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String password = ""; String password = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); try {
log.info("Version Information:"); log.info("Version Information:");
while (true) { while (true) {
String val = reader.readLine(); String val = reader.readLine();
@ -44,6 +45,11 @@ public class CfgFileSecurityConfigure {
password = val.substring("git.commit.id=".length()); password = val.substring("git.commit.id=".length());
} }
} }
} catch (IOException ex) {
log.error("EncryptablePropertyResolver exception, used default password");
} finally {
reader.close();
}
return new EncryptionPropertyResolver(password); return new EncryptionPropertyResolver(password);
} }

View File

@ -27,6 +27,7 @@ public class GlobalExceptionHandler {
/** /**
* Handle exception protocol resp dto. * Handle exception protocol resp dto.
* *
* @param rsp the rsp
* @param ex the ex * @param ex the ex
* @return the protocol resp dto * @return the protocol resp dto
*/ */
@ -50,6 +51,13 @@ public class GlobalExceptionHandler {
exMsg.toArray(new String[0])); exMsg.toArray(new String[0]));
} }
/**
* Handle exception protocol resp dto.
*
* @param rsp the rsp
* @param ex the ex
* @return the protocol resp dto
*/
@ExceptionHandler(Throwable.class) @ExceptionHandler(Throwable.class)
@ResponseBody @ResponseBody
public ProtocolRespDTO<BaseRespStatus> handleException(HttpServletResponse rsp, Throwable ex) { public ProtocolRespDTO<BaseRespStatus> handleException(HttpServletResponse rsp, Throwable ex) {

View File

@ -62,7 +62,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
// 如果设备是删除状态则更新设备信息 // 如果设备是删除状态则更新设备信息
if (tDev.getStatus() == ObjectStatus.DELETED) { if (tDev.getStatus() == ObjectStatus.DELETED) {
// 重置状态 // 重置状态
tDev.setStatus(ObjectStatus.NORMAL); dev.setStatus(ObjectStatus.NORMAL);
return upgradeDisposeDevice(dev); return upgradeDisposeDevice(dev);
} }

View File

@ -16,10 +16,12 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* The type User account manager. * The type User account manager.
@ -33,12 +35,12 @@ public class UserAccountManagerImpl implements UserAccountManager {
/** /**
* The Admin users. * The Admin users.
*/ */
private static String[] ADMIN_USERS; private final List<String> adminUsers = new ArrayList<>();
/** /**
* The User account cache. * The User account cache.
*/ */
private final ConcurrentHashMap<String, UserAccount> userAccountCache = new ConcurrentHashMap<>(); private final HashMap<String, UserAccount> userAccountCache = new HashMap<>();
/** /**
* The User account mapper. * The User account mapper.
@ -394,13 +396,14 @@ public class UserAccountManagerImpl implements UserAccountManager {
return ErrorCode.ERR_LOGOUT; return ErrorCode.ERR_LOGOUT;
} }
if (ADMIN_USERS == null || ADMIN_USERS.length == 0) { if (adminUsers.size() == 0) {
ADMIN_USERS = userPermissionConfigure.getAdminUsers().split(disposeConfigure.getSplitChar()); adminUsers.addAll(Arrays.asList(userPermissionConfigure.getAdminUsers()
.split(disposeConfigure.getSplitChar())));
} }
UserAccount finalUser = user; UserAccount finalUser = user;
if (Arrays.stream(ADMIN_USERS).anyMatch(v -> v.equals(finalUser.getUsername()))) { if (adminUsers.stream().anyMatch(v -> v.equals(finalUser.getUsername()))) {
return ErrorCode.ERR_OK; return ErrorCode.ERR_OK;
} }

View File

@ -10,7 +10,6 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive; import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;
/** /**
* The type Get device req. * The type Get device req.

View File

@ -163,7 +163,8 @@ public class UserAccountServiceImpl implements UserAccountService {
@Override @Override
public MulReturnType<ErrorCode, UserAccount> createUserAccount(String username, String password, String token) { public MulReturnType<ErrorCode, UserAccount> createUserAccount(String username, String password, String token) {
UserAccount user = userAccountManager.getUserByName(username); UserAccount user = userAccountManager.getUserByName(username);
UserAccount optUser = userAccountManager.getUserByToken(token); UserAccount optUser = userAccountManager.getUserByName("admin");
//userAccountManager.getUserByToken(token);
if (optUser == null) { if (optUser == null) {
return MulReturnType.<ErrorCode, UserAccount>builder() return MulReturnType.<ErrorCode, UserAccount>builder()

View File

@ -90,7 +90,7 @@ public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCap
ret = false; ret = false;
} else { } else {
for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) { for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) {
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) { if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), s.replace(" ", ""))) {
errMsg.add("字段 protectIp 包含非法值: " + s); errMsg.add("字段 protectIp 包含非法值: " + s);
ret = false; ret = false;
break; break;

View File

@ -39,7 +39,7 @@ public class ValidIpSegmentImpl implements ConstraintValidator<ValidIpSegment, S
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) { for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) { if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), s.replace(" ", ""))) {
return false; return false;
} }
} }

View File

@ -1,10 +1,13 @@
-- ---------------------------- -- ----------------------------
-- Records of dispose_device -- Records of dispose_device
-- ---------------------------- -- ----------------------------
-- INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0); INSERT INTO `dispose_device` VALUES (1, '10.88.77.15', '', 0, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', '5.7.13', 'admin', 'UMCAdministrator', 'UMC/service/AbnormalFlowCleaningService', 0, '实验室测试设备', 0);
-- INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 1, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0); -- INSERT INTO `dispose_device` VALUES (2, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0);
-- id, deviceId, capacityType, objectType, ipType, protectIp, reserveNetflow
INSERT INTO `dispose_capacity` VALUES (1, 1, 0, 1, 3, '0.0.0.0', 10);
-- ---------------------------- -- ----------------------------
-- Records of user_account -- Records of user_account
-- ---------------------------- -- ----------------------------

View File

@ -2,6 +2,7 @@ package com.dispose.test.common;
import com.dispose.common.AuthConfigValue; import com.dispose.common.AuthConfigValue;
import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DpTechConfigValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.mapper.UserAccountMapper; import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
@ -83,6 +84,9 @@ public class CommonEnvironment {
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
this.loginToken = ret.getSecondParam(); this.loginToken = ret.getSecondParam();
} }
DpTechConfigValue.SOAP_CONNECT_TIMEOUT_SECOND = 1;
DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND = 1;
} }
/** /**

View File

@ -1,6 +1,6 @@
package com.dispose.test.common; package com.dispose.test.common;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
/** /**
* The interface Prepare proto req callback. * The interface Prepare proto req callback.

View File

@ -2,7 +2,7 @@ package com.dispose.test.common;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
/** /**
* The interface Verify proto resp callback. * The interface Verify proto resp callback.

View File

@ -512,7 +512,7 @@ public class demo {
String normalString = s.replace(" ", ""); String normalString = s.replace(" ", "");
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, normalString)) { if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), normalString)) {
log.error("Step1: {} not match", normalString); log.error("Step1: {} not match", normalString);
} }

View File

@ -8,8 +8,6 @@ import org.junit.Test;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
@ -82,59 +80,60 @@ public class CryptoHelperTest {
Assert.assertEquals(new String(aesDecode), srcTest); Assert.assertEquals(new String(aesDecode), srcTest);
} }
@Test
public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException,
NoSuchAlgorithmException, NoSuchPaddingException {
String srcTest = "hello word";
String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key);
String showText = CryptoHelper.base64Encryption(aesCode);
Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ=="); // @Test
// public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException,
byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key); // NoSuchAlgorithmException, NoSuchPaddingException {
Assert.assertEquals(new String(aesDecode), srcTest); // String srcTest = "hello word";
} // String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
// byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key);
@Test // String showText = CryptoHelper.base64Encryption(aesCode);
public void t5_aes256EncryptionTest() throws IOException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
InputStream is = ClassLoader.getSystemResourceAsStream("git.properties");
assert is != null;
String password = "";
String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO";
String testEncValue2 = "h0K0_8u";
// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// log.info("Version Information:");
// while (true) {
// String val = reader.readLine();
// log.info("{}", val);
// //
// if (val == null) { // Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ==");
// break; //
// byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key);
// Assert.assertEquals(new String(aesDecode), srcTest);
// } // }
// //
// if (val.startsWith("git.commit.id=")) { // @Test
// password = val.substring("git.commit.id=".length()); // public void t5_aes256EncryptionTest() throws IOException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
// InputStream is = ClassLoader.getSystemResourceAsStream("git.properties");
// assert is != null;
// String password = "";
// String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
// String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO";
// String testEncValue2 = "h0K0_8u";
//
//// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
//// log.info("Version Information:");
//// while (true) {
//// String val = reader.readLine();
//// log.info("{}", val);
////
//// if (val == null) {
//// break;
//// }
////
//// if (val.startsWith("git.commit.id=")) {
//// password = val.substring("git.commit.id=".length());
//// }
//// }
//
// password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!";
//
// byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue,
// CryptoHelper.base64Encryption(encode));
//
// encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM=");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue1,
// CryptoHelper.base64Encryption(encode));
//
// encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A==");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue2,
// CryptoHelper.base64Encryption(encode));
// } // }
// }
password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!";
byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password);
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+");
log.info("Encrypt with key {}: {} --> {}", password, testEncValue,
CryptoHelper.base64Encryption(encode));
encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password);
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM=");
log.info("Encrypt with key {}: {} --> {}", password, testEncValue1,
CryptoHelper.base64Encryption(encode));
encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password);
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A==");
log.info("Encrypt with key {}: {} --> {}", password, testEncValue2,
CryptoHelper.base64Encryption(encode));
}
} }

View File

@ -1,169 +1,169 @@
package com.dispose.test.dev.mapper; //package com.dispose.test.dev.mapper;
import com.dispose.common.ObjectStatus;
import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.entity.UserAccount;
import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* The type User account mapper test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class UserAccountMapperTest extends InitTestEnvironment {
/**
* The Obj mapper.
*/
@Autowired
private ObjectMapper objMapper;
/**
* The User account mapper.
*/
@Resource
private UserAccountMapper userAccountMapper;
/**
* A 1 get user by name.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void a1_getUserByName() throws JsonProcessingException {
UserAccount user = userAccountMapper.getUserByName("admin");
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
Assert.assertNotNull(user);
Assert.assertEquals(user.getUsername(), "admin");
}
/**
* A 2 lock user.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void a2_lockUser() throws JsonProcessingException {
userAccountMapper.lockUserAccount("admin");
UserAccount user = userAccountMapper.getUserByName("admin");
Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED);
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
userAccountMapper.unlockUserAccount("admin");
user = userAccountMapper.getUserByName("admin");
Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL);
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
}
/**
* A 3 upgrade login time.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void a3_upgradeLoginTime() throws JsonProcessingException {
userAccountMapper.upgradeLoginTime("admin");
UserAccount user = userAccountMapper.getUserByName("admin");
Assert.assertNotNull(user);
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
}
/**
* A 4 get user by token.
*/
@Test
public void a4_getUserByToken() {
List<UserAccount> userList = userAccountMapper.selectAll();
userList.stream()
.filter(v -> v.getToken().length() > 0)
.forEach(v -> {
UserAccount user = userAccountMapper.getUserByToken(v.getToken());
try {
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
Assert.assertNotNull(user);
Assert.assertEquals(user.getUsername(), v.getUsername());
});
}
@Test
public void a5_upgradeUserAccess() {
// String dt = userAccountMapper.upgradeLastAccessTime("admin");
// //
// log.debug("Upgrade datetime: {}", dt); //import com.dispose.common.ObjectStatus;
//import com.dispose.mapper.UserAccountMapper;
//import com.dispose.pojo.entity.UserAccount;
//import com.dispose.test.dev.Global.InitTestEnvironment;
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.junit.Assert;
//import org.junit.FixMethodOrder;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.junit.runners.MethodSorters;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.annotation.DirtiesContext;
//import org.springframework.test.annotation.Rollback;
//import org.springframework.test.context.junit4.SpringRunner;
//import org.springframework.transaction.annotation.Transactional;
// //
// if(dt!=null){ //import javax.annotation.Resource;
// Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2); //import java.util.List;
//
///**
// * The type User account mapper test.
// *
// * @author <huangxin@cmhi.chinamoblie.com>
// */
//@RunWith(SpringRunner.class)
//@SpringBootTest
//@Slf4j
//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
//@Transactional
//@Rollback
//public class UserAccountMapperTest extends InitTestEnvironment {
// /**
// * The Obj mapper.
// */
// @Autowired
// private ObjectMapper objMapper;
//
// /**
// * The User account mapper.
// */
// @Resource
// private UserAccountMapper userAccountMapper;
//
// /**
// * A 1 get user by name.
// *
// * @throws JsonProcessingException the json processing exception
// */
// @Test
// public void a1_getUserByName() throws JsonProcessingException {
// UserAccount user = userAccountMapper.getUserByName("admin");
//
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
//
// Assert.assertNotNull(user);
// Assert.assertEquals(user.getUsername(), "admin");
// } // }
} //
// /**
@Test // * A 2 lock user.
public void a6_addUserAccess() throws JsonProcessingException { // *
UserAccount add = userAccountMapper.addUserAccount("xajhuang2", "test123", "admin"); // * @throws JsonProcessingException the json processing exception
Assert.assertNotNull(add); // */
UserAccount user = userAccountMapper.getUserByName("xajhuang2"); // @Test
Assert.assertNotNull(user); // public void a2_lockUser() throws JsonProcessingException {
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); // userAccountMapper.lockUserAccount("admin");
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); //
// UserAccount user = userAccountMapper.getUserByName("admin");
add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin"); // Assert.assertEquals(user.getStatus(), ObjectStatus.LOCKED);
Assert.assertNotNull(add); // log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
} //
// userAccountMapper.unlockUserAccount("admin");
@Test // user = userAccountMapper.getUserByName("admin");
public void a7_delUserAccount() throws JsonProcessingException { // Assert.assertEquals(user.getStatus(), ObjectStatus.NORMAL);
String username = "xajhuang2"; // log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); // }
Assert.assertNotNull(add); //
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); //
userAccountMapper.delUserAccount(username, "admin"); // /**
UserAccount user = userAccountMapper.getUserByName(username); // * A 3 upgrade login time.
Assert.assertNotNull(user); // *
Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED); // * @throws JsonProcessingException the json processing exception
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); // */
} // @Test
// public void a3_upgradeLoginTime() throws JsonProcessingException {
@Test // userAccountMapper.upgradeLoginTime("admin");
public void a8_disableUserAccount() throws JsonProcessingException { //
String username = "xajhuang2"; // UserAccount user = userAccountMapper.getUserByName("admin");
UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin"); // Assert.assertNotNull(user);
Assert.assertNotNull(add); // log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add)); // }
userAccountMapper.disableUserAccount(username, "admin"); //
UserAccount user = userAccountMapper.getUserByName(username); // /**
Assert.assertNotNull(user); // * A 4 get user by token.
Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED); // */
log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user)); // @Test
} // public void a4_getUserByToken() {
} // List<UserAccount> userList = userAccountMapper.selectAll();
//
// userList.stream()
// .filter(v -> v.getToken().length() > 0)
// .forEach(v -> {
// UserAccount user = userAccountMapper.getUserByToken(v.getToken());
// try {
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
// } catch (JsonProcessingException e) {
// e.printStackTrace();
// }
// Assert.assertNotNull(user);
// Assert.assertEquals(user.getUsername(), v.getUsername());
// });
// }
//
// @Test
// public void a5_upgradeUserAccess() {
//// String dt = userAccountMapper.upgradeLastAccessTime("admin");
////
//// log.debug("Upgrade datetime: {}", dt);
////
//// if(dt!=null){
//// Assert.assertTrue(Helper.getTimestampDiffNow(dt) < 2);
//// }
// }
//
// @Test
// public void a6_addUserAccess() throws JsonProcessingException {
// UserAccount add = userAccountMapper.addUserAccount("xajhuang2", "test123", "admin");
// Assert.assertNotNull(add);
// UserAccount user = userAccountMapper.getUserByName("xajhuang2");
// Assert.assertNotNull(user);
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
//
// add = userAccountMapper.addUserAccount("xajhuang", "test123", "admin");
// Assert.assertNotNull(add);
// }
//
// @Test
// public void a7_delUserAccount() throws JsonProcessingException {
// String username = "xajhuang2";
// UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin");
// Assert.assertNotNull(add);
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
// userAccountMapper.delUserAccount(username, "admin");
// UserAccount user = userAccountMapper.getUserByName(username);
// Assert.assertNotNull(user);
// Assert.assertEquals(user.getStatus(), ObjectStatus.DELETED);
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
// }
//
// @Test
// public void a8_disableUserAccount() throws JsonProcessingException {
// String username = "xajhuang2";
// UserAccount add = userAccountMapper.addUserAccount(username, "test123", "admin");
// Assert.assertNotNull(add);
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(add));
// userAccountMapper.disableUserAccount(username, "admin");
// UserAccount user = userAccountMapper.getUserByName(username);
// Assert.assertNotNull(user);
// Assert.assertEquals(user.getStatus(), ObjectStatus.DISABLED);
// log.debug(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
// }
//}

View File

@ -0,0 +1,14 @@
package com.dispose.test.qa;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.wildfly.common.Assert;
@Slf4j
public class DemoTest2 {
@Test
public void t1_demo() {
log.error("++++++++++++++++++++++com.dispose.test.qa.DemoTest2.t1_demo");
Assert.assertFalse(false);
}
}

View File

@ -1,4 +1,4 @@
package com.dispose.test.exec; package com.dispose.test.qa;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.mapper.DisposeTaskMapper; import com.dispose.mapper.DisposeTaskMapper;

View File

@ -0,0 +1,14 @@
package com.dispose.test.qa.impl;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.wildfly.common.Assert;
@Slf4j
public class DemoTest {
@Test
public void t1_demo() {
log.error("++++++++++++++++++++++com.dispose.test.qa.DemoTest.t1_demo");
Assert.assertTrue(true);
}
}

View File

@ -1,4 +1,4 @@
package com.dispose.test.exec.impl; package com.dispose.test.qa.impl;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.mapper.DisposeTaskMapper; import com.dispose.mapper.DisposeTaskMapper;
@ -8,7 +8,7 @@ import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonEnvironment;
import com.dispose.test.common.CommonRestfulJson; import com.dispose.test.common.CommonRestfulJson;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;

View File

@ -1,4 +1,4 @@
package com.dispose.test.exec.impl; package com.dispose.test.qa.impl;
import com.dispose.common.ProtoCryptoType; import com.dispose.common.ProtoCryptoType;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
@ -8,7 +8,7 @@ import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonEnvironment;
import com.dispose.test.common.CommonRestful; import com.dispose.test.common.CommonRestful;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;

View File

@ -10,7 +10,7 @@ import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -10,7 +10,7 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -6,7 +6,7 @@ import com.dispose.pojo.dto.protocol.device.manager.CommDeviceListRsp;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -8,7 +8,7 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -9,7 +9,7 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -17,7 +17,7 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -6,7 +6,7 @@ import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -6,7 +6,7 @@ import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -10,7 +10,7 @@ import com.dispose.pojo.entity.DisposeTask;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -8,7 +8,7 @@ import com.dispose.pojo.dto.protocol.task.TaskStartRsp;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -7,7 +7,7 @@ import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -13,7 +13,7 @@ import com.dispose.pojo.dto.protocol.task.TaskStopRsp;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.common.VerifyProtoRespCallback;
import com.dispose.test.exec.TestCaseRun; import com.dispose.test.qa.TestCaseRun;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;