1. 添加策略模板API文档
This commit is contained in:
@@ -60,7 +60,8 @@ class ProtectObjectServiceTest {
|
||||
|
||||
@Test
|
||||
void updateProtectObject() {
|
||||
Integer testId = 300;
|
||||
List<ProtectObject> protectObjects = protectObjectService.queryProtectObjects(null, null, 1, 1);
|
||||
Integer testId = protectObjects.get(0).getProtectObjectId();
|
||||
|
||||
protectObject.setProtectObjectName("x-1-1");
|
||||
protectObject.setProtectObjectId(testId);
|
||||
@@ -71,7 +72,7 @@ class ProtectObjectServiceTest {
|
||||
@Test
|
||||
void deleteProtectObject() {
|
||||
int testNum = 0;
|
||||
for (int i = 0; i < 100000; i++ ) {
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
if (protectObjectService.queryProtectObject(i) != null) {
|
||||
testNum = i;
|
||||
break;
|
||||
@@ -84,7 +85,7 @@ class ProtectObjectServiceTest {
|
||||
@Test
|
||||
void deleteProtectObjects() {
|
||||
ArrayList<Integer> testNums = new ArrayList<>();
|
||||
for (int i = 0; i < 100000; i++ ) {
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
if (protectObjectService.queryProtectObject(i) != null) {
|
||||
testNums.add(i);
|
||||
if (testNums.size() > 5) {
|
||||
@@ -102,7 +103,7 @@ class ProtectObjectServiceTest {
|
||||
@Test
|
||||
void changeProtectObjectAuditStatus() {
|
||||
int testNum = 0;
|
||||
for (int i = 300; i < 100000; i++ ) {
|
||||
for (int i = 300; i < 100000; i++) {
|
||||
if (protectObjectService.queryProtectObject(i) != null) {
|
||||
testNum = i;
|
||||
break;
|
||||
|
||||
@@ -7,7 +7,9 @@ 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 java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -57,8 +59,24 @@ class TemplateServiceTest {
|
||||
|
||||
@Test
|
||||
void testNewTemplate() {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
try {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
} catch (DuplicateKeyException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,9 +92,9 @@ class TemplateServiceTest {
|
||||
|
||||
@Test
|
||||
void testUpdateTemplateSuccess() {
|
||||
List<Template> templates = templateService.queryTemplates("反射", 1, 6);
|
||||
List<Template> templates = templateService.queryTemplates("DDOS", 1, 1);
|
||||
Template testTemplate = templates.get(0);
|
||||
testTemplate.setTemplateName("洪泛型DDOS攻击");
|
||||
testTemplate.setTemplateName("洪泛型DDOS攻击-"+LocalDateTime.now());
|
||||
|
||||
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.DataIntegrityViolationException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -57,7 +58,7 @@ class TaskServiceTest {
|
||||
@Test
|
||||
void testNewTaskLostData() {
|
||||
this.task.setTaskStartTime(null);
|
||||
assertThrows(PersistenceException.class, () -> {
|
||||
assertThrows(DataIntegrityViolationException.class, () -> {
|
||||
Long taskId = taskService.newTask(task);
|
||||
assertTrue(taskId > 0);
|
||||
});
|
||||
@@ -101,7 +102,7 @@ class TaskServiceTest {
|
||||
|
||||
@Test
|
||||
void testGetStaticCommands() {
|
||||
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(26L);
|
||||
assertEquals(3, taskCommandInfos.size());
|
||||
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
||||
assertNotNull(taskCommandInfos);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ class CommandServiceTest {
|
||||
|
||||
private final CommandService commandService;
|
||||
private TaskCommandInfo taskCommandInfo;
|
||||
private Command command;
|
||||
|
||||
private Long startTime;
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.realtime.protection.server.user.login;
|
||||
|
||||
import com.realtime.protection.configuration.entity.user.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class LoginServiceTest {
|
||||
|
||||
private final LoginService loginService;
|
||||
|
||||
@Autowired
|
||||
LoginServiceTest(LoginService loginService) {
|
||||
this.loginService = loginService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginFail() {
|
||||
User user = new User();
|
||||
user.setPassword("12345");
|
||||
user.setUsername("endera");
|
||||
|
||||
assertThrows(LoginException.class, () -> loginService.login(user));
|
||||
|
||||
user.setUsername("");
|
||||
user.setPassword("");
|
||||
assertThrows(LoginException.class, () -> loginService.login(user));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginSuccess() {
|
||||
User user = new User();
|
||||
user.setUsername("endera");
|
||||
user.setPassword("123456");
|
||||
|
||||
assertDoesNotThrow(() -> assertEquals(1, loginService.login(user)));
|
||||
}
|
||||
}
|
||||
@@ -73,15 +73,4 @@ class WhiteListServiceTest {
|
||||
whiteListService.updateWhiteListObjectAuditStatus(7, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWhiteListCommandJudge() {
|
||||
Command command = new Command();
|
||||
command.setDestinationIP("128.1.1.123");
|
||||
command.setMaskDestinationIP("255.255.255.0");
|
||||
command.setDestinationPort("81");
|
||||
|
||||
List<WhiteListObject> whitelists = whiteListService.whiteListCommandJudge(command);
|
||||
System.out.println(whitelists);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user