From 94b6478422897164bc075e7b14cd3873f5586b0e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 20 Feb 2024 15:31:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=89=A7=E8=A1=8C=E8=A7=A3=E6=9E=90rest?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=92=8C=E8=AE=A4=E8=AF=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/request/http/MsHTTPConfig.java | 4 +- .../api/dto/request/http/MsHTTPElement.java | 6 +- .../api/dto/request/http/auth/BasicAuth.java | 8 +- .../api/dto/request/http/auth/DigestAuth.java | 7 +- .../api/dto/request/http/auth/HTTPAuth.java | 16 +- .../dto/request/http/auth/HTTPAuthConfig.java | 41 +++++ .../api/dto/request/http/auth/NoAuth.java | 2 +- .../parser/jmeter/MsHTTPElementConverter.java | 144 +++++++++++++++++- .../jmeter/body/MsBinaryBodyConverter.java | 6 +- .../parser/jmeter/constants/JmeterAlias.java | 1 + .../parser/jmeter/processor/ScriptFilter.java | 2 +- .../processor/ScriptProcessorConverter.java | 4 +- .../assertion/VariableAssertionConverter.java | 2 +- .../controller/ApiDebugControllerTests.java | 35 +++++ .../controller/ApiTestControllerTests.java | 5 +- .../api/controller/MsHTTPElementTest.java | 35 +---- .../project/api/KeyValueParam.java | 4 + .../project/constants/ScriptLanguageType.java | 20 +-- .../request/CustomFunctionRequest.java | 3 + 19 files changed, 261 insertions(+), 84 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java index ad43ba7067..e93ccc6dba 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java @@ -14,11 +14,11 @@ public class MsHTTPConfig { /** * 连接超时 */ - private Long connectTimeout; + private Long connectTimeout = 6000L; /** * 响应超时 */ - private Long responseTimeout; + private Long responseTimeout = 6000L; /** * 证书别名 */ 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 6cc3331c80..bfa1638bd4 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.HTTPAuth; +import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.sdk.constants.HttpMethodConstants; @@ -66,12 +66,12 @@ public class MsHTTPElement extends AbstractMsTestElement { * 其他配置 */ @Valid - private MsHTTPConfig otherConfig; + private MsHTTPConfig otherConfig = new MsHTTPConfig(); /** * 认证配置 */ @Valid - private HTTPAuth authConfig; + private HTTPAuthConfig authConfig = new HTTPAuthConfig(); /** * 模块ID * 运行时参数,接口无需设置 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java index bc6ef56d8d..a98c075df1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/BasicAuth.java @@ -1,15 +1,19 @@ package io.metersphere.api.dto.request.http.auth; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; +import org.apache.commons.lang3.StringUtils; /** * @Author: jianxing * @CreateTime: 2023-11-07 11:00 */ @Data -@JsonTypeName("BASIC") public class BasicAuth extends HTTPAuth { private String userName; private String password; + + @Override + public boolean isValid() { + return StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java index 128015b88e..c2ffa0af28 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/DigestAuth.java @@ -1,15 +1,18 @@ package io.metersphere.api.dto.request.http.auth; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; +import org.apache.commons.lang3.StringUtils; /** * @Author: jianxing * @CreateTime: 2023-11-07 11:00 */ @Data -@JsonTypeName("DIGEST") public class DigestAuth extends HTTPAuth { private String userName; private String password; + + public boolean isValid() { + return StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java index d0e66696c1..129bfff57d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java @@ -1,27 +1,13 @@ package io.metersphere.api.dto.request.http.auth; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Data; /** * http 认证配置 - *
- * 该参数传参时,需要传入 authType 字段,用于区分是哪种认证方式
- * authType 取值为:
- *   BASIC ({@link BasicAuth})
- *   DIGEST ({@link DigestAuth})
- *   NONE ({@link NoAuth})
- * 
* @Author: jianxing * @CreateTime: 2023-11-07 11:00 */ @Data -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "authType") -@JsonSubTypes({ - @JsonSubTypes.Type(value = NoAuth.class), - @JsonSubTypes.Type(value = BasicAuth.class), - @JsonSubTypes.Type(value = DigestAuth.class), -}) public abstract class HTTPAuth { + public abstract boolean isValid(); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java new file mode 100644 index 0000000000..fd763351d3 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuthConfig.java @@ -0,0 +1,41 @@ +package io.metersphere.api.dto.request.http.auth; + +import io.metersphere.system.valid.EnumValue; +import lombok.Data; + +import java.util.HashMap; + +/** + * http 认证配置 + * + * @Author: jianxing + * @CreateTime: 2023-11-07 11:00 + */ +@Data +public class HTTPAuthConfig { + /** + * 认证方式 + * {@link HTTPAuthType} + */ + @EnumValue(enumClass = HTTPAuthType.class) + private String authType = HTTPAuthType.NONE.name(); + private BasicAuth basicAuth; + private DigestAuth digestAuth; + + public boolean isHTTPAuthValid() { + HashMap httpAuthHashMap = HashMap.newHashMap(2); + httpAuthHashMap.put(HTTPAuthType.BASIC.name(), basicAuth); + httpAuthHashMap.put(HTTPAuthType.DIGEST.name(), digestAuth); + HTTPAuth httpAuth = httpAuthHashMap.get(authType); + return httpAuth != null && httpAuth.isValid(); + } + + /** + * http 认证方式 + */ + public enum HTTPAuthType { + NONE, + BASIC, + DIGEST + } +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java index e8e4fb61e8..f0eb36d42a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/NoAuth.java @@ -9,5 +9,5 @@ import lombok.Data; */ @Data @JsonTypeName("NONE") -public class NoAuth extends HTTPAuth { +public class NoAuth extends HTTPAuthConfig { } 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 4753ddf9e1..e2e049a5ca 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 @@ -2,8 +2,13 @@ package io.metersphere.api.parser.jmeter; import io.metersphere.api.dto.ApiParamConfig; +import io.metersphere.api.dto.request.http.MsHTTPConfig; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.QueryParam; +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.api.dto.request.http.body.Body; import io.metersphere.api.parser.jmeter.body.MsBodyConverter; import io.metersphere.api.parser.jmeter.body.MsBodyConverterFactory; @@ -25,6 +30,8 @@ import io.metersphere.sdk.util.LogUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.protocol.http.control.AuthManager; +import org.apache.jmeter.protocol.http.control.Authorization; import org.apache.jmeter.protocol.http.control.Header; import org.apache.jmeter.protocol.http.control.HeaderManager; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; @@ -34,10 +41,12 @@ import org.apache.jorphan.collections.HashTree; import org.springframework.http.HttpMethod; import java.util.*; +import java.util.function.BiConsumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; -import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.HEADER_PANEL; -import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.HTTP_TEST_SAMPLE_GUI; +import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.*; /** * @Author: jianxing @@ -71,22 +80,89 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter mechanismMap = HashMap.newHashMap(2); + private static final Map> authHanlerMap = HashMap.newHashMap(2); + + static { + mechanismMap.put(HTTPAuthConfig.HTTPAuthType.BASIC.name(), AuthManager.Mechanism.BASIC); + mechanismMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), AuthManager.Mechanism.DIGEST); + authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.BASIC.name(), (authorization, httpAuth) -> { + BasicAuth basicAuth = httpAuth.getBasicAuth(); + authorization.setUser(basicAuth.getUserName()); + authorization.setPass(basicAuth.getPassword()); + }); + authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), (authorization, httpAuth) -> { + DigestAuth digestAuth = httpAuth.getDigestAuth() ; + authorization.setUser(digestAuth.getUserName()); + authorization.setPass(digestAuth.getPassword()); + }); + } + + /** + * 获取认证配置 + * @param sampler + * @param authConfig + * @return + */ + private AuthManager getAuthManager(HTTPSamplerProxy sampler, HTTPAuthConfig authConfig) { + if (authConfig == null || !authConfig.isHTTPAuthValid()) { + return null; + } + + Authorization auth = new Authorization(); + auth.setURL(sampler.getPath()); + auth.setMechanism(mechanismMap.get(authConfig.getAuthType())); + authHanlerMap.get(authConfig.getAuthType()).accept(auth, authConfig); + + AuthManager authManager = new AuthManager(); + authManager.setEnabled(true); + authManager.setName("AuthManager"); + authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName()); + authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(AUTH_PANEL)); + authManager.addAuth(auth); + return authManager; + } + /** * 设置步骤标识 * 当前步骤唯一标识,结果和步骤匹配的关键 + * * @param msHTTPElement * @param config * @param sampler @@ -105,9 +181,71 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter rest = msHTTPElement.getRest(); + if (CollectionUtils.isEmpty(rest)) { + return path; + } + + rest = rest.stream() + .filter(RestParam::getEnable) + .filter(RestParam::isValid) + .filter(RestParam::isNotBlankValue) + .toList(); + + if (CollectionUtils.isEmpty(rest)) { + return path; + } + + Map keyValueMap = new HashMap<>(); + for (RestParam restParam : rest) { + try { + String value = restParam.getValue(); + value = Mock.buildFunctionCallString(value); + value = BooleanUtils.isTrue(restParam.getEncode()) ? String.format(URL_ENCODE, value.replace(",", "\\,")) : value; + keyValueMap.put(restParam.getKey(), value); + } catch (Exception e) { + LogUtils.error(e); + } + } + + try { + Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})"); + Matcher m = p.matcher(path); + while (m.find()) { + String group = m.group(2); + if (!isRestVariable(path, group) && keyValueMap.containsKey(group)) { + path = path.replace("{" + group + "}", keyValueMap.get(group)); + } + } + } catch (Exception e) { + LogUtils.error(e); + } + return path; + } + + private boolean isRestVariable(String path, String value) { + Pattern p = Pattern.compile("(\\$\\{)([\\w]+)(\\})"); + Matcher m = p.matcher(path); + while (m.find()) { + String group = m.group(2); + if (group.equals(value)) { + return true; + } + } + return false; + } + private HeaderManager getHttpHeader(MsHTTPElement msHTTPElement, ApiParamConfig apiParamConfig, HttpConfig httpConfig) { Map headerMap = new HashMap<>(); @@ -260,7 +398,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter { @Override public void parse(HTTPSamplerProxy sampler, BinaryBody body, ParameterConfig config) { - HTTPFileArg httpFileArg = getHttpFileArg(body.getFile()); + ApiFile file = body.getFile(); + if (file == null) { + return; + } + HTTPFileArg httpFileArg = getHttpFileArg(file); sampler.setHTTPFiles(new HTTPFileArg[]{httpFileArg}); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/constants/JmeterAlias.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/constants/JmeterAlias.java index 6b71a695d8..feadc616ff 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/constants/JmeterAlias.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/constants/JmeterAlias.java @@ -19,4 +19,5 @@ public class JmeterAlias { public static final String USER_PARAMETERS_GUI = "UserParametersGui"; public static final String COOKIE_PANEL = "CookiePanel"; public static final String HEADER_PANEL = "HeaderPanel"; + public static final String AUTH_PANEL = "AuthPanel"; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptFilter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptFilter.java index 57effe77dc..6322aeb7d9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptFilter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptFilter.java @@ -57,7 +57,7 @@ public class ScriptFilter { public static void verify(String language, String label, String script) { // 默认 groovy ScriptLanguageType scriptLanguageType = Arrays.stream(ScriptLanguageType.values()) - .filter(item -> StringUtils.equals(item.getValue(), language)) + .filter(item -> StringUtils.equals(item.name(), language)) .findFirst() .orElse(ScriptLanguageType.GROOVY); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java index ea1181a737..7ea4ab5f98 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java @@ -34,7 +34,7 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter getRestParams() { + RestParam restParam1 = new RestParam(); + restParam1.setKey("rest1"); + restParam1.setValue("value"); + RestParam restParam2 = new RestParam(); + restParam2.setKey("rest2"); + restParam2.setValue("value2"); + restParam2.setEncode(true); + RestParam restParam3 = new RestParam(); + restParam3.setKey("rest3"); + restParam3.setEnable(false); + return List.of(restParam1, restParam2, restParam3); + } + private void testBodyParse(ApiDebugRunRequest request, MsHTTPElement msHTTPElement, Body generalBody) throws Exception { // 测试 FORM_DATA generalBody.setBodyType(Body.BodyType.FORM_DATA.name()); 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 81462f82b8..77174bea7c 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 @@ -3,9 +3,9 @@ package io.metersphere.api.controller; import io.metersphere.api.dto.ApiTestPluginOptionRequest; import io.metersphere.api.service.BaseResourcePoolTestService; import io.metersphere.plugin.api.dto.ApiPluginSelectOption; +import io.metersphere.project.api.KeyValueParam; import io.metersphere.project.constants.ScriptLanguageType; import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest; -import io.metersphere.project.api.KeyValueParam; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.base.BasePluginTestService; import io.metersphere.system.base.BaseTest; @@ -25,7 +25,6 @@ import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import static io.metersphere.sdk.constants.InternalUserRole.ADMIN; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; @@ -78,7 +77,7 @@ public class ApiTestControllerTests extends BaseTest { CustomFunctionRunRequest request = new CustomFunctionRunRequest(); request.setReportId(IDGenerator.nextStr()); request.setProjectId(DEFAULT_PROJECT_ID); - request.setType(ScriptLanguageType.BEANSHELL.getValue()); + request.setType(ScriptLanguageType.BEANSHELL.name()); request.setScript(""" log.info("========"); log.info("${test}"); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java index 121b61dfca..73824a2567 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java @@ -6,10 +6,6 @@ import io.metersphere.api.dto.assertion.MsAssertionConfig; import io.metersphere.api.dto.definition.HttpResponse; import io.metersphere.api.dto.request.MsCommonElement; 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.HTTPAuth; -import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.request.processors.MsProcessorConfig; import io.metersphere.api.dto.schema.JsonSchemaItem; @@ -105,33 +101,6 @@ public class MsHTTPElementTest { return body; } - @Test - public void authConfigTest() { - - MsHTTPElement msHTTPElement = getMsHttpElement(); - - List authConfigs = new ArrayList<>(); - - authConfigs.add(new NoAuth()); - - BasicAuth basicAuth = new BasicAuth(); - basicAuth.setUserName("test"); - basicAuth.setPassword("passwd"); - authConfigs.add(basicAuth); - - DigestAuth digestAuth = new DigestAuth(); - digestAuth.setUserName("test"); - digestAuth.setPassword("passwd"); - authConfigs.add(digestAuth); - - for (Object authConfig : authConfigs) { - msHTTPElement.setAuthConfig((HTTPAuth) authConfig); - String json = ApiDataUtils.toJSONString(msHTTPElement); - Assertions.assertNotNull(json); - Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); - } - } - @Test public void processorParseTest() { @@ -157,13 +126,13 @@ public class MsHTTPElementTest { ScriptProcessor scriptProcessor = new ScriptProcessor(); scriptProcessor.setEnable(true); scriptProcessor.setScript("script"); - scriptProcessor.setScriptLanguage(ScriptLanguageType.JAVASCRIPT.getValue()); + scriptProcessor.setScriptLanguage(ScriptLanguageType.JAVASCRIPT.name()); processors.add(scriptProcessor); ScriptProcessor beanShellScriptProcessor = new ScriptProcessor(); beanShellScriptProcessor.setEnable(true); beanShellScriptProcessor.setScript("script"); - beanShellScriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL.getValue()); + beanShellScriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL.name()); processors.add(beanShellScriptProcessor); SQLProcessor sqlProcessor = new SQLProcessor(); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/KeyValueParam.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/KeyValueParam.java index 951ee7a9b5..5dc88a6366 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/KeyValueParam.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/KeyValueParam.java @@ -25,4 +25,8 @@ public class KeyValueParam { public boolean isValid() { return StringUtils.isNotBlank(key); } + + public boolean isNotBlankValue() { + return StringUtils.isNotBlank(value); + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/constants/ScriptLanguageType.java b/backend/services/project-management/src/main/java/io/metersphere/project/constants/ScriptLanguageType.java index 2a127d869d..3608fa078c 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/constants/ScriptLanguageType.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/constants/ScriptLanguageType.java @@ -5,19 +5,9 @@ package io.metersphere.project.constants; * @CreateTime: 2024-01-19 18:19 */ public enum ScriptLanguageType { - BEANSHELL("beanshell"), - BEANSHELL_JSR233("beanshell-jsr233"), - GROOVY("groovy"), - JAVASCRIPT("javascript"), - PYTHON("python"); - - private String value; - - ScriptLanguageType(String value) { - this.value = value; - } - - public String getValue() { - return value; - } + BEANSHELL, + BEANSHELL_JSR233, + GROOVY, + JAVASCRIPT, + PYTHON } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java index 16b6cb8165..22faadaf63 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/customfunction/request/CustomFunctionRequest.java @@ -1,5 +1,7 @@ package io.metersphere.project.dto.customfunction.request; +import io.metersphere.project.constants.ScriptLanguageType; +import io.metersphere.system.valid.EnumValue; import io.metersphere.validation.groups.Created; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; @@ -33,6 +35,7 @@ public class CustomFunctionRequest implements Serializable { private String name; @Schema(description = "脚本语言类型") + @EnumValue(enumClass = ScriptLanguageType.class) private String type; @Schema(description = "脚本状态(草稿/测试通过)")