fix(接口测试): 修复新版本环境DNS不起作用问题;修复环境中请求头历史数据问题。

This commit is contained in:
fit2-zhao 2021-05-13 10:30:06 +08:00 committed by fit2-zhao
parent 98b6477691
commit 2f3076f80a
3 changed files with 12 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.api.dto.definition.request.dns;
import com.alibaba.fastjson.annotation.JSONType; import com.alibaba.fastjson.annotation.JSONType;
import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.scenario.HttpConfig;
import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.dto.scenario.environment.Host; import io.metersphere.api.dto.scenario.environment.Host;
@ -40,9 +41,9 @@ public class MsDNSCacheManager extends MsTestElement {
samplerHashTree.add(arguments(name, config.getCommonConfig().getVariables())); samplerHashTree.add(arguments(name, config.getCommonConfig().getVariables()));
} }
public static void addEnvironmentDNS(HashTree samplerHashTree, String name, EnvironmentConfig config) { public static void addEnvironmentDNS(HashTree samplerHashTree, String name, EnvironmentConfig config, HttpConfig httpConfig) {
if (config.getCommonConfig().isEnableHost() && CollectionUtils.isNotEmpty(config.getCommonConfig().getHosts())) { if (config.getCommonConfig().isEnableHost() && CollectionUtils.isNotEmpty(config.getCommonConfig().getHosts()) && httpConfig != null) {
String domain = config.getHttpConfig().getDomain().trim(); String domain = httpConfig.getDomain().trim();
List<Host> hosts = new ArrayList<>(); List<Host> hosts = new ArrayList<>();
config.getCommonConfig().getHosts().forEach(host -> { config.getCommonConfig().getHosts().forEach(host -> {
if (StringUtils.isNotBlank(host.getDomain())) { if (StringUtils.isNotBlank(host.getDomain())) {

View File

@ -197,10 +197,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
compatible(config); compatible(config);
HttpConfig httpConfig = null;
try { try {
if (config.isEffective(this.getProjectId())) { if (config.isEffective(this.getProjectId())) {
HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig(), tree); httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig());
if (httpConfig == null && !isURL(this.getUrl())) { if (httpConfig == null && !isURL(this.getUrl())) {
MSException.throwException("未匹配到环境,请检查环境配置"); MSException.throwException("未匹配到环境,请检查环境配置");
} }
@ -333,13 +333,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (CollectionUtils.isNotEmpty(this.headers)) { if (CollectionUtils.isNotEmpty(this.headers)) {
setHeader(httpSamplerTree, this.headers); setHeader(httpSamplerTree, this.headers);
} }
// 新版本符合条件 HTTP 请求头
// 通用请求Headers if (httpConfig != null && CollectionUtils.isNotEmpty(httpConfig.getHeaders())) {
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getHttpConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders())) {
if (!this.isCustomizeReq() || this.isRefEnvironment) { if (!this.isCustomizeReq() || this.isRefEnvironment) {
// 如果不是自定义请求,或者引用环境则添加环境请求头 // 如果不是自定义请求,或者引用环境则添加环境请求头
setHeader(httpSamplerTree, config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders()); setHeader(httpSamplerTree, httpConfig.getHeaders());
} }
} }
@ -352,7 +350,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
&& config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) { && config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) {
MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId())); MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()));
MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId())); MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()), httpConfig);
} }
if (this.authManager != null) { if (this.authManager != null) {
@ -559,7 +557,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
* @param httpConfig * @param httpConfig
* @return * @return
*/ */
private HttpConfig getHttpConfig(HttpConfig httpConfig, HashTree tree) { private HttpConfig getHttpConfig(HttpConfig httpConfig) {
boolean isNext = true; boolean isNext = true;
if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) { if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) {
for (HttpConfigCondition item : httpConfig.getConditions()) { for (HttpConfigCondition item : httpConfig.getConditions()) {
@ -609,13 +607,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
} }
} }
// HTTP 环境中请求头
if (httpConfig != null && CollectionUtils.isNotEmpty(httpConfig.getHeaders())) {
if (!this.isCustomizeReq() || this.isRefEnvironment) {
// 如果不是自定义请求,或者引用环境则添加环境请求头
setHeader(tree, httpConfig.getHeaders());
}
}
return httpConfig; return httpConfig;
} }

View File

@ -22,6 +22,7 @@ public class HttpConfig {
HttpConfig config = new HttpConfig(); HttpConfig config = new HttpConfig();
config.isMock = this.isMock; config.isMock = this.isMock;
BeanUtils.copyBean(config, configCondition); BeanUtils.copyBean(config, configCondition);
config.setHeaders(configCondition.getHeaders());
return config; return config;
} }