fix(接口测试): 修复DELETE请求接口使用变量作为域名的场景URL拼接错误问题

--bug=1012987 --user=赵勇 [接口测试]github#13239DELETE方法接口使用变量作为域名的场景URL拼接错误 https://www.tapd.cn/55049933/s/1152822
This commit is contained in:
fit2-zhao 2022-05-05 16:07:56 +08:00 committed by fit2-zhao
parent d8bc177b21
commit ced328afce
3 changed files with 11 additions and 6 deletions

View File

@ -312,7 +312,7 @@ public class ElementUtil {
} }
} else if (element.getString("type").equals("HTTPSamplerProxy")) { } else if (element.getString("type").equals("HTTPSamplerProxy")) {
if (element.getString("authManager") != null) { if (element.getString("authManager") != null) {
JSONObject authManager = JSON.parseObject(element.getString("authManager"),Feature.DisableSpecialKeyDetect); JSONObject authManager = JSON.parseObject(element.getString("authManager"), Feature.DisableSpecialKeyDetect);
if (authManager != null && authManager.get("clazzName") == null) { if (authManager != null && authManager.get("clazzName") == null) {
authManager.fluentPut("clazzName", clazzMap.get(authManager.getString("type"))); authManager.fluentPut("clazzName", clazzMap.get(authManager.getString("type")));
element.fluentPut("authManager", authManager); element.fluentPut("authManager", authManager);
@ -390,7 +390,7 @@ public class ElementUtil {
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
environmentMap = JSON.parseObject(environmentJson, Map.class,Feature.DisableSpecialKeyDetect); environmentMap = JSON.parseObject(environmentJson, Map.class, Feature.DisableSpecialKeyDetect);
} }
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16); Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
if (environmentMap != null && !environmentMap.isEmpty()) { if (environmentMap != null && !environmentMap.isEmpty()) {
@ -422,6 +422,8 @@ public class ElementUtil {
httpSamplerProxy.toHashTree(tmpHashTree, null, msParameter); httpSamplerProxy.toHashTree(tmpHashTree, null, msParameter);
if (tmpHashTree != null && tmpHashTree.getArray().length > 0) { if (tmpHashTree != null && tmpHashTree.getArray().length > 0) {
HTTPSamplerProxy object = (HTTPSamplerProxy) tmpHashTree.getArray()[0]; HTTPSamplerProxy object = (HTTPSamplerProxy) tmpHashTree.getArray()[0];
// 清空Domain
element.fluentPut("domain", "");
if (object != null && StringUtils.isNotEmpty(object.getDomain())) { if (object != null && StringUtils.isNotEmpty(object.getDomain())) {
element.fluentPut("domain", StringUtils.isNotEmpty(object.getProtocol()) ? object.getProtocol() + "://" + object.getDomain() : object.getDomain()); element.fluentPut("domain", StringUtils.isNotEmpty(object.getProtocol()) ? object.getProtocol() + "://" + object.getDomain() : object.getDomain());
} }

View File

@ -135,7 +135,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
// 非导出操作且不是启用状态则跳过执行Ms // 非导出操作且不是启用状态则跳过执行Ms
if (!config.isOperating() && !this.isEnable()) { if (!config.isOperating() && !this.isEnable()) {
return; return;
}else if(config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())){ } else if (config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())) {
this.setName(config.getOperatingSampleTestName()); this.setName(config.getOperatingSampleTestName());
} }
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
@ -188,7 +188,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
setSamplerPath(config, httpConfig, sampler); setSamplerPath(config, httpConfig, sampler);
// 请求体处理 // 请求体处理
if (this.body != null && StringUtils.equalsAnyIgnoreCase(method,"POST","PUT","PATCH")) { if (this.body != null && StringUtils.equalsAnyIgnoreCase(method, "POST", "PUT", "PATCH")) {
List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId()); List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId());
if (StringUtils.isNotEmpty(this.body.getType()) && "Form Data".equals(this.body.getType())) { if (StringUtils.isNotEmpty(this.body.getType()) && "Form Data".equals(this.body.getType())) {
AtomicBoolean kvIsEmpty = new AtomicBoolean(true); AtomicBoolean kvIsEmpty = new AtomicBoolean(true);
@ -370,7 +370,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig()); httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
httpConfig.setAssertions(environmentConfig.getAssertions()); httpConfig.setAssertions(environmentConfig.getAssertions());
if (environmentConfig.isUseErrorCode()) { if (environmentConfig.isUseErrorCode()) {
httpConfig.setErrorReportAssertions(HashTreeUtil.getErrorReportByProjectId(this.getProjectId(),environmentConfig.isHigherThanSuccess(),environmentConfig.isHigherThanError())); httpConfig.setErrorReportAssertions(HashTreeUtil.getErrorReportByProjectId(this.getProjectId(), environmentConfig.isHigherThanSuccess(), environmentConfig.isHigherThanError()));
} }
return httpConfig; return httpConfig;
} }
@ -453,7 +453,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
if (CollectionUtils.isNotEmpty(this.getArguments())) { if (CollectionUtils.isNotEmpty(this.getArguments())) {
String path = postQueryParameters(envPath); String path = postQueryParameters(envPath);
if (HTTPConstants.DELETE.equals(this.getMethod()) && !path.startsWith("${")) { if (HTTPConstants.DELETE.equals(this.getMethod()) && !path.startsWith("${") && !path.startsWith("/${")) {
if (!path.startsWith("/")) { if (!path.startsWith("/")) {
path = "/" + path; path = "/" + path;
} }

View File

@ -748,6 +748,8 @@ export default {
if (item && map.has(item.resourceId)) { if (item && map.has(item.resourceId)) {
item.domain = map.get(item.resourceId); item.domain = map.get(item.resourceId);
item.resourceId = getUUID(); item.resourceId = getUUID();
}else{
item.domain = "";
} }
if (item && item.hashTree && item.hashTree.length > 0) { if (item && item.hashTree && item.hashTree.length > 0) {
this.margeDomain(item.hashTree, map); this.margeDomain(item.hashTree, map);
@ -1269,6 +1271,7 @@ export default {
request.versionEnable = item.versionEnable; request.versionEnable = item.versionEnable;
request.versionId = item.versionId; request.versionId = item.versionId;
request.versionName = item.versionName; request.versionName = item.versionName;
request.domain = "";
request.requestResult = []; request.requestResult = [];
if (!request.url) { if (!request.url) {
request.url = ""; request.url = "";