diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java index 383f03db0a..0d70276ee2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java @@ -1,6 +1,6 @@ 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.plugin.api.spi.AbstractMsProtocolTestElement; import io.metersphere.sdk.constants.HttpMethodConstants; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java index a42a2a761f..77cd63ef82 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java @@ -8,7 +8,7 @@ import io.metersphere.api.dto.definition.ResponseBody; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.MsCommonElement; 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.schema.JsonSchemaItem; import io.metersphere.api.parser.ImportParser; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsHTTPElementConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsHTTPElementConverter.java index 116360b165..cc2b94f0a5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsHTTPElementConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsHTTPElementConverter.java @@ -4,9 +4,9 @@ package io.metersphere.api.parser.jmeter; import io.metersphere.api.constants.ApiConstants; import io.metersphere.api.dto.ApiParamConfig; import io.metersphere.api.dto.request.http.*; -import io.metersphere.api.dto.request.http.auth.BasicAuth; -import io.metersphere.api.dto.request.http.auth.DigestAuth; -import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; +import io.metersphere.project.dto.environment.auth.BasicAuth; +import io.metersphere.project.dto.environment.auth.DigestAuth; +import io.metersphere.project.dto.environment.auth.HTTPAuthConfig; import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.api.parser.jmeter.body.MsBodyConverter; import io.metersphere.api.parser.jmeter.body.MsBodyConverterFactory; @@ -102,6 +102,9 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter extractParams) { + public JSR223PostProcessor getJdbcPostProcessor(String name, List 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) - .forEach(keyValue -> - arguments.addArgument(keyValue.getKey(), String.format("vars.get(\"%s\")", keyValue.getValue()), "=") - ); - return arguments; + .forEach(keyValue -> { + String script = """ + vars.put("%s","${%s}"); + """; + scriptBuilder.append(String.format(script, keyValue.getKey(), keyValue.getValue())); + }); + jsr223PostProcessor.setProperty(JmeterProperty.SCRIPT, scriptBuilder.toString()); + return jsr223PostProcessor; } return null; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java index 2b826ecf6f..75df319efe 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java @@ -102,7 +102,6 @@ public class ApiTestService { EnvironmentConfig newEnvironmentConfig = new EnvironmentConfig(); newEnvironmentConfig.setHttpConfig(environmentConfig.getHttpConfig()); newEnvironmentConfig.setCommonVariables(environmentConfig.getCommonVariables()); - newEnvironmentConfig.setAuthConfig(null); newEnvironmentConfig.setPreProcessorConfig(null); newEnvironmentConfig.setPostProcessorConfig(null); newEnvironmentConfig.setAssertionConfig(null); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java index 83c05f50db..36ed3e52ce 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java @@ -16,9 +16,9 @@ import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.MsCommonElement; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.RestParam; -import io.metersphere.api.dto.request.http.auth.BasicAuth; -import io.metersphere.api.dto.request.http.auth.DigestAuth; -import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; +import io.metersphere.project.dto.environment.auth.BasicAuth; +import io.metersphere.project.dto.environment.auth.DigestAuth; +import io.metersphere.project.dto.environment.auth.HTTPAuthConfig; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.mapper.ApiDebugBlobMapper; import io.metersphere.api.mapper.ApiDebugMapper; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java index 6fbca23ce7..6e5f61ed43 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java @@ -222,7 +222,6 @@ public class ApiTestControllerTests extends BaseTest { Environment environment = baseEnvTestService.initEnv("111"); MvcResult mvcResult = this.requestGetAndReturn(ENVIRONMENT, environment.getId()); EnvironmentConfig environmentConfig = getResultData(mvcResult, EnvironmentConfig.class); - Assertions.assertNull(environmentConfig.getAuthConfig()); Assertions.assertNull(environmentConfig.getPreProcessorConfig()); Assertions.assertNull(environmentConfig.getPostProcessorConfig()); Assertions.assertNull(environmentConfig.getAssertionConfig()); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentConfig.java index a95ec88f5b..cda4103c44 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentConfig.java @@ -1,6 +1,5 @@ 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.datasource.DataSource; import io.metersphere.project.dto.environment.host.HostConfig; @@ -28,8 +27,6 @@ public class EnvironmentConfig { @Schema(description = "Host配置") private HostConfig hostConfig = new HostConfig(); - @Schema(description = "认证配置") - private AuthConfig authConfig = new AuthConfig(); @Schema(description = "全局前置脚本") private EnvProcessorConfig preProcessorConfig = new EnvProcessorConfig(); @Schema(description = "全局后置脚本") diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/AuthConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/AuthConfig.java deleted file mode 100644 index 311624b97c..0000000000 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/AuthConfig.java +++ /dev/null @@ -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; -} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/BasicAuth.java similarity index 87% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java rename to backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/BasicAuth.java index a98c075df1..9363f61a62 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/BasicAuth.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.request.http.auth; +package io.metersphere.project.dto.environment.auth; import lombok.Data; import org.apache.commons.lang3.StringUtils; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/DigestAuth.java similarity index 87% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java rename to backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/DigestAuth.java index c2ffa0af28..87fae53840 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/DigestAuth.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.request.http.auth; +package io.metersphere.project.dto.environment.auth; import lombok.Data; import org.apache.commons.lang3.StringUtils; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuth.java similarity index 77% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java rename to backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuth.java index 129bfff57d..965989ffcc 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuth.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.request.http.auth; +package io.metersphere.project.dto.environment.auth; import lombok.Data; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuthConfig.java similarity index 94% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java rename to backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuthConfig.java index e9d7a4152d..3dc0f05e51 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/HTTPAuthConfig.java @@ -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 lombok.Data; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/NoAuth.java similarity index 80% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java rename to backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/NoAuth.java index f0eb36d42a..49cc0ea414 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/auth/NoAuth.java @@ -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 lombok.Data; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java index 95ecd3a500..f9c27fb911 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java @@ -1,6 +1,7 @@ package io.metersphere.project.dto.environment.http; import io.metersphere.project.api.KeyValueEnableParam; +import io.metersphere.project.dto.environment.auth.HTTPAuthConfig; import io.metersphere.sdk.constants.ValueEnum; import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; @@ -46,6 +47,9 @@ public class HttpConfig implements Serializable { @Schema(description = "排序") private int order; + @Schema(description = "认证配置") + private HTTPAuthConfig authConfig = new HTTPAuthConfig(); + public boolean isModuleMatchRule() { return StringUtils.equals(HttpConfigMatchType.MODULE.name(), type); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java index e893c4280a..75d1c04dbe 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java @@ -10,7 +10,6 @@ import io.metersphere.project.dto.CommonScriptInfo; import io.metersphere.project.dto.DropNode; import io.metersphere.project.dto.NodeSortQueryParam; 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.datasource.DataSource; 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.processors.*; 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.mapper.ExtEnvironmentMapper; import io.metersphere.project.service.EnvironmentService; @@ -284,39 +280,12 @@ public class EnvironmentControllerTests extends BaseTest { return hostConfig; } - private AuthConfig createAuthConfig() { - AuthConfig authConfig = new AuthConfig(); - authConfig.setUsername("username"); - authConfig.setPassword("password"); - return authConfig; - } - private EnvProcessorConfig createEnvironmentProcessorConfig() { EnvProcessorConfig environmentPreScript = new EnvProcessorConfig(); environmentPreScript.setApiProcessorConfig(createApiEnvProcessorConfig()); 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() { ApiEnvProcessorConfig apiScript = new ApiEnvProcessorConfig(); ScriptProcessor scriptProcessor = new ScriptProcessor(); @@ -602,61 +571,6 @@ public class EnvironmentControllerTests extends BaseTest { } //校验日志 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()); request.setName("preScript"); diff --git a/frontend/src/views/api-test/components/paramDescInput.vue b/frontend/src/views/api-test/components/paramDescInput.vue index 7ae1579113..bcc97e48e6 100644 --- a/frontend/src/views/api-test/components/paramDescInput.vue +++ b/frontend/src/views/api-test/components/paramDescInput.vue @@ -11,7 +11,6 @@