fix(接口测试): 加强host列表校验
This commit is contained in:
parent
92c5215349
commit
a92db96844
|
@ -65,300 +65,300 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import MsApiScenarioConfig from "./components/ApiScenarioConfig";
|
||||
import {Test} from "./model/ScenarioModel"
|
||||
import MsApiReportStatus from "../report/ApiReportStatus";
|
||||
import MsApiReportDialog from "./ApiReportDialog";
|
||||
import {checkoutTestManagerOrTestUser, downloadFile} from "@/common/js/utils";
|
||||
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
|
||||
import ApiImport from "./components/import/ApiImport";
|
||||
import {getUUID} from "../../../../common/js/utils";
|
||||
import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent";
|
||||
import MsContainer from "@/business/components/common/components/MsContainer";
|
||||
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
|
||||
import MsApiScenarioConfig from "./components/ApiScenarioConfig";
|
||||
import {Test} from "./model/ScenarioModel"
|
||||
import MsApiReportStatus from "../report/ApiReportStatus";
|
||||
import MsApiReportDialog from "./ApiReportDialog";
|
||||
import {checkoutTestManagerOrTestUser, downloadFile} from "@/common/js/utils";
|
||||
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
|
||||
import ApiImport from "./components/import/ApiImport";
|
||||
import {getUUID} from "../../../../common/js/utils";
|
||||
import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent";
|
||||
import MsContainer from "@/business/components/common/components/MsContainer";
|
||||
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
|
||||
|
||||
export default {
|
||||
name: "MsApiTestConfig",
|
||||
export default {
|
||||
name: "MsApiTestConfig",
|
||||
|
||||
components: {
|
||||
MsMainContainer,
|
||||
MsContainer, ApiImport, MsScheduleConfig, MsApiReportDialog, MsApiReportStatus, MsApiScenarioConfig
|
||||
},
|
||||
components: {
|
||||
MsMainContainer,
|
||||
MsContainer, ApiImport, MsScheduleConfig, MsApiReportDialog, MsApiReportStatus, MsApiScenarioConfig
|
||||
},
|
||||
|
||||
props: ["id"],
|
||||
props: ["id"],
|
||||
|
||||
data() {
|
||||
return {
|
||||
reportVisible: false,
|
||||
create: false,
|
||||
result: {},
|
||||
projects: [],
|
||||
change: false,
|
||||
test: new Test(),
|
||||
isReadOnly: false,
|
||||
debugReportId: ''
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'$route': 'init',
|
||||
test: {
|
||||
handler: function () {
|
||||
this.change = true;
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
init() {
|
||||
let projectId;
|
||||
|
||||
this.isReadOnly = !checkoutTestManagerOrTestUser();
|
||||
|
||||
if (this.id) {
|
||||
this.create = false;
|
||||
this.getTest(this.id);
|
||||
} else {
|
||||
this.create = true;
|
||||
this.test = new Test();
|
||||
if (this.$refs.config) {
|
||||
this.$refs.config.reset();
|
||||
}
|
||||
// 仅创建时获取选择的项目
|
||||
projectId = this.$store.state.common.projectId;
|
||||
data() {
|
||||
return {
|
||||
reportVisible: false,
|
||||
create: false,
|
||||
result: {},
|
||||
projects: [],
|
||||
change: false,
|
||||
test: new Test(),
|
||||
isReadOnly: false,
|
||||
debugReportId: ''
|
||||
}
|
||||
this.result = this.$get("/project/listAll", response => {
|
||||
this.projects = response.data;
|
||||
// 等待项目列表加载完
|
||||
if (projectId) this.test.projectId = projectId;
|
||||
})
|
||||
},
|
||||
getTest(id) {
|
||||
this.result = this.$get("/api/get/" + id, response => {
|
||||
if (response.data) {
|
||||
let item = response.data;
|
||||
|
||||
this.test = new Test({
|
||||
id: item.id,
|
||||
projectId: item.projectId,
|
||||
name: item.name,
|
||||
status: item.status,
|
||||
scenarioDefinition: JSON.parse(item.scenarioDefinition),
|
||||
schedule: item.schedule ? item.schedule : {},
|
||||
});
|
||||
this.$refs.config.reset();
|
||||
}
|
||||
});
|
||||
},
|
||||
save(callback) {
|
||||
let validator = this.test.isValid();
|
||||
if (!validator.isValid) {
|
||||
this.$warning(this.$t(validator.info));
|
||||
return;
|
||||
watch: {
|
||||
'$route': 'init',
|
||||
test: {
|
||||
handler: function () {
|
||||
this.change = true;
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
this.change = false;
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
let url = this.create ? "/api/create" : "/api/update";
|
||||
let jmx = this.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.result = this.$fileUpload(url, file, bodyFiles, this.test, response => {
|
||||
if (callback) callback();
|
||||
this.create = false;
|
||||
this.resetBodyFile();
|
||||
});
|
||||
},
|
||||
saveTest() {
|
||||
this.save(() => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
if (this.create) {
|
||||
this.$router.push({
|
||||
path: '/api/test/edit?id=' + this.test.id
|
||||
})
|
||||
|
||||
methods: {
|
||||
init() {
|
||||
let projectId;
|
||||
|
||||
this.isReadOnly = !checkoutTestManagerOrTestUser();
|
||||
|
||||
if (this.id) {
|
||||
this.create = false;
|
||||
this.getTest(this.id);
|
||||
} else {
|
||||
this.create = true;
|
||||
this.test = new Test();
|
||||
if (this.$refs.config) {
|
||||
this.$refs.config.reset();
|
||||
}
|
||||
// 仅创建时获取选择的项目
|
||||
projectId = this.$store.state.common.projectId;
|
||||
}
|
||||
// 发送广播,刷新 head 上的最新列表
|
||||
ApiEvent.$emit(LIST_CHANGE);
|
||||
})
|
||||
},
|
||||
runTest() {
|
||||
this.result = this.$post("/api/run", {id: this.test.id, triggerMode: 'MANUAL'}, (response) => {
|
||||
this.$success(this.$t('api_test.running'));
|
||||
this.$router.push({
|
||||
path: '/api/report/view/' + response.data
|
||||
this.result = this.$get("/project/listAll", response => {
|
||||
this.projects = response.data;
|
||||
// 等待项目列表加载完
|
||||
if (projectId) this.test.projectId = projectId;
|
||||
})
|
||||
});
|
||||
},
|
||||
saveRunTest() {
|
||||
this.change = false;
|
||||
if (!this.validateEnableTest()) {
|
||||
this.$warning(this.$t('api_test.enable_validate_tip'));
|
||||
return;
|
||||
}
|
||||
this.save(() => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.runTest();
|
||||
// 发送广播,刷新 head 上的最新列表
|
||||
ApiEvent.$emit(LIST_CHANGE);
|
||||
})
|
||||
},
|
||||
getBodyUploadFiles() {
|
||||
let bodyUploadFiles = [];
|
||||
this.test.bodyUploadIds = [];
|
||||
this.test.scenarioDefinition.forEach(scenario => {
|
||||
scenario.requests.forEach(request => {
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
let fileId = getUUID().substring(0, 8);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
this.test.bodyUploadIds.push(fileId);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
getTest(id) {
|
||||
this.result = this.$get("/api/get/" + id, response => {
|
||||
if (response.data) {
|
||||
let item = response.data;
|
||||
|
||||
this.test = new Test({
|
||||
id: item.id,
|
||||
projectId: item.projectId,
|
||||
name: item.name,
|
||||
status: item.status,
|
||||
scenarioDefinition: JSON.parse(item.scenarioDefinition),
|
||||
schedule: item.schedule ? item.schedule : {},
|
||||
});
|
||||
this.$refs.config.reset();
|
||||
}
|
||||
});
|
||||
});
|
||||
return bodyUploadFiles;
|
||||
},
|
||||
validateEnableTest() {
|
||||
for (let scenario of this.test.scenarioDefinition) {
|
||||
if (scenario.enable) {
|
||||
for (let request of scenario.requests) {
|
||||
if (request.enable) {
|
||||
return true;
|
||||
},
|
||||
save(callback) {
|
||||
let validator = this.test.isValid();
|
||||
if (!validator.isValid) {
|
||||
this.$warning(this.$t(validator.info));
|
||||
return;
|
||||
}
|
||||
this.change = false;
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
let url = this.create ? "/api/create" : "/api/update";
|
||||
let jmx = this.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.result = this.$fileUpload(url, file, bodyFiles, this.test, response => {
|
||||
if (callback) callback();
|
||||
this.create = false;
|
||||
this.resetBodyFile();
|
||||
});
|
||||
},
|
||||
saveTest() {
|
||||
this.save(() => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
if (this.create) {
|
||||
this.$router.push({
|
||||
path: '/api/test/edit?id=' + this.test.id
|
||||
})
|
||||
}
|
||||
// 发送广播,刷新 head 上的最新列表
|
||||
ApiEvent.$emit(LIST_CHANGE);
|
||||
})
|
||||
},
|
||||
runTest() {
|
||||
this.result = this.$post("/api/run", {id: this.test.id, triggerMode: 'MANUAL'}, (response) => {
|
||||
this.$success(this.$t('api_test.running'));
|
||||
this.$router.push({
|
||||
path: '/api/report/view/' + response.data
|
||||
})
|
||||
});
|
||||
},
|
||||
saveRunTest() {
|
||||
this.change = false;
|
||||
if (!this.validateEnableTest()) {
|
||||
this.$warning(this.$t('api_test.enable_validate_tip'));
|
||||
return;
|
||||
}
|
||||
this.save(() => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.runTest();
|
||||
// 发送广播,刷新 head 上的最新列表
|
||||
ApiEvent.$emit(LIST_CHANGE);
|
||||
})
|
||||
},
|
||||
getBodyUploadFiles() {
|
||||
let bodyUploadFiles = [];
|
||||
this.test.bodyUploadIds = [];
|
||||
this.test.scenarioDefinition.forEach(scenario => {
|
||||
scenario.requests.forEach(request => {
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
let fileId = getUUID().substring(0, 8);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
this.test.bodyUploadIds.push(fileId);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return bodyUploadFiles;
|
||||
},
|
||||
validateEnableTest() {
|
||||
for (let scenario of this.test.scenarioDefinition) {
|
||||
if (scenario.enable) {
|
||||
for (let request of scenario.requests) {
|
||||
if (request.enable) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
resetBodyFile() {
|
||||
//下次保存不再上传已传文件
|
||||
this.test.scenarioDefinition.forEach(scenario => {
|
||||
scenario.requests.forEach(request => {
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
item.file = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
this.$router.push('/api/test/list/all');
|
||||
},
|
||||
handleCommand(command) {
|
||||
switch (command) {
|
||||
case "report":
|
||||
this.$refs.reportDialog.open();
|
||||
break;
|
||||
case "performance":
|
||||
this.$store.commit('setTest', {
|
||||
projectId: this.test.projectId,
|
||||
name: this.test.name,
|
||||
jmx: this.test.toJMX()
|
||||
})
|
||||
this.$router.push({
|
||||
path: "/performance/test/create"
|
||||
})
|
||||
break;
|
||||
case "export":
|
||||
downloadFile(this.test.name + ".json", this.test.export());
|
||||
break;
|
||||
case "import":
|
||||
this.$refs.apiImport.open();
|
||||
break;
|
||||
}
|
||||
},
|
||||
saveCronExpression(cronExpression) {
|
||||
this.test.schedule.enable = true;
|
||||
this.test.schedule.value = cronExpression;
|
||||
this.saveSchedule();
|
||||
},
|
||||
saveSchedule() {
|
||||
this.checkScheduleEdit();
|
||||
let param = {};
|
||||
param = this.test.schedule;
|
||||
param.resourceId = this.test.id;
|
||||
let url = '/api/schedule/create';
|
||||
if (param.id) {
|
||||
url = '/api/schedule/update';
|
||||
}
|
||||
this.$post(url, param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.getTest(this.test.id);
|
||||
});
|
||||
},
|
||||
checkScheduleEdit() {
|
||||
if (this.create) {
|
||||
this.$message(this.$t('api_test.environment.please_save_test'));
|
||||
return false;
|
||||
},
|
||||
resetBodyFile() {
|
||||
//下次保存不再上传已传文件
|
||||
this.test.scenarioDefinition.forEach(scenario => {
|
||||
scenario.requests.forEach(request => {
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
item.file = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
this.$router.push('/api/test/list/all');
|
||||
},
|
||||
handleCommand(command) {
|
||||
switch (command) {
|
||||
case "report":
|
||||
this.$refs.reportDialog.open();
|
||||
break;
|
||||
case "performance":
|
||||
this.$store.commit('setTest', {
|
||||
projectId: this.test.projectId,
|
||||
name: this.test.name,
|
||||
jmx: this.test.toJMX()
|
||||
})
|
||||
this.$router.push({
|
||||
path: "/performance/test/create"
|
||||
})
|
||||
break;
|
||||
case "export":
|
||||
downloadFile(this.test.name + ".json", this.test.export());
|
||||
break;
|
||||
case "import":
|
||||
this.$refs.apiImport.open();
|
||||
break;
|
||||
}
|
||||
},
|
||||
saveCronExpression(cronExpression) {
|
||||
this.test.schedule.enable = true;
|
||||
this.test.schedule.value = cronExpression;
|
||||
this.saveSchedule();
|
||||
},
|
||||
saveSchedule() {
|
||||
this.checkScheduleEdit();
|
||||
let param = {};
|
||||
param = this.test.schedule;
|
||||
param.resourceId = this.test.id;
|
||||
let url = '/api/schedule/create';
|
||||
if (param.id) {
|
||||
url = '/api/schedule/update';
|
||||
}
|
||||
this.$post(url, param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.getTest(this.test.id);
|
||||
});
|
||||
},
|
||||
checkScheduleEdit() {
|
||||
if (this.create) {
|
||||
this.$message(this.$t('api_test.environment.please_save_test'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
runDebug(scenario) {
|
||||
if (this.create) {
|
||||
this.$warning(this.$t('api_test.environment.please_save_test'));
|
||||
return;
|
||||
}
|
||||
|
||||
let url = "/api/run/debug";
|
||||
let runningTest = new Test();
|
||||
Object.assign(runningTest, this.test);
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
runningTest.scenarioDefinition = [];
|
||||
runningTest.scenarioDefinition.push(scenario);
|
||||
let validator = runningTest.isValid();
|
||||
if (!validator.isValid) {
|
||||
this.$warning(this.$t(validator.info));
|
||||
return;
|
||||
}
|
||||
|
||||
let jmx = runningTest.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(url, file, bodyFiles, this.test, response => {
|
||||
this.debugReportId = response.data;
|
||||
this.resetBodyFile();
|
||||
});
|
||||
}
|
||||
return true;
|
||||
},
|
||||
runDebug(scenario) {
|
||||
if (this.create) {
|
||||
this.$warning(this.$t('api_test.environment.please_save_test'));
|
||||
return;
|
||||
}
|
||||
|
||||
let url = "/api/run/debug";
|
||||
let runningTest = new Test();
|
||||
Object.assign(runningTest, this.test);
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
runningTest.scenarioDefinition = [];
|
||||
runningTest.scenarioDefinition.push(scenario);
|
||||
let validator = runningTest.isValid();
|
||||
if (!validator.isValid) {
|
||||
this.$warning(this.$t(validator.info));
|
||||
return;
|
||||
}
|
||||
|
||||
let jmx = runningTest.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(url, file, bodyFiles, this.test, response => {
|
||||
this.debugReportId = response.data;
|
||||
this.resetBodyFile();
|
||||
});
|
||||
created() {
|
||||
this.init();
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.test-container {
|
||||
height: calc(100vh - 155px);
|
||||
min-height: 600px;
|
||||
}
|
||||
.test-container {
|
||||
height: calc(100vh - 155px);
|
||||
min-height: 600px;
|
||||
}
|
||||
|
||||
.test-name {
|
||||
width: 600px;
|
||||
margin-left: -20px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
.test-name {
|
||||
width: 600px;
|
||||
margin-left: -20px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.test-project {
|
||||
min-width: 150px;
|
||||
}
|
||||
.test-project {
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.test-container .more {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.test-container .more {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -123,6 +123,9 @@
|
|||
validateDomain(domain) {
|
||||
let url = {};
|
||||
try {
|
||||
if (!domain.startsWith("http") || !domain.startsWith("https")) {
|
||||
domain += "http://";
|
||||
}
|
||||
url = new URL(domain);
|
||||
} catch (e) {
|
||||
this.$warning(this.$t('load_test.input_domain'));
|
||||
|
|
|
@ -504,8 +504,8 @@ export class DNSCacheManager extends DefaultTestElement {
|
|||
let collectionPropHosts = this.collectionProp('DNSCacheManager.hosts');
|
||||
|
||||
hosts.forEach(host => {
|
||||
let elementProp = collectionPropHosts.elementProp('', 'StaticHost');
|
||||
if (host && host.domain.trim() === domain.trim()) {
|
||||
let elementProp = collectionPropHosts.elementProp(host.domain, 'StaticHost');
|
||||
if (host && host.domain.trim().indexOf(domain.trim()) != -1) {
|
||||
elementProp.stringProp('StaticHost.Name', host.domain);
|
||||
elementProp.stringProp('StaticHost.Address', host.ip);
|
||||
}
|
||||
|
|
|
@ -948,8 +948,8 @@ class JMXGenerator {
|
|||
let name = request.name + " DNSCacheManager";
|
||||
let hosts = JSON.parse(request.environment.hosts);
|
||||
if (hosts.length > 0) {
|
||||
let domain = request.environment.protocol + "://" + request.environment.domain;
|
||||
threadGroup.put(new DNSCacheManager(name, domain, hosts));
|
||||
//let domain = request.environment.protocol + "://" + request.environment.domain;
|
||||
threadGroup.put(new DNSCacheManager(name, request.environment.domain, hosts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue