refactor(项目管理): 优化环境的http参数

This commit is contained in:
wxg0103 2024-03-04 19:35:32 +08:00 committed by 刘瑞斌
parent dbacfc7d7c
commit 13e34f8ee7
10 changed files with 45 additions and 14 deletions

View File

@ -106,6 +106,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
/** /**
* 设置超时时间等配置 * 设置超时时间等配置
*
* @param msHTTPConfig * @param msHTTPConfig
* @param sampler * @param sampler
*/ */
@ -128,7 +129,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
authorization.setPass(basicAuth.getPassword()); authorization.setPass(basicAuth.getPassword());
}); });
authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), (authorization, httpAuth) -> { authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), (authorization, httpAuth) -> {
DigestAuth digestAuth = httpAuth.getDigestAuth() ; DigestAuth digestAuth = httpAuth.getDigestAuth();
authorization.setUser(digestAuth.getUserName()); authorization.setUser(digestAuth.getUserName());
authorization.setPass(digestAuth.getPassword()); authorization.setPass(digestAuth.getPassword());
}); });
@ -136,6 +137,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
/** /**
* 获取认证配置 * 获取认证配置
*
* @param authConfig * @param authConfig
* @return * @return
*/ */
@ -178,7 +180,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
if (httpConfig != null) { if (httpConfig != null) {
// 接口调试没有环境不取环境的配置 // 接口调试没有环境不取环境的配置
String protocol = httpConfig.getProtocol().toLowerCase(); String protocol = httpConfig.getProtocol().toLowerCase();
url = protocol + "://" + (httpConfig.getUrl() + "/" + url).replace("//", "/"); url = protocol + "://" + (httpConfig.getHostname() + "/" + url).replace("//", "/");
} }
url = getPathWithQueryRest(msHTTPElement, url); url = getPathWithQueryRest(msHTTPElement, url);
return getPathWithQuery(url, msHTTPElement.getQuery()); return getPathWithQuery(url, msHTTPElement.getQuery());
@ -186,6 +188,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
/** /**
* 替换 rest 参数 * 替换 rest 参数
*
* @param msHTTPElement * @param msHTTPElement
* @param path * @param path
* @return * @return

View File

@ -1087,12 +1087,12 @@ public class ApiScenarioControllerTests extends BaseTest {
header3.setValue("a=b"); header3.setValue("a=b");
HttpConfig httpNoneConfig = new HttpConfig(); HttpConfig httpNoneConfig = new HttpConfig();
httpNoneConfig.setUrl("localhost:8081"); httpNoneConfig.setHostname("localhost:8081");
httpNoneConfig.setType(HttpConfig.HttpConfigMatchType.NONE.name()); httpNoneConfig.setType(HttpConfig.HttpConfigMatchType.NONE.name());
httpNoneConfig.setHeaders(List.of(header1, header2, header3)); httpNoneConfig.setHeaders(List.of(header1, header2, header3));
HttpConfig httpModuleConfig = new HttpConfig(); HttpConfig httpModuleConfig = new HttpConfig();
httpModuleConfig.setUrl("localhost:8081"); httpModuleConfig.setHostname("localhost:8081");
httpModuleConfig.setType(HttpConfig.HttpConfigMatchType.MODULE.name()); httpModuleConfig.setType(HttpConfig.HttpConfigMatchType.MODULE.name());
SelectModule selectModule = new SelectModule(); SelectModule selectModule = new SelectModule();
selectModule.setModuleId(moduleId); selectModule.setModuleId(moduleId);
@ -1101,7 +1101,7 @@ public class ApiScenarioControllerTests extends BaseTest {
httpModuleConfig.setHeaders(List.of(header1, header2, header3)); httpModuleConfig.setHeaders(List.of(header1, header2, header3));
HttpConfig httpPathConfig = new HttpConfig(); HttpConfig httpPathConfig = new HttpConfig();
httpPathConfig.setUrl("localhost:8081"); httpPathConfig.setHostname("localhost:8081");
httpPathConfig.setType(HttpConfig.HttpConfigMatchType.PATH.name()); httpPathConfig.setType(HttpConfig.HttpConfigMatchType.PATH.name());
httpPathConfig.getPathMatchRule().setPath("/test"); httpPathConfig.getPathMatchRule().setPath("/test");
httpPathConfig.getPathMatchRule().setCondition(HttpConfigPathMatchRule.MatchRuleCondition.CONTAINS.name()); httpPathConfig.getPathMatchRule().setCondition(HttpConfigPathMatchRule.MatchRuleCondition.CONTAINS.name());

View File

@ -21,7 +21,7 @@ public class HttpConfig implements Serializable {
@EnumValue(enumClass = HttpProtocolType.class) @EnumValue(enumClass = HttpProtocolType.class)
private String protocol = HttpProtocolType.HTTP.name(); private String protocol = HttpProtocolType.HTTP.name();
@Schema(description = "环境域名") @Schema(description = "环境域名")
private String url; private String hostname;
/** /**
* 启用条件 * 启用条件
* {@link HttpConfigMatchType} * {@link HttpConfigMatchType}
@ -39,6 +39,8 @@ public class HttpConfig implements Serializable {
private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0); private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0);
@Schema(description = "描述") @Schema(description = "描述")
private String description; private String description;
@Schema(description = "排序")
private int order;
public boolean isModuleMatchRule() { public boolean isModuleMatchRule() {

View File

@ -197,7 +197,7 @@ public class EnvironmentService {
List<HttpConfig> httpConfigs = environmentInfoDTO.getConfig().getHttpConfig(); List<HttpConfig> httpConfigs = environmentInfoDTO.getConfig().getHttpConfig();
if (CollectionUtils.isEmpty(httpConfigs)) { if (CollectionUtils.isEmpty(httpConfigs)) {
HttpConfig httpConfig = new HttpConfig(); HttpConfig httpConfig = new HttpConfig();
httpConfig.setUrl(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum())); httpConfig.setHostname(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum()));
httpConfigs.add(new HttpConfig()); httpConfigs.add(new HttpConfig());
} }
} }
@ -446,7 +446,7 @@ public class EnvironmentService {
if (BooleanUtils.isTrue(environment.getMock())) { if (BooleanUtils.isTrue(environment.getMock())) {
if (StringUtils.isNotEmpty(baseUrl)) { if (StringUtils.isNotEmpty(baseUrl)) {
Long projectNum = projectMap.get(environment.getProjectId()).getNum(); Long projectNum = projectMap.get(environment.getProjectId()).getNum();
environmentInfo.getConfig().getHttpConfig().getFirst().setUrl(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, projectNum)); environmentInfo.getConfig().getHttpConfig().getFirst().setHostname(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, projectNum));
} }
} }
environmentInfos.add(environmentInfo); environmentInfos.add(environmentInfo);

View File

@ -20,6 +20,7 @@ import io.metersphere.project.dto.environment.ssl.KeyStoreConfig;
import io.metersphere.project.dto.environment.ssl.KeyStoreEntry; import io.metersphere.project.dto.environment.ssl.KeyStoreEntry;
import io.metersphere.project.dto.environment.ssl.KeyStoreFile; 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.service.EnvironmentService;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.MsAssertionCondition; import io.metersphere.sdk.constants.MsAssertionCondition;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
@ -111,6 +112,8 @@ public class EnvironmentControllerTests extends BaseTest {
private PluginService pluginService; private PluginService pluginService;
@Resource @Resource
private PluginScriptMapper pluginScriptMapper; private PluginScriptMapper pluginScriptMapper;
@Resource
private EnvironmentService environmentService;
@Value("${spring.datasource.url}") @Value("${spring.datasource.url}")
private String dburl; private String dburl;
@Value("${spring.datasource.username}") @Value("${spring.datasource.username}")
@ -231,7 +234,7 @@ public class EnvironmentControllerTests extends BaseTest {
keyValue.setValue("value"); keyValue.setValue("value");
headers.add(keyValue); headers.add(keyValue);
httpConfig.setHeaders(headers); httpConfig.setHeaders(headers);
httpConfig.setUrl("http://www.baidu.com"); httpConfig.setHostname("http://www.baidu.com");
httpConfigs.add(httpConfig); httpConfigs.add(httpConfig);
return httpConfigs; return httpConfigs;
@ -1217,4 +1220,14 @@ public class EnvironmentControllerTests extends BaseTest {
List<EnvironmentOptionsDTO> options = getResultDataArray(mvcResult, EnvironmentOptionsDTO.class); List<EnvironmentOptionsDTO> options = getResultDataArray(mvcResult, EnvironmentOptionsDTO.class);
Assertions.assertFalse(options.isEmpty()); Assertions.assertFalse(options.isEmpty());
} }
@Test
@Order(18)
public void addCover() throws Exception {
List<Environment> environments = environmentMapper.selectByExample(new EnvironmentExample());
//获取id集合 过滤一下mock为false的
List<String> ids = environments.stream().filter(environment -> !environment.getMock()).map(Environment::getId).toList();
environmentService.getByIds(ids);
environmentService.getEnvironmentBlobsByIds(List.of());
}
} }

View File

@ -117,7 +117,7 @@ public class EnvironmentGroupControllerTests extends BaseTest {
keyValue.setValue("value"); keyValue.setValue("value");
headers.add(keyValue); headers.add(keyValue);
httpConfig.setHeaders(headers); httpConfig.setHeaders(headers);
httpConfig.setUrl("http://www.baidu.com"); httpConfig.setHostname("http://www.baidu.com");
httpConfigs.add(httpConfig); httpConfigs.add(httpConfig);
return httpConfigs; return httpConfigs;

View File

@ -342,7 +342,7 @@
<template #host="{ record }"> <template #host="{ record }">
<span v-if="!record.domain || record.domain.length === 0"></span> <span v-if="!record.domain || record.domain.length === 0"></span>
<span v-else-if="Array.isArray(record.domain) && record.domain.length === 1" class="text-[var(--color-text-4)]">{{ <span v-else-if="Array.isArray(record.domain) && record.domain.length === 1" class="text-[var(--color-text-4)]">{{
record.domain[0].protocol + '://' + (record.domain[0].url || '') record.domain[0].protocol + '://' + (record.domain[0].hostname || '')
}}</span> }}</span>
<span <span
v-if="Array.isArray(record.domain) && record.domain.length > 1" v-if="Array.isArray(record.domain) && record.domain.length > 1"
@ -726,7 +726,7 @@
const showHostModal = (record: Record<string, any>) => { const showHostModal = (record: Record<string, any>) => {
hostVisible.value = true; hostVisible.value = true;
record.domain?.forEach((e: any) => { record.domain?.forEach((e: any) => {
e.host = `${e.protocol} :// ${e.url || ''}`; e.host = `${e.protocol} :// ${e.hostname || ''}`;
}); });
hostData.value = record.domain || []; hostData.value = record.domain || [];

View File

@ -460,7 +460,12 @@
// //
const handleDeleteEnv = async (id: string) => { const handleDeleteEnv = async (id: string) => {
try { try {
await deleteEnv(id); if (store.currentId === NEW_ENV_PARAM) {
// idnewEnvParam
envList.value = envList.value.filter((item) => item.id !== id);
} else {
await deleteEnv(id);
}
if (store.currentId === id) { if (store.currentId === id) {
store.setCurrentId(''); store.setCurrentId('');
} }
@ -474,7 +479,12 @@
// //
const handleDeleteEnvGroup = async (id: string) => { const handleDeleteEnvGroup = async (id: string) => {
try { try {
await deleteEnvGroup(id); if (store.currentGroupId === NEW_ENV_GROUP) {
// idnewEnvParam
evnGroupList.value = evnGroupList.value.filter((item) => item.id !== id);
} else {
await deleteEnvGroup(id);
}
await initGroupList(); await initGroupList();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

View File

@ -84,4 +84,6 @@ export default {
'project.environmental.host.hostNamePlaceholder': 'Please enter the host name', 'project.environmental.host.hostNamePlaceholder': 'Please enter the host name',
'project.environmental.host.desc': 'Description', 'project.environmental.host.desc': 'Description',
'project.environmental.host.descPlaceholder': 'Please enter the description', 'project.environmental.host.descPlaceholder': 'Please enter the description',
'project.environmental.newEnv': 'New Environment',
'project.environmental.http.hostNamePlaceholder': 'Please enter the host name',
}; };

View File

@ -101,4 +101,5 @@ export default {
'project.environmental.group.envGroupName': '环境组名称', 'project.environmental.group.envGroupName': '环境组名称',
'project.environmental.group.envGroupNameIsRequire': '环境组名称不能为空', 'project.environmental.group.envGroupNameIsRequire': '环境组名称不能为空',
'project.environmental.group.envGroupPlaceholder': '请输入环境组', 'project.environmental.group.envGroupPlaceholder': '请输入环境组',
'project.environmental.http.hostNamePlaceholder': '请输入域名',
}; };