Merge remote-tracking branch 'origin/master' into haskafka

This commit is contained in:
PushM
2024-04-23 21:10:33 +08:00
18 changed files with 269 additions and 81 deletions

View File

@@ -25,6 +25,7 @@ public class DynamicTaskInfo {
private Integer ruleId;
private String sourceSystem;
private String eventType;
private Long logRuleId;
// 从防护对象列表中获取
private List<SimpleProtectObject> protectObjects;

View File

@@ -71,7 +71,7 @@ public class AuditAdvice implements ResponseBodyAdvice<ResponseResult> {
return null;
})
.doOnError(WebClientRequestException.class, err ->
log.warn("审计服务器遭遇异常" + err.getMessage()));
log.warn("审计服务器遭遇异常{}", err.getMessage()));
mono.subscribe(AuditAdvice::handleMono);

View File

@@ -3,6 +3,7 @@ package com.realtime.protection.server.defense.object;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -74,6 +75,14 @@ public class ProtectObjectService {
}
public Boolean updateProtectObject(ProtectObject protectObject) {
if (!protectObjectMapper.queryProtectObject(protectObject.getProtectObjectId())
.getProtectObjectAuditStatus()
.equals(AuditStatusEnum.AUDITED.getNum())) {
return false;
}
protectObject.setProtectObjectAuditStatus(AuditStatusEnum.PENDING.getNum());
return protectObjectMapper.updateProtectObject(protectObject);
}

View File

@@ -64,6 +64,13 @@ public class TemplateController implements TemplateControllerApi {
return ResponseResult.ok().setData("template", template);
}
@Override
@GetMapping("/query/level")
public ResponseResult queryTemplateProtectLevels() {
List<Template> templates = templateService.queryTemplatesShort();
return ResponseResult.ok().setData("templates", templates);
}
@Override
@PostMapping("/{templateId}/update")
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,

View File

@@ -41,7 +41,6 @@ public interface TemplateControllerApi {
""",
description = """
"success": 新建防御策略模板是否成功
"template_id": 新建防御策略模板ID
"""
)
@@ -104,7 +103,8 @@ public interface TemplateControllerApi {
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
"running_tasks": 0,
"description": "xxx"
},
{
"template_id": 24,
@@ -140,7 +140,8 @@ public interface TemplateControllerApi {
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
"running_tasks": 0,
"description": "xxx"
}
],
"total_num": 708
@@ -149,17 +150,17 @@ public interface TemplateControllerApi {
""",
description = """
"template_id": 防御策略模板ID
"template_name": 防御策略模板名称
"protect_level_low": 防御策略模板日常态数据
"protect_level_medium": 防御策略模板应急态数据
"protect_level_high": 防御策略模板紧急态数据
"template_used_times": 防御策略模板使用次数
"running_tasks": 防御策略模板任务运行数量
"""
)
@@ -231,24 +232,25 @@ public interface TemplateControllerApi {
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
"running_tasks": 0,
"description": "xxx"
}
}
}
""",
description = """
"template_id": 防御策略模板ID
"template_name": 防御策略模板名称
"protect_level_low": 防御策略模板日常态数据
"protect_level_medium": 防御策略模板应急态数据
"protect_level_high": 防御策略模板紧急态数据
"template_used_times": 防御策略模板使用次数
"running_tasks": 防御策略模板任务运行数量
"""
)
@@ -261,6 +263,58 @@ public interface TemplateControllerApi {
)
ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException;
@GetMapping("/query/level")
@Operation(
summary = "查询所有策略模板是否含有不同类型防护等级",
description = "查询所有的策略模板是否还有日常态/应急态/紧急态三种防护等级",
responses = {
@ApiResponse(
description = "返回策略模板防护等级信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"templates": [
{
"template_id": 18,
"template_name": "洪泛型DDOS攻击-2024-01-18T16:46:14.640176900",
"has_protect_level_low": false,
"has_protect_level_medium": true,
"has_protect_level_high": false
},
{
"template_id": 24,
"template_name": "反射型DDOS攻击-2024-01-12T17:52:32.077477700",
"has_protect_level_low": false,
"has_protect_level_medium": true,
"has_protect_level_high": true
}
],
"total_num": 708
}
}
""",
description =
"""
"has_protect_level_low": 是否包含日常态防护等级
"has_protect_level_medium": 是否包含应急态防护等级
"has_protect_level_high": 是否包含紧急态防护等级
"""
)
)
)
}
)
ResponseResult queryTemplateProtectLevels();
@PostMapping("/{templateId}/update")
@Operation(
summary = "更新防御策略模板信息",
@@ -285,7 +339,7 @@ public interface TemplateControllerApi {
""",
description = """
"success": 更新是否成功
"template_id": 更新的策略模板ID
"""
)
@@ -323,7 +377,7 @@ public interface TemplateControllerApi {
""",
description = """
"success": 删除是否成功
"template_id": 删除的策略模板ID
"""
)

View File

@@ -28,9 +28,7 @@ public class DynamicRuleService {
//判断protectObject id是否有效
boolean ProtectObjIdValid = dynamicRule.getProtectObjectIds().stream()
.allMatch(
protectObjectId -> dynamicRuleMapper.queryProtectObjectById(protectObjectId)
);
.allMatch(dynamicRuleMapper::queryProtectObjectById);
if (!ProtectObjIdValid) {
throw new IllegalArgumentException("protect object id is invalid");
}
@@ -125,9 +123,7 @@ public class DynamicRuleService {
dynamicRuleMapper.deleteDynamicRuleProtectObjectConcat(dynamicRuleId);
//新增DynamicRule关联的ProtectObject
boolean ProtectObjIdValid = dynamicRuleObject.getProtectObjectIds().stream()
.allMatch(
protectObjectId -> dynamicRuleMapper.queryProtectObjectById(protectObjectId)
);
.allMatch(dynamicRuleMapper::queryProtectObjectById);
if (!ProtectObjIdValid) {
throw new IllegalArgumentException("protect object id is invalid");
}

View File

@@ -114,8 +114,8 @@ public class StaticRuleService {
throw new IllegalArgumentException("未知的静态规则ID");
}
if (Objects.equals(staticRuleObject.getStaticRuleAuditStatus(), AuditStatusEnum.USING.getNum())) {
throw new IllegalArgumentException("静态规则当前正在使用,无法更新");
if (!staticRuleObject.getStaticRuleAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
throw new IllegalStateException("无法修改该静态规则,因为其审核状态未处于" + AuditStatusEnum.AUDITED);
}
if (!RuleEnum.checkValidate(object)) {
@@ -125,6 +125,7 @@ public class StaticRuleService {
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
//按id查询该静态规则的used_task_id字段如果不为空则不能修改
object.setStaticRuleModifyTime(LocalDateTime.now());
object.setStaticRuleAuditStatus(AuditStatusEnum.PENDING.getNum());
//修改静态规则
return staticRuleMapper.updateStaticRule(id, object);
}

View File

@@ -12,7 +12,9 @@ import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/task")
@@ -70,9 +72,10 @@ public class TaskController implements TaskControllerApi {
@RequestParam(value = "task_type", required = false) Integer taskType,
@RequestParam(value = "task_name", required = false) String taskName,
@RequestParam(value = "task_creator", required = false) String taskCreator,
@RequestParam(value = "audit_status", required = false) Integer auditStatus,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize) {
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus, page, pageSize);
return ResponseResult.ok()
.setData("task_list", tasks)
.setData("total_num", taskService.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator));
@@ -154,4 +157,28 @@ public class TaskController implements TaskControllerApi {
.setData("success", commandService.setCommandJudged(commandId, isJudged))
.setData("command_id", commandId);
}
/**
* 批量修改审核状态
*/
@PostMapping("/auditbatch")
public ResponseResult updateTaskAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
return new ResponseResult(400, "id or status is invalid")
.setData("tasks_id", errorIds)
.setData("success", false);
}
return ResponseResult.ok()
.setData("success", taskService.updateAuditStatusBatch(idsWithAuditStatusMap));
}
}

View File

@@ -44,9 +44,9 @@ public interface TaskControllerApi {
""",
description = """
"task_name": 任务名称
"success": 任务添加是否成功
"task_id": 新建任务ID
"""
)
@@ -83,9 +83,9 @@ public interface TaskControllerApi {
""",
description = """
"task_name": 任务名称
"success": 任务添加是否成功
"task_id": 新建任务ID
"""
)
@@ -149,27 +149,27 @@ public interface TaskControllerApi {
""",
description = """
"task_id": 任务ID
"task_name": 任务名称
"task_start_time": 任务开始时间
"task_end_time": 任务结束时间
"task_type": 任务类型静态、动态、研判后对应123
"task_create_username": 任务创建人名称
"task_create_depart": 任务创建人处室
"static_rule_ids": 静态规则ID列表
"dynamic_rule_ids": 动态规则ID列表
"task_status": 任务当前运行状态
"task_audit_status": 任务当前审核状态
"total_num": 任务总数
"""
)
@@ -181,6 +181,7 @@ public interface TaskControllerApi {
@Parameter(name = "task_type", description = "任务类型1为静态2为实时3为研判后"),
@Parameter(name = "task_name", description = "任务名称"),
@Parameter(name = "task_creator", description = "任务创建人"),
@Parameter(name = "audit_status", description = "审批状态"),
@Parameter(name = "page", description = "页码", example = "1"),
@Parameter(name = "page_size", description = "每页查询个数", example = "10")
}
@@ -189,6 +190,7 @@ public interface TaskControllerApi {
@RequestParam(value = "task_type", required = false) Integer taskType,
@RequestParam(value = "task_name", required = false) String taskName,
@RequestParam(value = "task_creator", required = false) String taskCreator,
@RequestParam(value = "audit_status", required = false) Integer auditStatus,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize);
@@ -227,25 +229,25 @@ public interface TaskControllerApi {
""",
description = """
"task_id": 任务ID
"task_name": 任务名称
"task_start_time": 任务开始时间
"task_end_time": 任务结束时间
"task_type": 任务类型静态、动态、研判后对应123
"task_create_username": 任务创建人名称
"task_create_depart": 任务创建人处室
"static_rule_ids": 静态规则ID列表
"dynamic_rule_ids": 动态规则ID列表
"task_status": 任务当前运行状态
"task_audit_status": 任务当前审核状态
"""
)
@@ -280,7 +282,7 @@ public interface TaskControllerApi {
""",
description = """
"success": 更新是否成功
"task_id": 更新任务ID
"""
)
@@ -321,9 +323,9 @@ public interface TaskControllerApi {
""",
description = """
"success": 任务审核状态修改是否成功
"task_id": 任务ID
"audit_status": 任务当前审核状态
"""
)
@@ -362,7 +364,7 @@ public interface TaskControllerApi {
""",
description = """
"success": 任务删除是否成功
"task_id": 删除的任务ID
"""
)
@@ -453,15 +455,15 @@ public interface TaskControllerApi {
""",
description = """
"task_act": 任务行为
"is_valid": 指令是否生效
"five_tuple_with_mask": 指令五元组信息
"command_send_times": 指令下发次数
"command_success_times": 指令下发成功次数
"uuid": 指令UUID
"""
)
@@ -509,7 +511,7 @@ public interface TaskControllerApi {
""",
description = """
"success": 指令下发是否成功
"command_uuid": 指令UUID
"""
)

View File

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
@Mapper
public interface TaskMapper {
@@ -23,6 +24,7 @@ public interface TaskMapper {
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
@Param("task_audit_status") Integer auditStatus,
@Param("page") Integer page, @Param("page_size") Integer pageSize);
Task queryTask(@Param("task_id") Long taskId);
@@ -57,4 +59,6 @@ public interface TaskMapper {
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
@Param("task_name") String taskName, @Param("task_creator") String taskCreator);
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
}

View File

@@ -4,22 +4,30 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
import com.realtime.protection.configuration.entity.task.Task;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
@Service
@Slf4j
@DS("mysql")
public class TaskService {
private final TaskMapper taskMapper;
private final SqlSessionWrapper sqlSessionWrapper;
public TaskService(TaskMapper taskMapper) {
public TaskService(TaskMapper taskMapper,SqlSessionWrapper sqlSessionWrapper) {
this.taskMapper = taskMapper;
this.sqlSessionWrapper = sqlSessionWrapper;
}
@Transactional
@@ -28,6 +36,8 @@ public class TaskService {
task.setTaskCreateUsername("xxx");
task.setTaskCreateDepart("xxx");
// todo: 添加新建任务时,将动态/静态规则从“已审核”修改为“使用中”
taskMapper.newTask(task);
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
@@ -42,8 +52,9 @@ public class TaskService {
@Transactional
public List<Task> queryTasks(Integer taskStatus,
Integer taskType, String taskName, String taskCreator,
Integer auditStatus,
Integer page, Integer pageSize) {
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus, page, pageSize);
for (Task task : tasks) {
if (task == null) {
continue;
@@ -70,6 +81,12 @@ public class TaskService {
@Transactional
public Boolean updateTask(Task task) {
if (!Objects.equals(taskMapper.queryTaskAuditStatus(task.getTaskId()), AuditStatusEnum.AUDITED.getNum())) {
return false;
}
task.setTaskAuditStatus(AuditStatusEnum.PENDING.getNum());
taskMapper.updateTask(task);
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
@@ -139,7 +156,35 @@ public class TaskService {
return taskMapper.queryTasksByStatus(StateEnum.FINISHED.getStateNum());
}
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName,String taskCreator) {
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
}
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =
mapper -> map -> {
if (map == null || map.isEmpty()) {
return false;
}
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
if (idWithAuditStatusBatch.size() < 100) {
continue;
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
}
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(TaskMapper.class, updateTaskAuditStatusFunction, idsWithAuditStatusMap);
}
}

View File

@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleOb
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
import org.springframework.stereotype.Service;
@@ -102,6 +103,12 @@ public class WhiteListService {
}
public Integer updateWhiteListObject(Integer id, WhiteListObject object) {
if (!whiteListMapper.queryWhiteListObjectAuditStuatusById(id).equals(AuditStatusEnum.AUDITED.getNum())) {
throw new IllegalStateException("无法修改白名单信息,因为其并未处于" + AuditStatusEnum.AUDITED + "状态");
}
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.toString());
return whiteListMapper.updateWhiteListObject(id, object);
}

View File

@@ -26,7 +26,7 @@
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
insert into t_command(
COMMAND_ID, TASK_ID, TASK_ACT, TASK_NAME, EVENT_TYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
COMMAND_ID, TASK_ID, TASK_ACT, TASKNAME, EVENT_TYPE, DEPARTMENT, DISTRIBUTEPOINT, FREQUENCY,
ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL,
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID,
IS_JUDGED,

View File

@@ -47,7 +47,8 @@
<select id="queryProtectObjects" resultMap="protectObjectMap">
SELECT
protect_object_id, protect_object_name, protect_object_system_name, INET_NTOA(protect_object_ip),
protect_object_id, protect_object_name, protect_object_system_name,
INET_NTOA(protect_object_ip) as protect_object_ip,
protect_object_port, protect_object_url, protect_object_protocol, protect_object_audit_status
FROM t_protect_object
<where>

View File

@@ -71,6 +71,9 @@
<if test="task_creator != null">
AND task_create_username LIKE CONCAT('%', #{task_creator}, '%')
</if>
<if test="task_audit_status != null">
AND task_audit_status = #{task_audit_status}
</if>
</where>
LIMIT ${(page - 1) * page_size}, #{page_size}
</select>
@@ -78,7 +81,7 @@
<select id="queryStaticRuleIdsFromTaskId" resultType="java.lang.Integer">
SELECT static_rule_id
FROM t_static_rule
WHERE static_rule_used_task_id = #{task_id}
WHERE static_rule_used_task_id = #{task_id} AND static_rule_audit_status = true
</select>
<select id="queryDynamicRuleIdsFromTaskId" resultType="java.lang.Integer">
@@ -145,6 +148,21 @@
WHERE task_id = #{task_id}
</update>
<!-- 批量审核 -->
<update id="updateAuditStatusByIdBatch">
update t_task
set task_audit_status = CASE task_id
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
WHEN #{id} THEN #{auditStatus}
</foreach>
ELSE task_audit_status
END
WHERE task_id IN
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteTask">
DELETE
FROM t_task
@@ -234,6 +252,7 @@
<result column="task_start_time" property="startTime"/>
<result column="task_end_time" property="endTime"/>
<result column="rule_id" property="ruleId"/>
<result column="log_rule_id" property="logRuleId"/>
<result column="source_system" property="sourceSystem"/>
<result column="event_type" property="eventType"/>
<collection property="protectObjects">
@@ -252,6 +271,7 @@
tdr.dynamic_rule_id as rule_id,
strategy_template_source_system as source_system,
strategy_template_name as event_type,
tdr.log_rule_id,
INET_NTOA(protect_object_ip),
protect_object_port,
protect_object_url,

View File

@@ -1,5 +1,5 @@
upstream server_list {
least_conn;
ip_hash; # todo: 暂时采用该方式保持会话连接
server ${SPRINGBOOT_FIRST_URL};
server ${SPRINGBOOT_SECOND_URL};
server ${SPRINGBOOT_THIRD_URL};

View File

@@ -16,7 +16,9 @@ import org.springframework.dao.DataIntegrityViolationException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
@@ -54,7 +56,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
@Test
void testNewTaskSuccess() {
for (int i = 1; i < 1000; i++) {
for (int i = 1; i < 10; i++) {
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
null, null, null, null, i, 2);
List<Integer> staticRuleIds = new ArrayList<>();
@@ -118,17 +120,17 @@ class TaskServiceTest extends ProtectionApplicationTests {
}
List<Task> tasks = taskService.queryTasks(null, null, null, null, 1, 10);
List<Task> tasks = taskService.queryTasks(null, null, null, null, null, 1, 10);
assertEquals(10, tasks.size());
tasks = taskService.queryTasks(0, null, null, null, 1, 10);
tasks = taskService.queryTasks(0, null, 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);
tasks = taskService.queryTasks(null, 0, null, null, null, 1, 10);
assertEquals(0, tasks.size());
tasks = taskService.queryTasks(null, null, testName, null, 1, 10);
tasks = taskService.queryTasks(null, null, testName, null, null, 1, 10);
assertEquals(10, tasks.size());
tasks.forEach(task -> assertEquals(testName, task.getTaskName()));
}
@@ -136,7 +138,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
@Test
void testUpdateTasks() {
Task originalTask = taskService.queryTasks(
null, null, null, null, 1, 1)
null, null, null, null, null, 1, 1)
.get(0);
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
@@ -153,7 +155,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
@Test
void testDeleteTask() {
long testNum = taskService.queryTasks(null, null, null, null, 1, 10)
long testNum = taskService.queryTasks(null, null, null, null, null, 1, 10)
.get(0).getTaskId();
assertTrue(taskService.deleteTask(testNum));
@@ -162,7 +164,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
@Test
void testChangeAuditStatus() {
long testNum = taskService.queryTasks(null, null, null, null, 1, 1)
long testNum = taskService.queryTasks(null, null, null, null, null, 1, 1)
.get(0).getTaskId();
assertTrue(taskService.changeTaskAuditStatus(testNum, 2));
@@ -175,4 +177,16 @@ class TaskServiceTest extends ProtectionApplicationTests {
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
assertNotNull(taskCommandInfos);
}
@Test
void testUpdateTaskAuditStatusBatch(){
Map<Integer, Integer> map = new HashMap<>();
map.put(43830, 1);
map.put(43831, 1);
map.put(43832, 1);
System.out.println(taskService.updateAuditStatusBatch(map));
}
}

View File

@@ -36,7 +36,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
@BeforeEach
void mockCommand() {
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
Task task = taskService.queryTasks(null, null, null, null, null, 1, 1).get(0);
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
fiveTupleWithMask.setMaskSourceIP("192.168.155.24");
@@ -66,7 +66,7 @@ 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);
Task task = taskService.queryTasks(null, null, null, null, null, 1, 1).get(0);
for (int i = 0; i < 100; i++) {
int port = i + 1000;
TaskCommandInfo taskCommandInfo = new TaskCommandInfo();
@@ -92,7 +92,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
@Test
void queryCommandInfos() {
Task task = taskService.queryTasks(null, null, null, null, 1, 1).get(0);
Task task = taskService.queryTasks(null, 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());