From 1ea17a964c0271b9dcc5eb8b76ef5380891f7828 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 19 Mar 2024 19:38:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0dns=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/jmeter/MsHTTPElementConverter.java | 52 +++++++++++++++++-- .../ApiTestCaseControllerTests.java | 43 ++++++++++++++- .../scenario/components/scenarioTable.vue | 6 +-- .../scenario/recycle/recycleTable.vue | 6 +-- .../components/envParams/HostTab.vue | 2 +- 5 files changed, 97 insertions(+), 12 deletions(-) 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 e347d1f2bb..f84ab4d1c1 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 @@ -22,6 +22,7 @@ import io.metersphere.project.api.KeyValueEnableParam; import io.metersphere.project.api.KeyValueParam; import io.metersphere.project.dto.environment.EnvironmentInfoDTO; import io.metersphere.project.dto.environment.GlobalParams; +import io.metersphere.project.dto.environment.host.Host; import io.metersphere.project.dto.environment.http.HttpConfig; import io.metersphere.project.dto.environment.http.HttpConfigPathMatchRule; import io.metersphere.project.dto.environment.http.SelectModule; @@ -32,10 +33,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; -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.control.*; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; @@ -61,6 +59,9 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter headerMap, List headers) { if (CollectionUtils.isEmpty(headers)) { return; @@ -436,4 +442,42 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter hosts = new ArrayList<>(); + envConfig.getConfig().getHostConfig().getHosts().forEach(host -> { + if (StringUtils.isNotBlank(host.getDomain())) { + String hostDomain = host.getDomain().trim().replace(HTTP, StringUtils.EMPTY).replace(HTTPS, StringUtils.EMPTY); + if (StringUtils.equals(hostDomain, domain)) { + host.setDomain(hostDomain); // 域名去掉协议 + hosts.add(host); + } + } + }); + if (CollectionUtils.isNotEmpty(hosts)) { + return dnsCacheManager(name + "DNSCacheManager", hosts); + } + return null; + } + + private static DNSCacheManager dnsCacheManager(String name, List hosts) { + DNSCacheManager dnsCacheManager = new DNSCacheManager(); + dnsCacheManager.setEnabled(true); + dnsCacheManager.setName(name); + dnsCacheManager.setProperty(TestElement.TEST_CLASS, DNSCacheManager.class.getName()); + dnsCacheManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DNSCachePanel")); + dnsCacheManager.setCustomResolver(false); + dnsCacheManager.setClearEachIteration(true); + hosts.forEach(host -> dnsCacheManager.addHost(host.getDomain(), host.getIp())); + + return dnsCacheManager; + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java index 331a8660ef..ed5758505d 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java @@ -20,15 +20,21 @@ import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.domain.ProjectVersion; +import io.metersphere.project.dto.environment.EnvironmentConfig; +import io.metersphere.project.dto.environment.host.Host; +import io.metersphere.project.dto.environment.host.HostConfig; +import io.metersphere.project.dto.environment.http.HttpConfig; import io.metersphere.project.dto.filemanagement.FileInfo; import io.metersphere.project.mapper.ProjectVersionMapper; import io.metersphere.project.service.FileAssociationService; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.domain.Environment; +import io.metersphere.sdk.domain.EnvironmentBlob; import io.metersphere.sdk.domain.EnvironmentExample; import io.metersphere.sdk.file.FileCenter; import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.file.MinioRepository; +import io.metersphere.sdk.mapper.EnvironmentBlobMapper; import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.CommonBeanFactory; @@ -119,6 +125,8 @@ public class ApiTestCaseControllerTests extends BaseTest { private ApiTestCaseFollowerMapper apiTestCaseFollowerMapper; @Resource private EnvironmentMapper environmentMapper; + @Resource + private EnvironmentBlobMapper environmentBlobMapper; private static String fileMetadataId; @Resource private SqlSessionFactory sqlSessionFactory; @@ -426,7 +434,40 @@ public class ApiTestCaseControllerTests extends BaseTest { resultHolder.getCode() == MsHttpResultCode.SUCCESS.getCode()); // 测试执行 - request.setEnvironmentId("envId"); + Environment environment = new Environment(); + environment.setId("test-host"); + environment.setProjectId(DEFAULT_PROJECT_ID); + environment.setName("test-host"); + environment.setPos(0L); + environment.setCreateTime(System.currentTimeMillis()); + environment.setUpdateTime(System.currentTimeMillis()); + environment.setCreateUser("admin"); + environment.setUpdateUser("admin"); + environment.setMock(false); + environmentMapper.insert(environment); + EnvironmentConfig environmentConfig = new EnvironmentConfig(); + List httpConfigs = new ArrayList<>(); + HttpConfig httpConfig = new HttpConfig(); + httpConfig.setHostname("www.aa.com"); + httpConfig.setType("NONE"); + httpConfig.setProtocol("HTTP"); + httpConfigs.add(httpConfig); + environmentConfig.setHttpConfig(httpConfigs); + HostConfig hostConfig = new HostConfig(); + hostConfig.setEnable(true); + List hosts = new ArrayList<>(); + Host host = new Host(); + host.setIp("172.0.0.1"); + host.setDomain("www.aa.com"); + hosts.add(host); + hostConfig.setHosts(hosts); + environmentConfig.setHostConfig(hostConfig); + EnvironmentBlob environmentBlob = new EnvironmentBlob(); + environmentBlob.setId(environment.getId()); + environmentBlob.setConfig(JSON.toJSONBytes(environmentConfig)); + environmentBlobMapper.insert(environmentBlob); + + request.setEnvironmentId("test-host"); mvcResult = this.requestPostAndReturn(RUN_POST, request); resultHolder = JSON.parseObject(mvcResult.getResponse().getContentAsString(Charset.defaultCharset()), ResultHolder.class); Assertions.assertTrue(resultHolder.getCode() == ApiResultCode.RESOURCE_POOL_EXECUTE_ERROR.getCode() || diff --git a/frontend/src/views/api-test/scenario/components/scenarioTable.vue b/frontend/src/views/api-test/scenario/components/scenarioTable.vue index 8ea733c9a7..f446f98951 100644 --- a/frontend/src/views/api-test/scenario/components/scenarioTable.vue +++ b/frontend/src/views/api-test/scenario/components/scenarioTable.vue @@ -9,7 +9,7 @@ type="line" @change="loadScenarioList(false)" /> - {{ + {{ t('apiScenario.table.showChildrenModuleScenario') }} @@ -425,14 +425,14 @@ }, { title: 'apiScenario.table.columns.createUser', - dataIndex: 'createUser', + dataIndex: 'createUserName', titleSlotName: 'createUser', width: 109, showDrag: true, }, { title: 'apiScenario.table.columns.updateUser', - dataIndex: 'updateUser', + dataIndex: 'updateUserName', titleSlotName: 'updateUser', width: 109, showDrag: true, diff --git a/frontend/src/views/api-test/scenario/recycle/recycleTable.vue b/frontend/src/views/api-test/scenario/recycle/recycleTable.vue index 266da410b5..54f2f25da9 100644 --- a/frontend/src/views/api-test/scenario/recycle/recycleTable.vue +++ b/frontend/src/views/api-test/scenario/recycle/recycleTable.vue @@ -9,7 +9,7 @@ type="line" @change="loadScenarioList(false)" /> - {{ + {{ t('apiScenario.table.showChildrenModuleScenario') }} @@ -265,14 +265,14 @@ }, { title: 'apiScenario.table.columns.createUser', - dataIndex: 'createUser', + dataIndex: 'createUserName', titleSlotName: 'createUser', width: 109, showDrag: true, }, { title: 'apiScenario.table.columns.updateUser', - dataIndex: 'updateUser', + dataIndex: 'updateUserName', titleSlotName: 'updateUser', width: 109, showDrag: true, diff --git a/frontend/src/views/project-management/environmental/components/envParams/HostTab.vue b/frontend/src/views/project-management/environmental/components/envParams/HostTab.vue index 75af13d2a5..9d5a43c55d 100644 --- a/frontend/src/views/project-management/environmental/components/envParams/HostTab.vue +++ b/frontend/src/views/project-management/environmental/components/envParams/HostTab.vue @@ -82,7 +82,7 @@ placeholder: 'project.environmental.host.ipPlaceholder', rules: [ { required: true, message: t('project.environmental.host.ipIsRequire') }, - { notRepeat: true, message: 'project.environmental.host.ipNotRepeat' }, + { notRepeat: true, message: t('project.environmental.host.ipNotRepeat') }, ], }, {