1、重构Template,一个策略模板只有一个防护等级,并且把防护等级配置都放在策略模板中。补充新Template的crud、审批等方法,并写swager
This commit is contained in:
@@ -63,7 +63,7 @@ public class AlertMessageTest {
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2);
|
||||
dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2,null,null,null);
|
||||
|
||||
|
||||
Task task = new Task();
|
||||
@@ -84,24 +84,24 @@ public class AlertMessageTest {
|
||||
//审核状态
|
||||
taskService.changeTaskAuditStatus(taskId, 2);
|
||||
//启动任务
|
||||
// stateChangeService.changeState(2, taskId, false);
|
||||
stateChangeService.changeState(2, taskId, false);
|
||||
|
||||
// for (int i = 0 ; i< 5; i++) {
|
||||
// AlertMessage alert = new AlertMessage();
|
||||
// FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
// fiveTupleWithMask.setSourceIP("111.1.1." + i);
|
||||
// fiveTupleWithMask.setDestinationIP("222.22.2." + i);
|
||||
// fiveTupleWithMask.setSourcePort("111");
|
||||
// fiveTupleWithMask.setDestinationPort("222");
|
||||
// fiveTupleWithMask.setProtocol("tcp");
|
||||
//
|
||||
// alert.setDynamicRuleId(dynamicRuleId);
|
||||
// alert.setTaskId(taskId);
|
||||
// alert.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
// alert.setContent("testcontent");
|
||||
// alert.setProtectIsSrcOrDst(1);
|
||||
// alertMessageService.processAlertMessage(alert);
|
||||
// }
|
||||
for (int i = 0 ; i< 5; i++) {
|
||||
AlertMessage alert = new AlertMessage();
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
fiveTupleWithMask.setSourceIP("111.1.1." + i);
|
||||
fiveTupleWithMask.setDestinationIP("222.22.2." + i);
|
||||
fiveTupleWithMask.setSourcePort("111");
|
||||
fiveTupleWithMask.setDestinationPort("222");
|
||||
fiveTupleWithMask.setProtocol("tcp");
|
||||
|
||||
alert.setDynamicRuleId(dynamicRuleId);
|
||||
alert.setTaskId(taskId);
|
||||
alert.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
alert.setContent("testcontent");
|
||||
alert.setProtectIsSrcOrDst(1);
|
||||
alertMessageService.processAlertMessage(alert);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.realtime.protection.server.defense.templatenew;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
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.dao.DuplicateKeyException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
public class NewTemplateServiceTest {
|
||||
|
||||
private final TemplateService templateService;
|
||||
private TemplateNew template;
|
||||
private Long startTime;
|
||||
|
||||
|
||||
@Autowired
|
||||
NewTemplateServiceTest(TemplateService templateService) {
|
||||
this.templateService = templateService;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void mockTemplate() {
|
||||
|
||||
template = new TemplateNew();
|
||||
|
||||
template.setTemplateName("反射型DDOS攻击");
|
||||
template.setSourceSystem("xxxx系统");
|
||||
template.setEventType("dsdos");
|
||||
template.setHasPeerIP(true);
|
||||
template.setProtectLevel("2");
|
||||
|
||||
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void summary() {
|
||||
Long endTime = System.currentTimeMillis();
|
||||
System.out.printf("total time: %d ms", endTime - startTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNewTemplate() {
|
||||
try {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
} catch (DuplicateKeyException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertThrows(DuplicateKeyException.class, () -> {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
});
|
||||
assertDoesNotThrow(() -> {
|
||||
template.setTemplateName("反射型DDOS攻击-" + LocalDateTime.now());
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
dynamicRuleService.updateAuditStatus(dynamicRuleId, 2);
|
||||
dynamicRuleService.updateAuditStatus(dynamicRuleId, 2,null,null,null);
|
||||
|
||||
|
||||
Task task = new Task();
|
||||
|
||||
@@ -265,7 +265,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
||||
|
||||
List<Integer> staticRuleIds = new ArrayList<>();
|
||||
staticRuleIds.add(staticRuleId);
|
||||
staticRuleService.updateAuditStatus(staticRuleId, 2);
|
||||
staticRuleService.updateAuditStatus(staticRuleId, 2,null,null,null);
|
||||
|
||||
task.setStaticRuleIds(staticRuleIds);
|
||||
|
||||
@@ -307,7 +307,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2);
|
||||
dynamicRuleService.updateAuditStatus(object.getDynamicRuleId(), 2,null,null,null);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user