fix(系统设置): 修复更新环境前后端未校验响应时间的缺陷

--bug=1013644 --user=王孝刚 [接口测试]github#14112更新或修改配置环境时“链接超时”前后端都没有进行校验。
https://www.tapd.cn/55049933/s/1170028
This commit is contained in:
wxg0103 2022-05-31 15:21:56 +08:00 committed by f2c-ci-robot[bot]
parent 647ffccd5c
commit cd4afe085e
4 changed files with 54 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package io.metersphere.api.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.ApiTestEnvironmentDTO;
@ -9,9 +11,12 @@ import io.metersphere.api.service.CommandService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.OperLogModule;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.EnvironmentRequest;
import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -61,15 +66,44 @@ public class ApiTestEnvironmentController {
@PostMapping("/add")
@MsAuditLog(module = OperLogModule.PROJECT_ENVIRONMENT_SETTING, type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#apiTestEnvironmentWithBLOBs.id)", msClass = ApiTestEnvironmentService.class)
public String create(@RequestPart("request") ApiTestEnvironmentDTO apiTestEnvironmentWithBLOBs, @RequestPart(value = "files", required = false) List<MultipartFile> sslFiles) {
checkParams(apiTestEnvironmentWithBLOBs);
return apiTestEnvironmentService.add(apiTestEnvironmentWithBLOBs, sslFiles);
}
@PostMapping(value = "/update")
@MsAuditLog(module = OperLogModule.PROJECT_ENVIRONMENT_SETTING, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#apiTestEnvironment.id)", content = "#msClass.getLogDetails(#apiTestEnvironment.id)", msClass = ApiTestEnvironmentService.class)
public void update(@RequestPart("request") ApiTestEnvironmentDTO apiTestEnvironment, @RequestPart(value = "files", required = false) List<MultipartFile> sslFiles) {
checkParams(apiTestEnvironment);
apiTestEnvironmentService.update(apiTestEnvironment, sslFiles);
}
private void checkParams(ApiTestEnvironmentDTO apiTestEnvironment) {
try {
JSONObject json = JSONObject.parseObject(apiTestEnvironment.getConfig());
JSONObject commonConfig = json.getJSONObject("commonConfig");
JSONArray databaseConfigs = json.getJSONArray("databaseConfigs");
Object requestTimeout = commonConfig.get("requestTimeout");
Object responseTimeout = commonConfig.get("responseTimeout");
if (commonConfig != null && (requestTimeout != null || responseTimeout != null) && ((int) requestTimeout < 1 ||
(int) responseTimeout < 1)) {
MSException.throwException(Translator.get("invalid_parameter"));
}
if (databaseConfigs.size() > 0) {
for (Object databaseConfig : databaseConfigs) {
JSONObject database = (JSONObject) databaseConfig;
Object poolMax = database.get("poolMax");
Object timeout = database.get("timeout");
if (database != null && (poolMax != null || timeout != null) && (int) database.get("poolMax") < 1 || (int) database.get("timeout") < 1) {
MSException.throwException(Translator.get("invalid_parameter"));
}
}
}
} catch (Exception e) {
LogUtil.error(e);
}
}
@GetMapping("/delete/{id}")
@MsAuditLog(module = OperLogModule.PROJECT_ENVIRONMENT_SETTING, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiTestEnvironmentService.class)
public void delete(@PathVariable String id) {

View File

@ -8,12 +8,16 @@
<el-form-item>
<span>{{ $t('api_test.environment.request_timeout') }}:</span>
<el-input-number style="margin-left: 20px" controls-position="right" size="small"
v-model="commonConfig.requestTimeout">
v-model="commonConfig.requestTimeout"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0">
{{ $t('api_test.environment.globalVariable') }}
</el-input-number>
<span style="margin-left: 30px">{{ $t('api_test.environment.response_timeout') }}:</span>
<el-input-number style="margin-left: 20px" controls-position="right" size="small"
v-model="commonConfig.responseTimeout">
v-model="commonConfig.responseTimeout"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0">
{{ $t('api_test.environment.globalVariable') }}
</el-input-number>
</el-form-item>

View File

@ -32,12 +32,18 @@
</el-form-item>
<el-form-item :label="$t('api_test.request.sql.pool_max')" prop="poolMax">
<el-input-number size="small" :disabled="isReadOnly" v-model="currentConfig.poolMax" :placeholder="$t('commons.please_select')" :max="100" :min="0"/>
<el-input-number size="small" :disabled="isReadOnly" v-model="currentConfig.poolMax"
:placeholder="$t('commons.please_select')" :max="100" :min="0"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0"/>
</el-form-item>
<el-form-item :label="$t('api_test.request.sql.timeout')" prop="timeout">
<el-input-number size="small" :disabled="isReadOnly" v-model="currentConfig.timeout" :placeholder="$t('commons.millisecond')" :max="1000*10000000" :min="0"/>
<el-input-number size="small" :disabled="isReadOnly" v-model="currentConfig.timeout"
:placeholder="$t('commons.millisecond')" :max="1000*10000000" :min="0"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0"/>
</el-form-item>
<el-form-item>

View File

@ -24,12 +24,16 @@
<el-row :gutter="10">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout">
<el-input-number v-model="config.ctimeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
<el-input-number v-model="config.ctimeout" controls-position="right" :min="0" :step="1000" :controls="false"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout" label-width="120px">
<el-input-number v-model="config.timeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
<el-input-number v-model="config.timeout" controls-position="right" :min="0" :step="1000" :controls="false"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
:precision="0"/>
</el-form-item>
</el-col>
</el-row>