fix(接口测试): 修复http协议请求参数为binary类型附件丢失问题

--bug=1013413 --user=赵勇 [接口测试]github#13849ES的api请求中有批量添加数据的方法,需要使用到binary的数据,上传一个文件,但是请求直接就报异常,找不到数据 https://www.tapd.cn/55049933/s/1162821
This commit is contained in:
fit2-zhao 2022-05-24 11:28:40 +08:00 committed by f2c-ci-robot[bot]
parent d3645b7b14
commit 93e114a493
2 changed files with 37 additions and 19 deletions

View File

@ -128,23 +128,24 @@ public class Body {
List<HTTPFileArg> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(this.getKvs())) {
this.getKvs().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
setFileArg(list, keyValue.getFiles(), keyValue, requestId);
setFileArg(list, keyValue.getFiles(), keyValue, requestId, false);
});
}
if (CollectionUtils.isNotEmpty(this.getBinary())) {
this.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
setFileArg(list, keyValue.getFiles(), keyValue, requestId);
setFileArg(list, keyValue.getFiles(), keyValue, requestId, true);
});
}
return list.toArray(new HTTPFileArg[0]);
}
private void setFileArg(List<HTTPFileArg> list, List<BodyFile> files, KeyValue keyValue, String requestId) {
private void setFileArg(List<HTTPFileArg> list, List<BodyFile> files,
KeyValue keyValue, String requestId, boolean isBinary) {
if (files != null) {
files.forEach(file -> {
String paramName = keyValue.getName() == null ? requestId : keyValue.getName();
String path = null;
if (StringUtils.isNotBlank(file.getId())) {
if (StringUtils.isNotBlank(file.getId()) && !isBinary) {
// 旧数据
path = FileUtils.BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName();
} else if (StringUtils.isNotBlank(this.tmpFilePath)) {

View File

@ -253,11 +253,12 @@ export default {
apiCaseClose() {
this.visible = false;
},
getBodyUploadFiles() {
getBodyUploadFiles(data) {
let bodyUploadFiles = [];
this.api.bodyUploadIds = [];
let request = this.api.request;
data.bodyUploadIds = [];
let request = data.request;
if (request.body) {
if (request.body.kvs) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
@ -269,6 +270,22 @@ export default {
}
});
}
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
let fileId = getUUID().substring(0, 8);
item.name = item.file.name;
item.id = fileId;
data.bodyUploadIds.push(fileId);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
return bodyUploadFiles;
},
saveAsCase() {
@ -305,7 +322,7 @@ export default {
},
updateApi() {
let url = "/api/definition/update";
let bodyFiles = this.getBodyUploadFiles();
let bodyFiles = this.getBodyUploadFiles(this.api);
this.api.method = this.api.request.method;
this.api.path = this.api.request.path;
if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {