refactor(项目管理): 优化环境的http参数
This commit is contained in:
parent
dbacfc7d7c
commit
13e34f8ee7
|
@ -106,6 +106,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
|
||||
/**
|
||||
* 设置超时时间等配置
|
||||
*
|
||||
* @param msHTTPConfig
|
||||
* @param sampler
|
||||
*/
|
||||
|
@ -128,7 +129,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
authorization.setPass(basicAuth.getPassword());
|
||||
});
|
||||
authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), (authorization, httpAuth) -> {
|
||||
DigestAuth digestAuth = httpAuth.getDigestAuth() ;
|
||||
DigestAuth digestAuth = httpAuth.getDigestAuth();
|
||||
authorization.setUser(digestAuth.getUserName());
|
||||
authorization.setPass(digestAuth.getPassword());
|
||||
});
|
||||
|
@ -136,6 +137,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
|
||||
/**
|
||||
* 获取认证配置
|
||||
*
|
||||
* @param authConfig
|
||||
* @return
|
||||
*/
|
||||
|
@ -178,7 +180,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
if (httpConfig != null) {
|
||||
// 接口调试没有环境,不取环境的配置
|
||||
String protocol = httpConfig.getProtocol().toLowerCase();
|
||||
url = protocol + "://" + (httpConfig.getUrl() + "/" + url).replace("//", "/");
|
||||
url = protocol + "://" + (httpConfig.getHostname() + "/" + url).replace("//", "/");
|
||||
}
|
||||
url = getPathWithQueryRest(msHTTPElement, url);
|
||||
return getPathWithQuery(url, msHTTPElement.getQuery());
|
||||
|
@ -186,6 +188,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
|
||||
/**
|
||||
* 替换 rest 参数
|
||||
*
|
||||
* @param msHTTPElement
|
||||
* @param path
|
||||
* @return
|
||||
|
|
|
@ -1087,12 +1087,12 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
header3.setValue("a=b");
|
||||
|
||||
HttpConfig httpNoneConfig = new HttpConfig();
|
||||
httpNoneConfig.setUrl("localhost:8081");
|
||||
httpNoneConfig.setHostname("localhost:8081");
|
||||
httpNoneConfig.setType(HttpConfig.HttpConfigMatchType.NONE.name());
|
||||
httpNoneConfig.setHeaders(List.of(header1, header2, header3));
|
||||
|
||||
HttpConfig httpModuleConfig = new HttpConfig();
|
||||
httpModuleConfig.setUrl("localhost:8081");
|
||||
httpModuleConfig.setHostname("localhost:8081");
|
||||
httpModuleConfig.setType(HttpConfig.HttpConfigMatchType.MODULE.name());
|
||||
SelectModule selectModule = new SelectModule();
|
||||
selectModule.setModuleId(moduleId);
|
||||
|
@ -1101,7 +1101,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
httpModuleConfig.setHeaders(List.of(header1, header2, header3));
|
||||
|
||||
HttpConfig httpPathConfig = new HttpConfig();
|
||||
httpPathConfig.setUrl("localhost:8081");
|
||||
httpPathConfig.setHostname("localhost:8081");
|
||||
httpPathConfig.setType(HttpConfig.HttpConfigMatchType.PATH.name());
|
||||
httpPathConfig.getPathMatchRule().setPath("/test");
|
||||
httpPathConfig.getPathMatchRule().setCondition(HttpConfigPathMatchRule.MatchRuleCondition.CONTAINS.name());
|
||||
|
|
|
@ -21,7 +21,7 @@ public class HttpConfig implements Serializable {
|
|||
@EnumValue(enumClass = HttpProtocolType.class)
|
||||
private String protocol = HttpProtocolType.HTTP.name();
|
||||
@Schema(description = "环境域名")
|
||||
private String url;
|
||||
private String hostname;
|
||||
/**
|
||||
* 启用条件
|
||||
* {@link HttpConfigMatchType}
|
||||
|
@ -39,6 +39,8 @@ public class HttpConfig implements Serializable {
|
|||
private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0);
|
||||
@Schema(description = "描述")
|
||||
private String description;
|
||||
@Schema(description = "排序")
|
||||
private int order;
|
||||
|
||||
|
||||
public boolean isModuleMatchRule() {
|
||||
|
|
|
@ -197,7 +197,7 @@ public class EnvironmentService {
|
|||
List<HttpConfig> httpConfigs = environmentInfoDTO.getConfig().getHttpConfig();
|
||||
if (CollectionUtils.isEmpty(httpConfigs)) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ public class EnvironmentService {
|
|||
if (BooleanUtils.isTrue(environment.getMock())) {
|
||||
if (StringUtils.isNotEmpty(baseUrl)) {
|
||||
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);
|
||||
|
|
|
@ -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.KeyStoreFile;
|
||||
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.MsAssertionCondition;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
|
@ -111,6 +112,8 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
private PluginService pluginService;
|
||||
@Resource
|
||||
private PluginScriptMapper pluginScriptMapper;
|
||||
@Resource
|
||||
private EnvironmentService environmentService;
|
||||
@Value("${spring.datasource.url}")
|
||||
private String dburl;
|
||||
@Value("${spring.datasource.username}")
|
||||
|
@ -231,7 +234,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
keyValue.setValue("value");
|
||||
headers.add(keyValue);
|
||||
httpConfig.setHeaders(headers);
|
||||
httpConfig.setUrl("http://www.baidu.com");
|
||||
httpConfig.setHostname("http://www.baidu.com");
|
||||
|
||||
httpConfigs.add(httpConfig);
|
||||
return httpConfigs;
|
||||
|
@ -1217,4 +1220,14 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
List<EnvironmentOptionsDTO> options = getResultDataArray(mvcResult, EnvironmentOptionsDTO.class);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ public class EnvironmentGroupControllerTests extends BaseTest {
|
|||
keyValue.setValue("value");
|
||||
headers.add(keyValue);
|
||||
httpConfig.setHeaders(headers);
|
||||
httpConfig.setUrl("http://www.baidu.com");
|
||||
httpConfig.setHostname("http://www.baidu.com");
|
||||
|
||||
httpConfigs.add(httpConfig);
|
||||
return httpConfigs;
|
||||
|
|
|
@ -342,7 +342,7 @@
|
|||
<template #host="{ record }">
|
||||
<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)]">{{
|
||||
record.domain[0].protocol + '://' + (record.domain[0].url || '')
|
||||
record.domain[0].protocol + '://' + (record.domain[0].hostname || '')
|
||||
}}</span>
|
||||
<span
|
||||
v-if="Array.isArray(record.domain) && record.domain.length > 1"
|
||||
|
@ -726,7 +726,7 @@
|
|||
const showHostModal = (record: Record<string, any>) => {
|
||||
hostVisible.value = true;
|
||||
record.domain?.forEach((e: any) => {
|
||||
e.host = `${e.protocol} :// ${e.url || ''}`;
|
||||
e.host = `${e.protocol} :// ${e.hostname || ''}`;
|
||||
});
|
||||
|
||||
hostData.value = record.domain || [];
|
||||
|
|
|
@ -460,7 +460,12 @@
|
|||
// 处理删除环境
|
||||
const handleDeleteEnv = async (id: string) => {
|
||||
try {
|
||||
await deleteEnv(id);
|
||||
if (store.currentId === NEW_ENV_PARAM) {
|
||||
// 删除id为newEnvParam的环境
|
||||
envList.value = envList.value.filter((item) => item.id !== id);
|
||||
} else {
|
||||
await deleteEnv(id);
|
||||
}
|
||||
if (store.currentId === id) {
|
||||
store.setCurrentId('');
|
||||
}
|
||||
|
@ -474,7 +479,12 @@
|
|||
// 处理删除环境组
|
||||
const handleDeleteEnvGroup = async (id: string) => {
|
||||
try {
|
||||
await deleteEnvGroup(id);
|
||||
if (store.currentGroupId === NEW_ENV_GROUP) {
|
||||
// 删除id为newEnvParam的环境
|
||||
evnGroupList.value = evnGroupList.value.filter((item) => item.id !== id);
|
||||
} else {
|
||||
await deleteEnvGroup(id);
|
||||
}
|
||||
await initGroupList();
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -84,4 +84,6 @@ export default {
|
|||
'project.environmental.host.hostNamePlaceholder': 'Please enter the host name',
|
||||
'project.environmental.host.desc': 'Description',
|
||||
'project.environmental.host.descPlaceholder': 'Please enter the description',
|
||||
'project.environmental.newEnv': 'New Environment',
|
||||
'project.environmental.http.hostNamePlaceholder': 'Please enter the host name',
|
||||
};
|
||||
|
|
|
@ -101,4 +101,5 @@ export default {
|
|||
'project.environmental.group.envGroupName': '环境组名称',
|
||||
'project.environmental.group.envGroupNameIsRequire': '环境组名称不能为空',
|
||||
'project.environmental.group.envGroupPlaceholder': '请输入环境组',
|
||||
'project.environmental.http.hostNamePlaceholder': '请输入域名',
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue