Merge remote-tracking branch 'origin/master'

This commit is contained in:
HopeLi 2025-07-05 22:16:43 +08:00
commit 25a6687abb
7 changed files with 76 additions and 10 deletions

View File

@ -11,7 +11,8 @@ import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController("/shuimu")
@RestController
@RequestMapping("/shuimu")
public class ShuiMuController {
@Resource
private ShuiMuService shuiMuService;
@ -27,9 +28,8 @@ public class ShuiMuController {
return CommonResult.success(shuiMuService.imageList(label));
}
@PostMapping("/createProject")
public CommonResult<Void> createProject(@RequestBody ShuiMuProjectCreateReq req){
shuiMuService.createProject(req);
return CommonResult.success();
public CommonResult<String> createProject(@RequestBody ShuiMuProjectCreateReq req){
return CommonResult.success(shuiMuService.createProject(req));
}
/**
* 获取检测配置

View File

@ -14,4 +14,5 @@ public class ShuiMuUrlConstant {
public static final String buildAndSaveConfig = "/api/driverGeneration/buildAndSaveConfig";
public static final String getProjectById = "/api/project/";
public static final String uploadWfuzzJson = "/api/project/code/uploadWfuzzJson";
public static final String executeAllEntrypointsTest ="/api/driverGeneration/executeAllEntrypointsTest";
}

View File

@ -0,0 +1,6 @@
package cd.casic.ci.process.engine.constant;
public class ShuiMuConstant {
public static final String SHUI_MU_PROJECT_ID_KEY="projectId";
public static final String SHUI_MU_FUZZ_MINUTES = "fuzzMinutes";
}

View File

@ -83,9 +83,9 @@ public class AFLWorker extends DockerWorker {
String commandScript = "docker run -v "+volumeWorkDirPath+":"+AFL_DOCKER_BASE_DIR+" -it "+imageName+" bash\n" +
"cd " + AFL_DOCKER_BASE_DIR+File.separator+workDir+ "\n"+
cdSourceName(fileName) +
"mkdir -p "+ outputPath +"\n" +
"rm -rf " + outputPath + "\n" +
"chmod o+rwx -p "+outputPath+"\n"+
"mkdir -p "+ outputPath +"\n" +
"chmod o+rwx -R "+outputPath+"\n"+
"afl-fuzz -i "+ AFL_DOCKER_BASE_DIR+File.separator+seedPath+" -o "+ outputPath+" ./"+ executableName + " " +commandEnd;
try {
//将节点的配置信息反编译成对象

View File

@ -0,0 +1,31 @@
package cd.casic.ci.process.engine.worker.shuimu;
import cd.casic.ci.process.common.WorkAtom;
import cd.casic.ci.process.engine.constant.ShuiMuConstant;
import cd.casic.ci.process.engine.runContext.TaskRunContext;
import cd.casic.ci.process.engine.worker.base.BaseWorker;
import cd.casic.ci.process.engine.worker.base.SshWorker;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.ci.process.process.service.shuimu.ShuiMuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
*
* */
@Slf4j
@WorkAtom(taskType = "SHUI_MU")
public class ShuiMuWorker extends BaseWorker {
@Resource
private ShuiMuService shuiMuService;
@Override
public void execute(TaskRunContext context) {
PipTask contextDef = (PipTask) context.getContextDef();
Map<String, Object> taskProperties = contextDef.getTaskProperties();
String projectId = (String)taskProperties.get(ShuiMuConstant.SHUI_MU_PROJECT_ID_KEY);
Integer fuzzMinutes = Integer.parseInt(String.valueOf(taskProperties.get(ShuiMuConstant.SHUI_MU_FUZZ_MINUTES)));
shuiMuService.executeAllEntrypointsTest(projectId,fuzzMinutes);
}
}

View File

@ -14,7 +14,7 @@ public interface ShuiMuService {
* 获取编译环境
* */
List<String> imageList(String label);
void createProject(ShuiMuProjectCreateReq req);
String createProject(ShuiMuProjectCreateReq req);
/**
* 获取检测配置
* */
@ -29,4 +29,5 @@ public interface ShuiMuService {
void buildAndSaveConfig(ShuiMuBuildAndSaveReq req);
void uploadWfuzzJson(ShuiMuUpdateWFuzzJsonReq req);
void executeAllEntrypointsTest(String projectId,Integer fuzzMinutes);
}

View File

@ -15,6 +15,7 @@ import cd.casic.ci.process.process.service.target.TargetVersionService;
import cd.casic.ci.process.properties.ShuiMuProperties;
import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import cd.casic.framework.commons.util.object.BeanUtils;
import cd.casic.framework.redis.core.RedisTemplateUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@ -107,11 +108,11 @@ public class ShuiMuServiceImpl implements ShuiMuService {
res.add(name);
}
}
return res.stream().filter(item->item.startsWith(SHUI_MU_IMAGE_LIST_FILTER)).toList();
return res.stream().filter(item->!item.startsWith(SHUI_MU_IMAGE_LIST_FILTER)).toList();
}
@Override
public void createProject(ShuiMuProjectCreateReq req) {
public String createProject(ShuiMuProjectCreateReq req) {
MultiValueMap<String,Object> body = new LinkedMultiValueMap<>();
body.add("projectName","应用检测_"+ UUID.randomUUID().toString().replaceAll("-",""));
body.add("language",req.getLanguage());
@ -124,14 +125,21 @@ public class ShuiMuServiceImpl implements ShuiMuService {
if (!targetFile.exists()) {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"找不到目标文件");
}
String fileName = targetVersion.getFileName();
String fileType = fileName.substring(fileName.indexOf(".")+1);
body.add("vcs",fileType);
FileSystemResource resource = new FileSystemResource(targetFile);
body.add("file",resource);
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<>(body,getHeaders());
HttpHeaders headers = getHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<>(body, headers);
ResponseEntity<String> exchange = restTemplate.exchange(shuiMuProperties.getBaseUrl() + createProject, HttpMethod.POST, entity, String.class, new HashMap<>());
HttpStatusCode statusCode = exchange.getStatusCode();
if (statusCode.isError()) {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"创建项目失败");
}
JSONObject response = JSONObject.parseObject(exchange.getBody());
return response.getString("data");
}
@Override
@ -217,7 +225,26 @@ public class ShuiMuServiceImpl implements ShuiMuService {
} catch (IOException e) {
throw new RuntimeException(e);
}
// 获取projectversion
ShuiMuProjectVersionResp projectVersion = getProjectVersion(req.getProjectId());
ShuiMuProjectVersionResp.Repo repo = projectVersion.getRepo();
ShuiMuBuildAndSaveReq shuiMuBuildAndSaveReq = new ShuiMuBuildAndSaveReq();
BeanUtils.copyProperties(repo,shuiMuBuildAndSaveReq);
buildAndSaveConfig(shuiMuBuildAndSaveReq);
}
@Override
public void executeAllEntrypointsTest(String projectId,Integer fuzzMinutes) {
HttpEntity<String> entity = new HttpEntity<>(null,getHeaders());
String uriString = UriComponentsBuilder.fromUriString(shuiMuProperties.getBaseUrl() + executeAllEntrypointsTest)
.queryParam("projectId",projectId)
.queryParam("arch","x86")
.queryParam("fuzzMinutes",fuzzMinutes)
.toUriString();
ResponseEntity<String> exchange = restTemplate.exchange(uriString, HttpMethod.GET, entity, String.class, new HashMap<>());
if (exchange.getStatusCode().isError()) {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"保存并且构建失败");
}
}