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 5da1e64301
commit e0e4a4710a
2 changed files with 37 additions and 19 deletions

View File

@ -97,7 +97,7 @@ public class Body {
} else {
try {
if (StringUtils.isNotEmpty(this.getRaw())) {
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField,Feature.DisableSpecialKeyDetect);
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField, Feature.DisableSpecialKeyDetect);
if (!this.getRaw().contains("$ref")) {
jsonMockParse(jsonObject);
}
@ -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,21 +253,38 @@ 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) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
item.name = item.file.name;
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.kvs) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
item.name = item.file.name;
bodyUploadFiles.push(item.file);
}
});
}
});
}
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;
},
@ -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') {