From d79105f084906f050c7ff3d3c9783410beae5996 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Tue, 11 Aug 2020 15:39:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E5=90=AF=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E4=BB=BB=E5=8A=A1=E3=80=81=E5=81=9C=E6=AD=A2=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E4=BB=BB=E5=8A=A1=E3=80=81=E8=8E=B7=E5=8F=96=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=8A=B6=E6=80=81=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/dptech/DPTechInterfaceTestCase.java | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java diff --git a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java new file mode 100644 index 00000000..b0f4694c --- /dev/null +++ b/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java @@ -0,0 +1,136 @@ +package com.dispose.test.dptech; + +import com.dispose.ability.DisposeAbility; +import com.dispose.ability.impl.DpTechAbilityImpl; +import com.dispose.common.*; +import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.test.Global.InitTestEnvironment; +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.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * The type Dp tech interface test case. + */ +@RunWith(SpringRunner.class) +@Slf4j +@SpringBootTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class DPTechInterfaceTestCase extends InitTestEnvironment { + public static Integer DPTECH_UMC = 0; + + /** + * User login. + */ + @Override + public void userLogin() { + } + + /** + * Gets ability map key. + * + * @param ipAddr the ip addr + * @param ipPort the ip port + * @return the ability map key + */ + private String getAbilityMapKey(String ipAddr, String ipPort) { + return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort); + } + + /** + * T 1 get all detection object from umc. + */ + @Test + public void t1_runDisposeTest() { + DisposeAbility db; + + NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN}; + + DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION}; + + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("10.88.77.15") + .ipPort("") + .deviceType(DisposeDeviceType.DPTECH_UMC) + .areaCode(0) + .deviceName("中移杭研实验室迪普清洗设备") + .manufacturer("DPTech") + .model("UMC") + .version("5.7.13") + .userName("admin") + .password("UMCAdministrator") + .urlPath("UMC/service/AbnormalFlowCleaningService") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); + + String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; + String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); + String url = httpType + addr + "/" + dev.getUrlPath(); + + if (dev.getDeviceType().getValue().equals(DPTECH_UMC)) { + db = new DpTechAbilityImpl(); + + // 初始化设备 + db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); + + MulReturnType ret = db.runDispose("192.168.3.5", DisposeCapacityType.CLEANUP, + nfDirection, ddoSAttackType, -1L); + + Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); + } + } + + /** + * T 2 stop dispose task. + */ + @Test + public void t2_stopDisposeTest() { + DisposeAbility db; + + NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN}; + + DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION}; + + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("10.88.77.15") + .ipPort("") + .deviceType(DisposeDeviceType.DPTECH_UMC) + .areaCode(0) + .deviceName("中移杭研实验室迪普清洗设备") + .manufacturer("DPTech") + .model("UMC") + .version("5.7.13") + .userName("admin") + .password("UMCAdministrator") + .urlPath("UMC/service/AbnormalFlowCleaningService") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); + + String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; + String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); + String url = httpType + addr + "/" + dev.getUrlPath(); + + if (dev.getDeviceType().getValue().equals(DPTECH_UMC)) { + db = new DpTechAbilityImpl(); + + // 初始化设备 + db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); + + Assert.assertTrue(db.getDeviceLinkStatus()); + MulReturnType ret = db.stopDispose("192.168.3.5", DisposeCapacityType.CLEANUP, + nfDirection, ddoSAttackType, -1L); + + Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); + } + } +} From 2d02831d6987682c7c62d1733e906fe38807d7cc Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Tue, 11 Aug 2020 15:52:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B5=A9=E7=80=9A=E8=AE=BE=E5=A4=87=E5=90=AF=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E4=BB=BB=E5=8A=A1=E3=80=81=E5=81=9C=E6=AD=A2=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E4=BB=BB=E5=8A=A1=E3=80=81=E8=8E=B7=E5=8F=96=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=8A=B6=E6=80=81=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/haohan/HAOHanInterfaceTestCast.java | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java diff --git a/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java b/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java new file mode 100644 index 00000000..31a652bb --- /dev/null +++ b/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java @@ -0,0 +1,136 @@ +package com.dispose.test.haohan; + +import com.dispose.ability.DisposeAbility; +import com.dispose.ability.impl.HaoHanAbilityImpl; +import com.dispose.common.*; +import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.test.Global.InitTestEnvironment; +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.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * The type Dp tech interface test case. + */ +@RunWith(SpringRunner.class) +@Slf4j +@SpringBootTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class HAOHanInterfaceTestCast extends InitTestEnvironment { + public static Integer HAOHAN_PLATFORM = 0; + + /** + * User login. + */ + @Override + public void userLogin() { + } + + /** + * Gets ability map key. + * + * @param ipAddr the ip addr + * @param ipPort the ip port + * @return the ability map key + */ + private String getAbilityMapKey(String ipAddr, String ipPort) { + return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort); + } + + /** + * T 1 get all detection object from umc. + */ + @Test + public void t1_runDisposeTest() { + DisposeAbility db; + + NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN}; + + DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION}; + + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("10.88.77.88") + .ipPort("18080") + .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) + .areaCode(0) + .deviceName("中移杭研实验室浩瀚清洗设备") + .manufacturer("Haohan") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("DDoSClean/clean") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); + + String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; + String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); + String url = httpType + addr + "/" + dev.getUrlPath(); + + if (dev.getDeviceType().getValue().equals(HAOHAN_PLATFORM)) { + db = new HaoHanAbilityImpl(); + + // 初始化设备 + db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); + + MulReturnType ret = db.runDispose("192.168.3.5", DisposeCapacityType.CLEANUP, + nfDirection, ddoSAttackType, -1L); + + Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); + } + } + + /** + * T 2 stop dispose task. + */ + @Test + public void t2_stopDisposeTest() { + DisposeAbility db; + + NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN}; + + DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION}; + + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("10.88.77.88") + .ipPort("18080") + .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) + .areaCode(0) + .deviceName("中移杭研实验室浩瀚清洗设备") + .manufacturer("Haohan") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("DDoSClean/clean") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); + + String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; + String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); + String url = httpType + addr + "/" + dev.getUrlPath(); + + if (dev.getDeviceType().getValue().equals(HAOHAN_PLATFORM)) { + db = new HaoHanAbilityImpl(); + + // 初始化设备 + db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); + + Assert.assertTrue(db.getDeviceLinkStatus()); + MulReturnType ret = db.stopDispose("192.168.3.5", DisposeCapacityType.CLEANUP, + nfDirection, ddoSAttackType, -1L); + + Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); + } + } +}