fix(接口测试): 修复SQL操作按列存储打印提取结果获取参数失败的缺陷

--bug=1038107 --user=王孝刚 【接口测试】定义-调试-SQL操作按列存储-打印提取结果获取参数失败
https://www.tapd.cn/55049933/s/1490352
This commit is contained in:
wxg0103 2024-04-08 15:32:11 +08:00 committed by 刘瑞斌
parent 69395aa465
commit 0ad32a44c6
17 changed files with 42 additions and 141 deletions

View File

@ -1,6 +1,6 @@
package io.metersphere.api.dto.request.http; package io.metersphere.api.dto.request.http;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; import io.metersphere.project.dto.environment.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement; import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.HttpMethodConstants;

View File

@ -8,7 +8,7 @@ import io.metersphere.api.dto.definition.ResponseBody;
import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.ImportRequest;
import io.metersphere.api.dto.request.MsCommonElement; import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.*; import io.metersphere.api.dto.request.http.*;
import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.project.dto.environment.auth.NoAuth;
import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.request.http.body.*;
import io.metersphere.api.dto.schema.JsonSchemaItem; import io.metersphere.api.dto.schema.JsonSchemaItem;
import io.metersphere.api.parser.ImportParser; import io.metersphere.api.parser.ImportParser;

View File

@ -4,9 +4,9 @@ package io.metersphere.api.parser.jmeter;
import io.metersphere.api.constants.ApiConstants; import io.metersphere.api.constants.ApiConstants;
import io.metersphere.api.dto.ApiParamConfig; import io.metersphere.api.dto.ApiParamConfig;
import io.metersphere.api.dto.request.http.*; import io.metersphere.api.dto.request.http.*;
import io.metersphere.api.dto.request.http.auth.BasicAuth; import io.metersphere.project.dto.environment.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth; import io.metersphere.project.dto.environment.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; import io.metersphere.project.dto.environment.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.api.parser.jmeter.body.MsBodyConverter; import io.metersphere.api.parser.jmeter.body.MsBodyConverter;
import io.metersphere.api.parser.jmeter.body.MsBodyConverterFactory; import io.metersphere.api.parser.jmeter.body.MsBodyConverterFactory;
@ -102,6 +102,9 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
HTTPAuthConfig authConfig = msHTTPElement.getAuthConfig(); HTTPAuthConfig authConfig = msHTTPElement.getAuthConfig();
if ((authConfig == null || !authConfig.isHTTPAuthValid()) && httpConfig != null) {
authConfig = httpConfig.getAuthConfig();
}
// 处理认证信息 // 处理认证信息
AuthManager authManager = getAuthManager(authConfig); AuthManager authManager = getAuthManager(authConfig);
Optional.ofNullable(authManager).ifPresent(httpTree::add); Optional.ofNullable(authManager).ifPresent(httpTree::add);

View File

@ -1,16 +1,18 @@
package io.metersphere.api.parser.jmeter.processor; package io.metersphere.api.parser.jmeter.processor;
import io.metersphere.api.dto.ApiParamConfig; import io.metersphere.api.dto.ApiParamConfig;
import io.metersphere.api.parser.jmeter.JmeterTestElementParserHelper; import io.metersphere.api.parser.jmeter.constants.JmeterAlias;
import io.metersphere.api.parser.jmeter.constants.JmeterProperty;
import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.dto.ParameterConfig;
import io.metersphere.project.api.KeyValueParam; import io.metersphere.project.api.KeyValueParam;
import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.api.processor.SQLProcessor;
import io.metersphere.project.constants.ScriptLanguageType;
import io.metersphere.project.dto.environment.EnvironmentInfoDTO; import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
import io.metersphere.project.dto.environment.datasource.DataSource; import io.metersphere.project.dto.environment.datasource.DataSource;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments; import org.apache.jmeter.extractor.JSR223PostProcessor;
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement; import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
import org.apache.jmeter.protocol.jdbc.processor.AbstractJDBCProcessor; import org.apache.jmeter.protocol.jdbc.processor.AbstractJDBCProcessor;
import org.apache.jmeter.save.SaveService; import org.apache.jmeter.save.SaveService;
@ -60,20 +62,29 @@ public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProc
.filter(KeyValueParam::isValid) .filter(KeyValueParam::isValid)
.toList(); .toList();
// 添加提取的变量 // 添加提取的变量
Arguments jdbcArguments = getJdbcArguments(sqlProcessor.getName(), extractParams); JSR223PostProcessor jdbcPostProcessor = getJdbcPostProcessor(sqlProcessor.getName(), extractParams);
if (jdbcArguments != null && !jdbcArguments.getArguments().isEmpty()) { if (jdbcPostProcessor != null ) {
hashTree.add(jdbcArguments); hashTree.add(jdbcPostProcessor);
} }
} }
public Arguments getJdbcArguments(String name, List<KeyValueParam> extractParams) { public JSR223PostProcessor getJdbcPostProcessor(String name, List<KeyValueParam> extractParams) {
if (CollectionUtils.isNotEmpty(extractParams)) { if (CollectionUtils.isNotEmpty(extractParams)) {
Arguments arguments = JmeterTestElementParserHelper.getArguments(name); JSR223PostProcessor jsr223PostProcessor = new JSR223PostProcessor();
jsr223PostProcessor.setName(name);
jsr223PostProcessor.setProperty(TestElement.TEST_CLASS, jsr223PostProcessor.getClass().getSimpleName());
jsr223PostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
jsr223PostProcessor.setProperty(JmeterProperty.SCRIPT_LANGUAGE, ScriptLanguageType.BEANSHELL.name().toLowerCase());
StringBuilder scriptBuilder = new StringBuilder();
extractParams.stream().filter(KeyValueParam::isValid) extractParams.stream().filter(KeyValueParam::isValid)
.forEach(keyValue -> .forEach(keyValue -> {
arguments.addArgument(keyValue.getKey(), String.format("vars.get(\"%s\")", keyValue.getValue()), "=") String script = """
); vars.put("%s","${%s}");
return arguments; """;
scriptBuilder.append(String.format(script, keyValue.getKey(), keyValue.getValue()));
});
jsr223PostProcessor.setProperty(JmeterProperty.SCRIPT, scriptBuilder.toString());
return jsr223PostProcessor;
} }
return null; return null;
} }

View File

@ -102,7 +102,6 @@ public class ApiTestService {
EnvironmentConfig newEnvironmentConfig = new EnvironmentConfig(); EnvironmentConfig newEnvironmentConfig = new EnvironmentConfig();
newEnvironmentConfig.setHttpConfig(environmentConfig.getHttpConfig()); newEnvironmentConfig.setHttpConfig(environmentConfig.getHttpConfig());
newEnvironmentConfig.setCommonVariables(environmentConfig.getCommonVariables()); newEnvironmentConfig.setCommonVariables(environmentConfig.getCommonVariables());
newEnvironmentConfig.setAuthConfig(null);
newEnvironmentConfig.setPreProcessorConfig(null); newEnvironmentConfig.setPreProcessorConfig(null);
newEnvironmentConfig.setPostProcessorConfig(null); newEnvironmentConfig.setPostProcessorConfig(null);
newEnvironmentConfig.setAssertionConfig(null); newEnvironmentConfig.setAssertionConfig(null);

View File

@ -16,9 +16,9 @@ import io.metersphere.api.dto.request.ApiTransferRequest;
import io.metersphere.api.dto.request.MsCommonElement; import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.dto.request.http.RestParam; import io.metersphere.api.dto.request.http.RestParam;
import io.metersphere.api.dto.request.http.auth.BasicAuth; import io.metersphere.project.dto.environment.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth; import io.metersphere.project.dto.environment.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; import io.metersphere.project.dto.environment.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.request.http.body.*;
import io.metersphere.api.mapper.ApiDebugBlobMapper; import io.metersphere.api.mapper.ApiDebugBlobMapper;
import io.metersphere.api.mapper.ApiDebugMapper; import io.metersphere.api.mapper.ApiDebugMapper;

View File

@ -222,7 +222,6 @@ public class ApiTestControllerTests extends BaseTest {
Environment environment = baseEnvTestService.initEnv("111"); Environment environment = baseEnvTestService.initEnv("111");
MvcResult mvcResult = this.requestGetAndReturn(ENVIRONMENT, environment.getId()); MvcResult mvcResult = this.requestGetAndReturn(ENVIRONMENT, environment.getId());
EnvironmentConfig environmentConfig = getResultData(mvcResult, EnvironmentConfig.class); EnvironmentConfig environmentConfig = getResultData(mvcResult, EnvironmentConfig.class);
Assertions.assertNull(environmentConfig.getAuthConfig());
Assertions.assertNull(environmentConfig.getPreProcessorConfig()); Assertions.assertNull(environmentConfig.getPreProcessorConfig());
Assertions.assertNull(environmentConfig.getPostProcessorConfig()); Assertions.assertNull(environmentConfig.getPostProcessorConfig());
Assertions.assertNull(environmentConfig.getAssertionConfig()); Assertions.assertNull(environmentConfig.getAssertionConfig());

View File

@ -1,6 +1,5 @@
package io.metersphere.project.dto.environment; package io.metersphere.project.dto.environment;
import io.metersphere.project.dto.environment.auth.AuthConfig;
import io.metersphere.project.dto.environment.common.CommonParams; import io.metersphere.project.dto.environment.common.CommonParams;
import io.metersphere.project.dto.environment.datasource.DataSource; import io.metersphere.project.dto.environment.datasource.DataSource;
import io.metersphere.project.dto.environment.host.HostConfig; import io.metersphere.project.dto.environment.host.HostConfig;
@ -28,8 +27,6 @@ public class EnvironmentConfig {
@Schema(description = "Host配置") @Schema(description = "Host配置")
private HostConfig hostConfig = new HostConfig(); private HostConfig hostConfig = new HostConfig();
@Schema(description = "认证配置")
private AuthConfig authConfig = new AuthConfig();
@Schema(description = "全局前置脚本") @Schema(description = "全局前置脚本")
private EnvProcessorConfig preProcessorConfig = new EnvProcessorConfig(); private EnvProcessorConfig preProcessorConfig = new EnvProcessorConfig();
@Schema(description = "全局后置脚本") @Schema(description = "全局后置脚本")

View File

@ -1,25 +0,0 @@
package io.metersphere.project.dto.environment.auth;
import io.metersphere.project.dto.environment.ssl.KeyStoreConfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class AuthConfig implements Serializable {
@Schema(description = "用户名")
private String username;
@Schema(description = "密码")
private String password;
@Schema(description = "认证方式 No Auth、Basic Auth、Digest Auth、ssl证书")
private String verification;
@Schema(description = "SSL配置")
private KeyStoreConfig sslConfig = new KeyStoreConfig();
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto.request.http.auth; package io.metersphere.project.dto.environment.auth;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto.request.http.auth; package io.metersphere.project.dto.environment.auth;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto.request.http.auth; package io.metersphere.project.dto.environment.auth;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto.request.http.auth; package io.metersphere.project.dto.environment.auth;
import io.metersphere.system.valid.EnumValue; import io.metersphere.system.valid.EnumValue;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto.request.http.auth; package io.metersphere.project.dto.environment.auth;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Data; import lombok.Data;

View File

@ -1,6 +1,7 @@
package io.metersphere.project.dto.environment.http; package io.metersphere.project.dto.environment.http;
import io.metersphere.project.api.KeyValueEnableParam; import io.metersphere.project.api.KeyValueEnableParam;
import io.metersphere.project.dto.environment.auth.HTTPAuthConfig;
import io.metersphere.sdk.constants.ValueEnum; import io.metersphere.sdk.constants.ValueEnum;
import io.metersphere.system.valid.EnumValue; import io.metersphere.system.valid.EnumValue;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -46,6 +47,9 @@ public class HttpConfig implements Serializable {
@Schema(description = "排序") @Schema(description = "排序")
private int order; private int order;
@Schema(description = "认证配置")
private HTTPAuthConfig authConfig = new HTTPAuthConfig();
public boolean isModuleMatchRule() { public boolean isModuleMatchRule() {
return StringUtils.equals(HttpConfigMatchType.MODULE.name(), type); return StringUtils.equals(HttpConfigMatchType.MODULE.name(), type);

View File

@ -10,7 +10,6 @@ import io.metersphere.project.dto.CommonScriptInfo;
import io.metersphere.project.dto.DropNode; import io.metersphere.project.dto.DropNode;
import io.metersphere.project.dto.NodeSortQueryParam; import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.project.dto.environment.*; import io.metersphere.project.dto.environment.*;
import io.metersphere.project.dto.environment.auth.AuthConfig;
import io.metersphere.project.dto.environment.common.CommonParams; import io.metersphere.project.dto.environment.common.CommonParams;
import io.metersphere.project.dto.environment.datasource.DataSource; import io.metersphere.project.dto.environment.datasource.DataSource;
import io.metersphere.project.dto.environment.host.Host; import io.metersphere.project.dto.environment.host.Host;
@ -18,9 +17,6 @@ import io.metersphere.project.dto.environment.host.HostConfig;
import io.metersphere.project.dto.environment.http.HttpConfig; import io.metersphere.project.dto.environment.http.HttpConfig;
import io.metersphere.project.dto.environment.processors.*; import io.metersphere.project.dto.environment.processors.*;
import io.metersphere.project.dto.environment.processors.pre.UiPreScript; import io.metersphere.project.dto.environment.processors.pre.UiPreScript;
import io.metersphere.project.dto.environment.ssl.KeyStoreConfig;
import io.metersphere.project.dto.environment.ssl.KeyStoreEntry;
import io.metersphere.project.dto.environment.ssl.KeyStoreFile;
import io.metersphere.project.dto.environment.variables.CommonVariables; import io.metersphere.project.dto.environment.variables.CommonVariables;
import io.metersphere.project.mapper.ExtEnvironmentMapper; import io.metersphere.project.mapper.ExtEnvironmentMapper;
import io.metersphere.project.service.EnvironmentService; import io.metersphere.project.service.EnvironmentService;
@ -284,39 +280,12 @@ public class EnvironmentControllerTests extends BaseTest {
return hostConfig; return hostConfig;
} }
private AuthConfig createAuthConfig() {
AuthConfig authConfig = new AuthConfig();
authConfig.setUsername("username");
authConfig.setPassword("password");
return authConfig;
}
private EnvProcessorConfig createEnvironmentProcessorConfig() { private EnvProcessorConfig createEnvironmentProcessorConfig() {
EnvProcessorConfig environmentPreScript = new EnvProcessorConfig(); EnvProcessorConfig environmentPreScript = new EnvProcessorConfig();
environmentPreScript.setApiProcessorConfig(createApiEnvProcessorConfig()); environmentPreScript.setApiProcessorConfig(createApiEnvProcessorConfig());
return environmentPreScript; return environmentPreScript;
} }
private KeyStoreConfig createKeyStoreConfig() {
KeyStoreConfig keyStoreConfig = new KeyStoreConfig();
KeyStoreEntry keyStoreEntry = new KeyStoreEntry();
keyStoreEntry.setId("id");
keyStoreEntry.setPassword("alias");
keyStoreEntry.setDefault(true);
keyStoreEntry.setSourceId("sourceId");
keyStoreEntry.setSourceName("sourceName");
keyStoreConfig.setEntry(List.of(keyStoreEntry));
KeyStoreFile keyStoreFile = new KeyStoreFile();
keyStoreFile.setId("id");
keyStoreFile.setName("name");
keyStoreFile.setType("type");
keyStoreFile.setUpdateTime("updateTime");
keyStoreFile.setPassword("password");
keyStoreFile.setFile(null);
keyStoreConfig.setFiles(List.of(keyStoreFile));
return keyStoreConfig;
}
private ApiEnvProcessorConfig createApiEnvProcessorConfig() { private ApiEnvProcessorConfig createApiEnvProcessorConfig() {
ApiEnvProcessorConfig apiScript = new ApiEnvProcessorConfig(); ApiEnvProcessorConfig apiScript = new ApiEnvProcessorConfig();
ScriptProcessor scriptProcessor = new ScriptProcessor(); ScriptProcessor scriptProcessor = new ScriptProcessor();
@ -602,61 +571,6 @@ public class EnvironmentControllerTests extends BaseTest {
} }
//校验日志 //校验日志
checkLog(response.getId(), OperationLogType.ADD); checkLog(response.getId(), OperationLogType.ADD);
//auth配置
envConfig.setAuthConfig(createAuthConfig());
request.setName("authConfig");
request.setConfig(envConfig);
paramMap.clear();
paramMap.set("request", JSON.toJSONString(request));
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
response = parseObjectFromMvcResult(mvcResult, Environment.class);
Assertions.assertNotNull(response);
environment = environmentMapper.selectByPrimaryKey(response.getId());
Assertions.assertNotNull(environment);
Assertions.assertEquals(response.getId(), environment.getId());
Assertions.assertEquals(response.getName(), environment.getName());
Assertions.assertEquals(response.getProjectId(), environment.getProjectId());
environmentBlob = environmentBlobMapper.selectByPrimaryKey(response.getId());
Assertions.assertNotNull(environmentBlob);
config = new String(environmentBlob.getConfig());
if (StringUtils.isNotBlank(config)) {
EnvironmentConfig environmentConfig = JSON.parseObject(config, EnvironmentConfig.class);
Assertions.assertNotNull(environmentConfig);
Assertions.assertNotNull(environmentConfig.getAuthConfig());
Assertions.assertEquals(envConfig.getAuthConfig(), environmentConfig.getAuthConfig());
}
//校验日志
checkLog(response.getId(), OperationLogType.ADD);
//ssl配置
AuthConfig authConfig = envConfig.getAuthConfig();
authConfig.setSslConfig(createKeyStoreConfig());
envConfig.setAuthConfig(authConfig);
request.setName("sslConfig");
request.setConfig(envConfig);
paramMap.clear();
paramMap.set("request", JSON.toJSONString(request));
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
response = parseObjectFromMvcResult(mvcResult, Environment.class);
Assertions.assertNotNull(response);
environment = environmentMapper.selectByPrimaryKey(response.getId());
Assertions.assertNotNull(environment);
Assertions.assertEquals(response.getId(), environment.getId());
Assertions.assertEquals(response.getName(), environment.getName());
Assertions.assertEquals(response.getProjectId(), environment.getProjectId());
environmentBlob = environmentBlobMapper.selectByPrimaryKey(response.getId());
Assertions.assertNotNull(environmentBlob);
config = new String(environmentBlob.getConfig());
if (StringUtils.isNotBlank(config)) {
EnvironmentConfig environmentConfig = JSON.parseObject(config, EnvironmentConfig.class);
Assertions.assertNotNull(environmentConfig);
Assertions.assertNotNull(environmentConfig.getAuthConfig());
Assertions.assertEquals(envConfig.getAuthConfig().getSslConfig(), environmentConfig.getAuthConfig().getSslConfig());
}
//校验日志
checkLog(response.getId(), OperationLogType.ADD);
//前置脚本 //前置脚本
envConfig.setPreProcessorConfig(createEnvironmentProcessorConfig()); envConfig.setPreProcessorConfig(createEnvironmentProcessorConfig());
request.setName("preScript"); request.setName("preScript");

View File

@ -11,7 +11,6 @@
<a-input <a-input
ref="inputRef" ref="inputRef"
v-model:model-value="innerValue" v-model:model-value="innerValue"
:max-length="255"
:disabled="props.disabled" :disabled="props.disabled"
:size="props.size" :size="props.size"
:placeholder="t('ms.paramsInput.commonPlaceholder')" :placeholder="t('ms.paramsInput.commonPlaceholder')"