refactor(接口测试): 优化自定义请求路径带变量时的处理逻辑
--bug=1027539 --user=王孝刚 [接口测试] github#25333URL引用的自定义常量,实际请求会被[]包裹,常量格式${ip}:${port} https://www.tapd.cn/55049933/s/1389897
This commit is contained in:
parent
6fa237bd2f
commit
fef406925c
|
@ -427,16 +427,16 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
if (!isCustomizeReqCompleteUrl(this.path) || isRefEnvironment) {
|
if (!isCustomizeReqCompleteUrl(this.path) || isRefEnvironment) {
|
||||||
try {
|
try {
|
||||||
URL urlObject = new URL(url);
|
URL urlObject = new URL(url);
|
||||||
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile();
|
|
||||||
if (StringUtils.isNotBlank(this.getPath())) {
|
if (StringUtils.isNotBlank(this.getPath())) {
|
||||||
envPath += this.getPath();
|
envPath += this.getPath();
|
||||||
}
|
}
|
||||||
if (httpConfig.getDomain().startsWith("${")) {
|
if (httpConfig.getSocket().contains("${")) {
|
||||||
envPath = StringUtils.isNotBlank(this.path) ? StringUtils.join(url, this.path) : url;
|
envPath = StringUtils.isNotBlank(this.path) ? StringUtils.join(url, this.path) : url;
|
||||||
} else if (StringUtils.isNotEmpty(httpConfig.getDomain())) {
|
} else if (StringUtils.isNotEmpty(urlObject.getHost())) {
|
||||||
sampler.setDomain(URLDecoder.decode(httpConfig.getDomain(), StandardCharsets.UTF_8.name()));
|
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile();
|
||||||
|
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name()));
|
||||||
sampler.setProtocol(httpConfig.getProtocol());
|
sampler.setProtocol(httpConfig.getProtocol());
|
||||||
sampler.setPort(httpConfig.getPort());
|
sampler.setPort(urlObject.getPort());
|
||||||
} else {
|
} else {
|
||||||
sampler.setDomain("");
|
sampler.setDomain("");
|
||||||
sampler.setProtocol("");
|
sampler.setProtocol("");
|
||||||
|
@ -451,9 +451,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name()));
|
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name()));
|
||||||
sampler.setProtocol(urlObject.getProtocol());
|
sampler.setProtocol(urlObject.getProtocol());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(envPath) && !envPath.startsWith("/")) {
|
/*if (StringUtils.isNotEmpty(envPath) && !envPath.startsWith("/")) {
|
||||||
envPath = "/" + envPath;
|
envPath = "/" + envPath;
|
||||||
}
|
}*/
|
||||||
sampler.setProperty("HTTPSampler.path", URLDecoder.decode(URLEncoder.encode(envPath, StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name()));
|
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 {
|
try {
|
||||||
URL urlObject = new URL(url);
|
URL urlObject = new URL(url);
|
||||||
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name()));
|
String envPath;
|
||||||
if (urlObject.getPort() > 0 && urlObject.getPort() == 10990 && StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) {
|
if (url.contains("${")){
|
||||||
sampler.setProperty("HTTPSampler.port", this.getPort());
|
envPath = url;
|
||||||
} else if (urlObject.getPort() != -1) {
|
} else {
|
||||||
sampler.setPort(urlObject.getPort());
|
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.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) {
|
} catch (Exception e) {
|
||||||
sampler.setProperty("HTTPSampler.path", url);
|
sampler.setProperty("HTTPSampler.path", url);
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
|
|
@ -20,7 +20,6 @@ public class HttpConfig {
|
||||||
private String socket;
|
private String socket;
|
||||||
private String domain;
|
private String domain;
|
||||||
private String protocol = "https";
|
private String protocol = "https";
|
||||||
private int port;
|
|
||||||
private boolean isMock;
|
private boolean isMock;
|
||||||
private List<HttpConfigCondition> conditions;
|
private List<HttpConfigCondition> conditions;
|
||||||
private List<KeyValue> headers;
|
private List<KeyValue> headers;
|
||||||
|
|
|
@ -173,7 +173,6 @@ export default {
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
domain: "",
|
||||||
port: 0,
|
|
||||||
headers: [new KeyValue()],
|
headers: [new KeyValue()],
|
||||||
headlessEnabled: true,
|
headlessEnabled: true,
|
||||||
browser: 'CHROME'
|
browser: 'CHROME'
|
||||||
|
@ -237,7 +236,6 @@ export default {
|
||||||
clearHisData() {
|
clearHisData() {
|
||||||
this.httpConfig.socket = undefined;
|
this.httpConfig.socket = undefined;
|
||||||
this.httpConfig.protocol = undefined;
|
this.httpConfig.protocol = undefined;
|
||||||
this.httpConfig.port = undefined;
|
|
||||||
this.httpConfig.domain = undefined;
|
this.httpConfig.domain = undefined;
|
||||||
},
|
},
|
||||||
getDetails(row) {
|
getDetails(row) {
|
||||||
|
@ -265,7 +263,6 @@ export default {
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
domain: "",
|
||||||
port: 0,
|
|
||||||
headers: [new KeyValue()]
|
headers: [new KeyValue()]
|
||||||
};
|
};
|
||||||
if (row) {
|
if (row) {
|
||||||
|
@ -340,7 +337,6 @@ export default {
|
||||||
socket: this.condition.socket,
|
socket: this.condition.socket,
|
||||||
headers: this.condition.headers,
|
headers: this.condition.headers,
|
||||||
protocol: this.condition.protocol,
|
protocol: this.condition.protocol,
|
||||||
port: this.condition.port,
|
|
||||||
time: this.condition.time
|
time: this.condition.time
|
||||||
};
|
};
|
||||||
if (obj.type === "PATH") {
|
if (obj.type === "PATH") {
|
||||||
|
@ -403,7 +399,6 @@ export default {
|
||||||
protocol: this.condition.protocol,
|
protocol: this.condition.protocol,
|
||||||
headers: this.condition.headers,
|
headers: this.condition.headers,
|
||||||
domain: this.condition.domain,
|
domain: this.condition.domain,
|
||||||
port: this.condition.port,
|
|
||||||
time: new Date().getTime(),
|
time: new Date().getTime(),
|
||||||
description: this.condition.description
|
description: this.condition.description
|
||||||
};
|
};
|
||||||
|
@ -444,6 +439,7 @@ export default {
|
||||||
},
|
},
|
||||||
validateSocket(socket) {
|
validateSocket(socket) {
|
||||||
if (!socket) return true;
|
if (!socket) return true;
|
||||||
|
this.condition.socket = socket;
|
||||||
let urlStr = this.condition.protocol + "://" + socket;
|
let urlStr = this.condition.protocol + "://" + socket;
|
||||||
let url = {};
|
let url = {};
|
||||||
try {
|
try {
|
||||||
|
@ -457,13 +453,6 @@ export default {
|
||||||
this.condition.domain = split[0];
|
this.condition.domain = split[0];
|
||||||
return true;
|
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;
|
return true;
|
||||||
},
|
},
|
||||||
validate() {
|
validate() {
|
||||||
|
|
|
@ -177,8 +177,6 @@ export default {
|
||||||
details: [new KeyValue({name: "", value: "contains"})],
|
details: [new KeyValue({name: "", value: "contains"})],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
|
||||||
port: 0,
|
|
||||||
headers: [new KeyValue()],
|
headers: [new KeyValue()],
|
||||||
headlessEnabled: true,
|
headlessEnabled: true,
|
||||||
browser: 'CHROME'
|
browser: 'CHROME'
|
||||||
|
@ -206,8 +204,6 @@ export default {
|
||||||
this.condition.type = "NONE";
|
this.condition.type = "NONE";
|
||||||
this.condition.socket = this.httpConfig.socket;
|
this.condition.socket = this.httpConfig.socket;
|
||||||
this.condition.protocol = this.httpConfig.protocol;
|
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.time = new Date().getTime();
|
||||||
this.condition.headers = this.httpConfig.headers;
|
this.condition.headers = this.httpConfig.headers;
|
||||||
this.condition.description = this.httpConfig.description;
|
this.condition.description = this.httpConfig.description;
|
||||||
|
@ -219,8 +215,6 @@ export default {
|
||||||
details: [new KeyValue({name: "", value: "contains"})],
|
details: [new KeyValue({name: "", value: "contains"})],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
|
||||||
port: 0,
|
|
||||||
headers: [new KeyValue()]
|
headers: [new KeyValue()]
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -242,8 +236,6 @@ export default {
|
||||||
clearHisData() {
|
clearHisData() {
|
||||||
this.httpConfig.socket = undefined;
|
this.httpConfig.socket = undefined;
|
||||||
this.httpConfig.protocol = undefined;
|
this.httpConfig.protocol = undefined;
|
||||||
this.httpConfig.port = undefined;
|
|
||||||
this.httpConfig.domain = undefined;
|
|
||||||
},
|
},
|
||||||
getDetails(row) {
|
getDetails(row) {
|
||||||
if (row && row.type === "MODULE") {
|
if (row && row.type === "MODULE") {
|
||||||
|
@ -269,8 +261,6 @@ export default {
|
||||||
details: [new KeyValue({name: "", value: "contains"})],
|
details: [new KeyValue({name: "", value: "contains"})],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
|
||||||
port: 0,
|
|
||||||
headers: [new KeyValue()]
|
headers: [new KeyValue()]
|
||||||
};
|
};
|
||||||
if (row) {
|
if (row) {
|
||||||
|
@ -345,7 +335,6 @@ export default {
|
||||||
socket: this.condition.socket,
|
socket: this.condition.socket,
|
||||||
headers: this.condition.headers,
|
headers: this.condition.headers,
|
||||||
protocol: this.condition.protocol,
|
protocol: this.condition.protocol,
|
||||||
port: this.condition.port,
|
|
||||||
time: this.condition.time
|
time: this.condition.time
|
||||||
};
|
};
|
||||||
if (obj.type === "PATH") {
|
if (obj.type === "PATH") {
|
||||||
|
@ -360,7 +349,6 @@ export default {
|
||||||
details: [new KeyValue({name: "", value: "contains"})],
|
details: [new KeyValue({name: "", value: "contains"})],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
|
||||||
headers: [new KeyValue()]
|
headers: [new KeyValue()]
|
||||||
};
|
};
|
||||||
this.reload();
|
this.reload();
|
||||||
|
@ -373,7 +361,6 @@ export default {
|
||||||
details: [new KeyValue({name: "", value: "contains"})],
|
details: [new KeyValue({name: "", value: "contains"})],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
socket: "",
|
socket: "",
|
||||||
domain: "",
|
|
||||||
headers: [new KeyValue()]
|
headers: [new KeyValue()]
|
||||||
};
|
};
|
||||||
this.$refs.envTable.setCurrentRow(0);
|
this.$refs.envTable.setCurrentRow(0);
|
||||||
|
@ -407,8 +394,6 @@ export default {
|
||||||
socket: this.condition.socket,
|
socket: this.condition.socket,
|
||||||
protocol: this.condition.protocol,
|
protocol: this.condition.protocol,
|
||||||
headers: this.condition.headers,
|
headers: this.condition.headers,
|
||||||
domain: this.condition.domain,
|
|
||||||
port: this.condition.port,
|
|
||||||
time: new Date().getTime(),
|
time: new Date().getTime(),
|
||||||
description: this.condition.description
|
description: this.condition.description
|
||||||
};
|
};
|
||||||
|
@ -438,7 +423,6 @@ export default {
|
||||||
details: row.details,
|
details: row.details,
|
||||||
protocol: row.protocol,
|
protocol: row.protocol,
|
||||||
headers: JSON.parse(JSON.stringify(row.headers)),
|
headers: JSON.parse(JSON.stringify(row.headers)),
|
||||||
domain: row.domain,
|
|
||||||
time: new Date().getTime()
|
time: new Date().getTime()
|
||||||
};
|
};
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
|
@ -448,7 +432,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
validateSocket(socket) {
|
validateSocket(socket) {
|
||||||
if (!socket) return true;
|
this.condition.socket = socket;
|
||||||
let urlStr = this.condition.protocol + "://" + socket;
|
let urlStr = this.condition.protocol + "://" + socket;
|
||||||
let url = {};
|
let url = {};
|
||||||
try {
|
try {
|
||||||
|
@ -462,14 +446,6 @@ export default {
|
||||||
this.condition.domain = split[0];
|
this.condition.domain = split[0];
|
||||||
return true;
|
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() {
|
validate() {
|
||||||
let isValidate = false;
|
let isValidate = false;
|
||||||
|
|
Loading…
Reference in New Issue