Merge branch 'v2.0.0_dev' of git.komect.net:DDOSAQ/phoenix_ddos_handle into v2.0.0_dev

This commit is contained in:
HuangXin 2020-08-05 19:35:51 +08:00
commit f288e01197
4 changed files with 77 additions and 62 deletions

View File

@ -23,7 +23,7 @@
<select id="addUserAccount" resultMap="user_account">
INSERT INTO user_account(username, password, operators, status)
SELECT #{username}, #{password}, #{operators}, ${@com.dispose.common.ObjectStatus@NORMAL.getCode()}
SELECT #{username}, #{password}, #{operators}, ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
FROM DUAL
WHERE NOT EXISTS(
SELECT username

View File

@ -119,16 +119,12 @@ public class UserAccountManagerTest extends InitTestEnvironment {
for (int i = 0; i < 3; i++) {
userAccountManager.setUserPwdErrTimes(v.getUsername(), i);
UserAccount user = userAccountMapper.getUserByName(v.getUsername());
int times = userAccountManager.getUsrPwdErrTimes(v.getUsername());
Assert.assertNotNull(user);
Assert.assertEquals(i, (long) user.getPwdErrTimes());
Assert.assertEquals(i, times);
try {
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(user));
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(userAccountManager.getUserByName(v.getUsername())));
} catch (JsonProcessingException e) {
e.printStackTrace();
Assert.fail();
@ -147,12 +143,15 @@ public class UserAccountManagerTest extends InitTestEnvironment {
String userToken = userAccountManager.getUserToken(v.getUsername());
UserAccount user = userAccountMapper.getUserByName(v.getUsername());
Assert.assertNotNull(userToken);
Assert.assertEquals(user.getToken(), userToken);
if(user.getToken().length() != 0){
Assert.assertNotNull(userToken);
userAccountManager.cleanUserToken(v.getUsername());
Assert.assertEquals(user.getToken(), userToken);
Assert.assertEquals(ErrorCode.ERR_LOGOUT, userAccountManager.verifyToken(userToken));
userAccountManager.cleanUserToken(v.getUsername());
Assert.assertEquals(ErrorCode.ERR_LOGOUT, userAccountManager.verifyToken(userToken));
}
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
} catch (JsonProcessingException | NoSuchAlgorithmException e) {

View File

@ -4,6 +4,7 @@ import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.IpAddrType;
import com.dispose.mapper.DisposeCapacityMapper;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeCapacity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -40,6 +41,11 @@ public class DisposeCapacityMapperTest {
*/
@Resource
DisposeCapacityMapper disposeCapacityMapper;
/**
* The Dispose device mapper.
*/
@Resource
DisposeDeviceMapper disposeDeviceMapper;
/**
* The Object mapper.
*/
@ -55,23 +61,28 @@ public class DisposeCapacityMapperTest {
public void a1_addNewDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>();
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4_IPV6)
.deviceId(deviceId)
.capacityType(DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP)
.ipType(IpAddrType.IPV4_IPV6)
.protectIp("")
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4_IPV6)
.deviceId(deviceId)
.capacityType(DisposeCapacityType.BLOCKING)
.objectType(DisposeObjectType.URL)
.ipType(IpAddrType.IPV4_IPV6)
.protectIp("")
.build());
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList));
int items = disposeCapacityMapper.addNewDisposeCapacity(newCapList);
log.info("+++++++++++++item {}", items);
Assert.assertEquals(items, newCapList.size());
@ -89,8 +100,10 @@ public class DisposeCapacityMapperTest {
public void a2_delDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>();
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP)
@ -98,7 +111,7 @@ public class DisposeCapacityMapperTest {
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.BLOCKING)
.objectType(DisposeObjectType.IP)
@ -116,7 +129,7 @@ public class DisposeCapacityMapperTest {
items = disposeCapacityMapper.delDisposeCapacity(capList.get(0).getDeviceId(),
capList.get(0).getCapacityType().getValue());
Assert.assertEquals(items, 2);
Assert.assertNotEquals(items, 0);
List<DisposeCapacity> caps = disposeCapacityMapper.selectAll();
@ -132,8 +145,10 @@ public class DisposeCapacityMapperTest {
public void a3_delDeviceDisposeCapacity() {
List<DisposeCapacity> newCapList = new ArrayList<>();
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP)
@ -141,7 +156,7 @@ public class DisposeCapacityMapperTest {
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.BLOCKING)
.objectType(DisposeObjectType.IP)
@ -150,10 +165,7 @@ public class DisposeCapacityMapperTest {
Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
List<DisposeCapacity> capList = disposeCapacityMapper.getDeviceDisposeCapacity(1L);
Assert.assertEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()),
capList.size());
Assert.assertNotEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()), 0);
Assert.assertEquals(0, disposeCapacityMapper.selectAll().size());
}
@ -167,8 +179,10 @@ public class DisposeCapacityMapperTest {
public void b1_getDeviceDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>();
Long deviceId = disposeDeviceMapper.selectAll().get(0).getId();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP)
@ -176,7 +190,7 @@ public class DisposeCapacityMapperTest {
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.deviceId(deviceId)
.ipType(IpAddrType.IPV4_IPV6)
.capacityType(DisposeCapacityType.BLOCKING)
.objectType(DisposeObjectType.IP)

View File

@ -110,40 +110,42 @@ public class DisposeDeviceMapperTest {
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
devList.forEach(v -> {
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort());
if(v.getIpPort().length() != 0){
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort());
String beforeVer = dev.getVersion();
if (dev.getVersion().equals("B5.2.27.7")) {
dev.setVersion("5.7.13");
} else {
dev.setVersion("B5.2.27.7");
}
String beforeVer = dev.getVersion();
if (dev.getVersion().equals("B5.2.27.7")) {
dev.setVersion("5.7.13");
} else {
dev.setVersion("B5.2.27.7");
}
DisposeDevice newDev = DisposeDevice.builder()
.id(dev.getId())
.ipAddr("10.88.77.15")
.ipPort("")
.deviceType(DisposeDeviceType.DPTECH_UMC)
.areaCode(0)
.deviceName("中移杭研实验室迪普清洗设备")
.manufacturer("DPTech")
.model("UMC")
.version(dev.getVersion())
.userName("admin")
.password("UMCAdministrator")
.urlPath("UMC/service/AbnormalFlowCleaningService")
.urlType(HttpType.HTTP)
.readme("实验室测试设备")
.status(ObjectStatus.NORMAL)
.build();
DisposeDevice newDev = DisposeDevice.builder()
.id(dev.getId())
.ipAddr("10.88.77.15")
.ipPort("")
.deviceType(DisposeDeviceType.DPTECH_UMC)
.areaCode(0)
.deviceName("中移杭研实验室迪普清洗设备")
.manufacturer("DPTech")
.model("UMC")
.version(dev.getVersion())
.userName("admin")
.password("UMCAdministrator")
.urlPath("UMC/service/AbnormalFlowCleaningService")
.urlType(HttpType.HTTP)
.readme("实验室测试设备")
.status(ObjectStatus.NORMAL)
.build();
Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev));
Assert.assertNotNull(dev.getId());
Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer);
try {
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
} catch (JsonProcessingException e) {
e.printStackTrace();
Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev));
Assert.assertNotNull(dev.getId());
Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer);
try {
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
});
@ -152,9 +154,7 @@ public class DisposeDeviceMapperTest {
}
/**
* D 1 get dispose device by ipAddr and ipPort.
*
* @throws JsonProcessingException the json processing exception
* D 1 get dispose device by ipAddr and ipPort.processing exception
*/
@Test
public void d1_getDeviceByAddress() {
@ -164,10 +164,12 @@ public class DisposeDeviceMapperTest {
DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort());
Assert.assertNotNull(dev);
dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(),
String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1));
if(v.getIpPort().length() != 0){
dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(),
String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1));
Assert.assertNull(dev);
Assert.assertNull(dev);
}
});
}