1. 更新前端界面和Nginx配置

2. 更新Dockerfile设置
This commit is contained in:
EnderByEndera
2024-01-24 16:36:03 +08:00
parent 02dd20743f
commit 0da97a5254
34 changed files with 300 additions and 69 deletions

View File

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -56,6 +57,29 @@ class ProtectObjectServiceTest extends ProtectionApplicationTests {
assertTrue(success);
}
@Test
void queryProtectObject() {
List<ProtectObject> protectObjects = new ArrayList<>();
String testName = "xxx" + LocalDateTime.now();
protectObject.setProtectObjectName(testName);
for (int i = 0; i < 100; i++) {
protectObject.setProtectObjectId(null);
protectObjectService.newProtectObject(protectObject);
protectObjects.add(protectObject);
}
protectObjects.forEach(protectObject -> {
assertNotNull(protectObjectService.queryProtectObject(protectObject.getProtectObjectId()));
assertNotNull(protectObjectService.queryProtectObjects(null,
protectObject.getProtectObjectId(), 1, 1));
});
assertEquals(100,
protectObjectService.queryProtectObjects(testName, null, 1, 1000).size());
}
@Test
void updateProtectObject() {
List<ProtectObject> protectObjects = protectObjectService.queryProtectObjects(null, null, 1, 1);

View File

@@ -12,8 +12,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cglib.core.Local;
import org.springframework.dao.DataIntegrityViolationException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -89,8 +91,48 @@ class TaskServiceTest extends ProtectionApplicationTests {
@Test
void testQueryTasks() {
String testName = "test query";
String testCreateName = "xxx query";
for (int i = 0; i < 10; i++) {
task.setTaskName(testName);
task.setTaskCreateUsername(testCreateName);
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
null, null, null, null, 1, 5);
List<Integer> staticRuleIds = new ArrayList<>();
staticRuleObjects.forEach(staticRuleObject ->
staticRuleIds.add(staticRuleObject.getStaticRuleId()));
task.setStaticRuleIds(staticRuleIds);
List<DynamicRuleObject> dynamicRuleObjects = dynamicRuleService.queryDynamicRuleObject(
null, null, null, null, 1, 5
);
List<Integer> dynamicRuleIds = new ArrayList<>();
dynamicRuleObjects.forEach(dynamicRuleObject ->
dynamicRuleIds.add(dynamicRuleObject.getDynamicRuleId()));
task.setDynamicRuleIds(dynamicRuleIds);
assertDoesNotThrow(() -> {
Long taskId = taskService.newTask(task);
assertTrue(taskId > 0);
});
assertTrue(task.getTaskId() > 0);
}
List<Task> tasks = taskService.queryTasks(null, null, null, null, 1, 10);
assertTrue(tasks.get(0).getTaskId() > 0);
assertEquals(10, tasks.size());
tasks = taskService.queryTasks(0, null, null, null, 1, 10);
assertEquals(10, tasks.size());
tasks.forEach(task -> assertEquals(0, task.getTaskStatus()));
tasks = taskService.queryTasks(null, 0, null, null, 1, 10);
assertEquals(0, tasks.size());
tasks = taskService.queryTasks(null, null, testName, null, 1, 10);
assertEquals(10, tasks.size());
tasks.forEach(task -> assertEquals(testName, task.getTaskName()));
}
@Test
@@ -117,7 +159,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
.get(0).getTaskId();
assertTrue(taskService.deleteTask(testNum));
assertFalse(taskService.deleteTask(235235L));
assertFalse(taskService.deleteTask(235156235L)); // 尝试一个不可能达到的数字
}
@Test

View File

@@ -3,8 +3,10 @@ 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.Task;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.server.command.CommandService;
import com.realtime.protection.server.task.TaskService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -21,23 +23,26 @@ import static org.junit.jupiter.api.Assertions.*;
class CommandServiceTest extends ProtectionApplicationTests {
private final CommandService commandService;
private final TaskService taskService;
private TaskCommandInfo taskCommandInfo;
private Long startTime;
@Autowired
CommandServiceTest(CommandService commandService) {
CommandServiceTest(CommandService commandService, TaskService taskService) {
this.commandService = commandService;
this.taskService = taskService;
}
@BeforeEach
void mockCommand() {
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
fiveTupleWithMask.setMaskSourceIP("192.168.155.24");
taskCommandInfo = new TaskCommandInfo();
taskCommandInfo.setFrequency(30);
taskCommandInfo.setTaskId(30L);
taskCommandInfo.setTaskId(task.getTaskId());
taskCommandInfo.setFiveTupleWithMask(fiveTupleWithMask);
taskCommandInfo.setTaskAct("阻断");
taskCommandInfo.setStartTime(LocalDateTime.now().plusDays(10));
@@ -61,11 +66,12 @@ class CommandServiceTest extends ProtectionApplicationTests {
@Test
void createCommands() {
List<TaskCommandInfo> taskCommandInfos = ListUtils.newArrayListWithExpectedSize(100);
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
for (int i = 0; i < 100; i++) {
int port = i + 1000;
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
taskCommandInfo.setFiveTupleWithMask(new FiveTupleWithMask());
taskCommandInfo.setTaskId(30L);
taskCommandInfo.setTaskId(task.getTaskId());
taskCommandInfo.setTaskAct("阻断");
taskCommandInfo.getFiveTupleWithMask().setSourcePort(Integer.toString(port));
taskCommandInfo.setStartTime(LocalDateTime.now().plusDays(5));
@@ -86,7 +92,8 @@ class CommandServiceTest extends ProtectionApplicationTests {
@Test
void queryCommandInfos() {
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(30L,
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(task.getTaskId(),
null, null, null, null,1, 5);
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());