1. 删除Command类,Doris数据库改用TaskCommandInfo类作为实体类
2. 取消FailedState和GeneratingState的使用 3. 修改部分bug
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package com.realtime.protection;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
|
||||
@SpringBootTest
|
||||
class ProtectionApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
@Rollback
|
||||
@DSTransactional
|
||||
public class ProtectionApplicationTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class ProtectObjectServiceTest {
|
||||
class ProtectObjectServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
private final ProtectObjectService protectObjectService;
|
||||
private ProtectObject protectObject;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.server.defense.template;
|
||||
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -15,7 +16,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class TemplateServiceTest {
|
||||
class TemplateServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
private final TemplateService templateService;
|
||||
private Template template;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.server.rule.dynamic;
|
||||
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.server.rule.dynamicrule.DynamicRuleService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -11,7 +12,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
public class DynamicRuleServiceTest {
|
||||
public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
private final DynamicRuleService dynamicRuleService;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.server.rule.staticrule;
|
||||
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
public class StaticRuleServiceTest {
|
||||
public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
private final StaticRuleService staticRuleService;
|
||||
private StaticRuleObject staticRuleTest;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection.server.task;
|
||||
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class TaskServiceTest {
|
||||
class TaskServiceTest extends ProtectionApplicationTests {
|
||||
private final TaskService taskService;
|
||||
private Task task;
|
||||
|
||||
@@ -35,9 +36,9 @@ class TaskServiceTest {
|
||||
task.setTaskEndTime(taskEndTime);
|
||||
task.setTaskAct("阻断");
|
||||
task.setTaskType(1);
|
||||
task.setStaticRuleIds(List.of(1L, 2L));
|
||||
task.setStaticRuleIds(List.of(1, 2));
|
||||
task.setDynamicRuleIds(List.of());
|
||||
task.setTaskCreateUserId(1L);
|
||||
task.setTaskCreateUserId(1);
|
||||
task.setTaskCreateUsername("xxx");
|
||||
task.setTaskCreateDepart("xxx");
|
||||
}
|
||||
@@ -76,7 +77,7 @@ class TaskServiceTest {
|
||||
void testUpdateTasks() {
|
||||
Task originalTask = taskService.queryTask(38L);
|
||||
|
||||
originalTask.setStaticRuleIds(List.of(16L, 17L, 18L, 19L));
|
||||
originalTask.setStaticRuleIds(List.of(16, 17, 18, 19));
|
||||
originalTask.setTaskName("修改测试");
|
||||
|
||||
assertTrue(taskService.updateTask(originalTask));
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.realtime.protection.server.task.status;
|
||||
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
@@ -10,13 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
@SpringBootTest
|
||||
class CommandServiceTest {
|
||||
class CommandServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
private final CommandService commandService;
|
||||
private TaskCommandInfo taskCommandInfo;
|
||||
@@ -37,8 +38,10 @@ class CommandServiceTest {
|
||||
taskCommandInfo.setFrequency(30);
|
||||
taskCommandInfo.setTaskId(30L);
|
||||
taskCommandInfo.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
taskCommandInfo.setOperation("阻断");
|
||||
taskCommandInfo.setEndTime(LocalDateTime.now().plusDays(1));
|
||||
taskCommandInfo.setTaskAct("阻断");
|
||||
taskCommandInfo.setStartTime(LocalDateTime.now().plusDays(10));
|
||||
taskCommandInfo.setEndTime(LocalDateTime.now().plusDays(140));
|
||||
taskCommandInfo.setFrequency(30);
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -56,12 +59,13 @@ class CommandServiceTest {
|
||||
|
||||
@Test
|
||||
void createCommands() {
|
||||
List<TaskCommandInfo> taskCommandInfos = new ArrayList<>();
|
||||
List<TaskCommandInfo> taskCommandInfos = ListUtils.newArrayListWithExpectedSize(100);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int port = i + 1000;
|
||||
taskCommandInfo = new TaskCommandInfo();
|
||||
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
|
||||
taskCommandInfo.setFiveTupleWithMask(new FiveTupleWithMask());
|
||||
taskCommandInfo.setTaskId(24L);
|
||||
taskCommandInfo.setTaskId(30L);
|
||||
taskCommandInfo.setTaskAct("阻断");
|
||||
taskCommandInfo.getFiveTupleWithMask().setSourcePort(Integer.toString(port));
|
||||
taskCommandInfo.setStartTime(LocalDateTime.now().plusDays(5));
|
||||
taskCommandInfo.setEndTime(LocalDateTime.now().plusDays(10));
|
||||
@@ -70,6 +74,12 @@ class CommandServiceTest {
|
||||
taskCommandInfos.add(taskCommandInfo);
|
||||
}
|
||||
|
||||
for (TaskCommandInfo info : taskCommandInfos) {
|
||||
if (info.getFrequency() == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> commandService.createCommands(taskCommandInfos));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.realtime.protection.server.whitelist;
|
||||
|
||||
import com.realtime.protection.configuration.entity.task.Command;
|
||||
import com.realtime.protection.ProtectionApplicationTests;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
class WhiteListServiceTest {
|
||||
class WhiteListServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
private final WhiteListService whiteListService;
|
||||
private WhiteListObject whiteListObject;
|
||||
@@ -78,13 +79,13 @@ class WhiteListServiceTest {
|
||||
@Test
|
||||
void testWhiteListCommandJudge() {
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
Command command = new Command();
|
||||
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
|
||||
fiveTupleWithMask.setDestinationIP("128.1.1.123");
|
||||
fiveTupleWithMask.setMaskDestinationIP("255.255.255.0");
|
||||
fiveTupleWithMask.setDestinationPort("80");
|
||||
command.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
taskCommandInfo.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
|
||||
List<WhiteListObject> whitelists = whiteListService.whiteListCommandJudge(command);
|
||||
List<WhiteListObject> whitelists = whiteListService.whiteListCommandJudge(taskCommandInfo);
|
||||
System.out.println(whitelists);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user