From fef406925cdfa198f3de188878ad12b4f9d3c4b5 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 5 Jul 2023 17:20:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=B7=AF=E5=BE=84=E5=B8=A6=E5=8F=98=E9=87=8F=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1027539 --user=王孝刚 [接口测试] github#25333URL引用的自定义常量,实际请求会被[]包裹,常量格式${ip}:${port} https://www.tapd.cn/55049933/s/1389897 --- .../request/sampler/MsHTTPSamplerProxy.java | 33 +++++++++++-------- .../api/dto/scenario/HttpConfig.java | 1 - .../environment/EnvironmentHttpConfig.vue | 13 +------- .../components/EnvironmentHttpConfig.vue | 26 +-------------- 4 files changed, 22 insertions(+), 51 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index f001596631..2b63e3c70b 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -427,16 +427,16 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (!isCustomizeReqCompleteUrl(this.path) || isRefEnvironment) { try { URL urlObject = new URL(url); - envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile(); if (StringUtils.isNotBlank(this.getPath())) { envPath += this.getPath(); } - if (httpConfig.getDomain().startsWith("${")) { + if (httpConfig.getSocket().contains("${")) { envPath = StringUtils.isNotBlank(this.path) ? StringUtils.join(url, this.path) : url; - } else if (StringUtils.isNotEmpty(httpConfig.getDomain())) { - sampler.setDomain(URLDecoder.decode(httpConfig.getDomain(), StandardCharsets.UTF_8.name())); + } else if (StringUtils.isNotEmpty(urlObject.getHost())) { + envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile(); + sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); sampler.setProtocol(httpConfig.getProtocol()); - sampler.setPort(httpConfig.getPort()); + sampler.setPort(urlObject.getPort()); } else { sampler.setDomain(""); sampler.setProtocol(""); @@ -451,9 +451,9 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); sampler.setProtocol(urlObject.getProtocol()); } - if (StringUtils.isNotEmpty(envPath) && !envPath.startsWith("/")) { + /*if (StringUtils.isNotEmpty(envPath) && !envPath.startsWith("/")) { envPath = "/" + envPath; - } + }*/ sampler.setProperty("HTTPSampler.path", URLDecoder.decode(URLEncoder.encode(envPath, StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name())); } } @@ -468,14 +468,21 @@ public class MsHTTPSamplerProxy extends MsTestElement { } try { URL urlObject = new URL(url); - sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); - if (urlObject.getPort() > 0 && urlObject.getPort() == 10990 && StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) { - sampler.setProperty("HTTPSampler.port", this.getPort()); - } else if (urlObject.getPort() != -1) { - sampler.setPort(urlObject.getPort()); + String envPath; + if (url.contains("${")){ + envPath = url; + } else { + sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); + if (urlObject.getPort() > 0 && urlObject.getPort() == 10990 && StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) { + sampler.setProperty("HTTPSampler.port", this.getPort()); + } else if (urlObject.getPort() != -1) { + sampler.setPort(urlObject.getPort()); + } + envPath = urlObject.getPath(); } + sampler.setProtocol(urlObject.getProtocol()); - sampler.setProperty("HTTPSampler.path", URLDecoder.decode(urlObject.getPath(), StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name()); + sampler.setProperty("HTTPSampler.path", URLDecoder.decode(envPath, StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name()); } catch (Exception e) { sampler.setProperty("HTTPSampler.path", url); LogUtil.error(e.getMessage(), e); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java index 34b5cbe4c9..8a18a1c381 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java @@ -20,7 +20,6 @@ public class HttpConfig { private String socket; private String domain; private String protocol = "https"; - private int port; private boolean isMock; private List conditions; private List headers; diff --git a/framework/sdk-parent/frontend/src/components/environment/EnvironmentHttpConfig.vue b/framework/sdk-parent/frontend/src/components/environment/EnvironmentHttpConfig.vue index edc6889333..4760330207 100644 --- a/framework/sdk-parent/frontend/src/components/environment/EnvironmentHttpConfig.vue +++ b/framework/sdk-parent/frontend/src/components/environment/EnvironmentHttpConfig.vue @@ -173,7 +173,6 @@ export default { protocol: "http", socket: "", domain: "", - port: 0, headers: [new KeyValue()], headlessEnabled: true, browser: 'CHROME' @@ -237,7 +236,6 @@ export default { clearHisData() { this.httpConfig.socket = undefined; this.httpConfig.protocol = undefined; - this.httpConfig.port = undefined; this.httpConfig.domain = undefined; }, getDetails(row) { @@ -265,7 +263,6 @@ export default { protocol: "http", socket: "", domain: "", - port: 0, headers: [new KeyValue()] }; if (row) { @@ -340,7 +337,6 @@ export default { socket: this.condition.socket, headers: this.condition.headers, protocol: this.condition.protocol, - port: this.condition.port, time: this.condition.time }; if (obj.type === "PATH") { @@ -403,7 +399,6 @@ export default { protocol: this.condition.protocol, headers: this.condition.headers, domain: this.condition.domain, - port: this.condition.port, time: new Date().getTime(), description: this.condition.description }; @@ -444,6 +439,7 @@ export default { }, validateSocket(socket) { if (!socket) return true; + this.condition.socket = socket; let urlStr = this.condition.protocol + "://" + socket; let url = {}; try { @@ -457,13 +453,6 @@ export default { this.condition.domain = split[0]; return true; } - this.condition.port = url.port; - let path = url.pathname === "/" ? "" : url.pathname; - if (url.port) { - this.condition.socket = this.condition.domain + ":" + url.port + path; - } else { - this.condition.socket = this.condition.domain + path; - } return true; }, validate() { diff --git a/project-management/frontend/src/business/menu/environment/components/EnvironmentHttpConfig.vue b/project-management/frontend/src/business/menu/environment/components/EnvironmentHttpConfig.vue index 0298c08255..10dc485a22 100644 --- a/project-management/frontend/src/business/menu/environment/components/EnvironmentHttpConfig.vue +++ b/project-management/frontend/src/business/menu/environment/components/EnvironmentHttpConfig.vue @@ -177,8 +177,6 @@ export default { details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", - domain: "", - port: 0, headers: [new KeyValue()], headlessEnabled: true, browser: 'CHROME' @@ -206,8 +204,6 @@ export default { this.condition.type = "NONE"; this.condition.socket = this.httpConfig.socket; this.condition.protocol = this.httpConfig.protocol; - this.condition.port = this.httpConfig.port; - this.condition.domain = this.httpConfig.domain; this.condition.time = new Date().getTime(); this.condition.headers = this.httpConfig.headers; this.condition.description = this.httpConfig.description; @@ -219,8 +215,6 @@ export default { details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", - domain: "", - port: 0, headers: [new KeyValue()] }; }, @@ -242,8 +236,6 @@ export default { clearHisData() { this.httpConfig.socket = undefined; this.httpConfig.protocol = undefined; - this.httpConfig.port = undefined; - this.httpConfig.domain = undefined; }, getDetails(row) { if (row && row.type === "MODULE") { @@ -269,8 +261,6 @@ export default { details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", - domain: "", - port: 0, headers: [new KeyValue()] }; if (row) { @@ -345,7 +335,6 @@ export default { socket: this.condition.socket, headers: this.condition.headers, protocol: this.condition.protocol, - port: this.condition.port, time: this.condition.time }; if (obj.type === "PATH") { @@ -360,7 +349,6 @@ export default { details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", - domain: "", headers: [new KeyValue()] }; this.reload(); @@ -373,7 +361,6 @@ export default { details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", - domain: "", headers: [new KeyValue()] }; this.$refs.envTable.setCurrentRow(0); @@ -407,8 +394,6 @@ export default { socket: this.condition.socket, protocol: this.condition.protocol, headers: this.condition.headers, - domain: this.condition.domain, - port: this.condition.port, time: new Date().getTime(), description: this.condition.description }; @@ -438,7 +423,6 @@ export default { details: row.details, protocol: row.protocol, headers: JSON.parse(JSON.stringify(row.headers)), - domain: row.domain, time: new Date().getTime() }; if (index != -1) { @@ -448,7 +432,7 @@ export default { } }, validateSocket(socket) { - if (!socket) return true; + this.condition.socket = socket; let urlStr = this.condition.protocol + "://" + socket; let url = {}; try { @@ -462,14 +446,6 @@ export default { this.condition.domain = split[0]; return true; } - this.condition.port = url.port; - let path = url.pathname === "/" ? "" : url.pathname; - if (url.port) { - this.condition.socket = this.condition.domain + ":" + url.port + path; - } else { - this.condition.socket = this.condition.domain + path; - } - return true; }, validate() { let isValidate = false;