fix(接口调试): 修复host不匹配时开启DnsCache缺陷

This commit is contained in:
fit2-zhao 2020-09-17 11:01:08 +08:00
parent c0a9dc003d
commit 4d983fd071
3 changed files with 24 additions and 10 deletions

View File

@ -76,6 +76,7 @@ public class XmindToTestCaseParser {
return jsonArray.toJSONString(); return jsonArray.toJSONString();
} }
// 初始化一个用例
private void newTestCase(String title, String nodePath, List<Attached> attacheds) { private void newTestCase(String title, String nodePath, List<Attached> attacheds) {
TestCaseWithBLOBs testCase = new TestCaseWithBLOBs(); TestCaseWithBLOBs testCase = new TestCaseWithBLOBs();
testCase.setProjectId(projectId); testCase.setProjectId(projectId);
@ -88,6 +89,7 @@ public class XmindToTestCaseParser {
String tcArr[] = tc.split(":"); String tcArr[] = tc.split(":");
if (tcArr.length != 2) { if (tcArr.length != 2) {
process.append(Translator.get("test_case_name") + "" + title + "" + Translator.get("incorrect_format")); process.append(Translator.get("test_case_name") + "" + title + "" + Translator.get("incorrect_format"));
return;
} }
// 用例名称 // 用例名称
testCase.setName(tcArr[1].replace("tc:|tc", "")); testCase.setName(tcArr[1].replace("tc:|tc", ""));

View File

@ -530,17 +530,15 @@ export class HeaderManager extends DefaultTestElement {
} }
export class DNSCacheManager extends DefaultTestElement { export class DNSCacheManager extends DefaultTestElement {
constructor(testName, domain, hosts) { constructor(testName, hosts) {
super('DNSCacheManager', 'DNSCachePanel', 'DNSCacheManager', testName); super('DNSCacheManager', 'DNSCachePanel', 'DNSCacheManager', testName);
let collectionPropServers = this.collectionProp('DNSCacheManager.servers'); let collectionPropServers = this.collectionProp('DNSCacheManager.servers');
let collectionPropHosts = this.collectionProp('DNSCacheManager.hosts'); let collectionPropHosts = this.collectionProp('DNSCacheManager.hosts');
hosts.forEach(host => { hosts.forEach(host => {
let elementProp = collectionPropHosts.elementProp(host.domain, 'StaticHost'); 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.Name', host.domain); elementProp.stringProp('StaticHost.Address', host.ip);
elementProp.stringProp('StaticHost.Address', host.ip);
}
}); });
let boolProp = this.boolProp('DNSCacheManager.isCustomResolver', true); let boolProp = this.boolProp('DNSCacheManager.isCustomResolver', true);

View File

@ -214,7 +214,12 @@ export class Scenario extends BaseConfig {
this.databaseConfigs = []; this.databaseConfigs = [];
this.set(options); this.set(options);
this.sets({variables: KeyValue, headers: KeyValue, requests: RequestFactory, databaseConfigs: DatabaseConfig}, options); this.sets({
variables: KeyValue,
headers: KeyValue,
requests: RequestFactory,
databaseConfigs: DatabaseConfig
}, options);
} }
initOptions(options = {}) { initOptions(options = {}) {
@ -1046,11 +1051,20 @@ class JMXGenerator {
if (request.environment) { if (request.environment) {
let commonConfig = request.environment.config.commonConfig; let commonConfig = request.environment.config.commonConfig;
let hosts = commonConfig.hosts; let hosts = commonConfig.hosts;
if (commonConfig.enableHost) { if (commonConfig.enableHost && hosts.length > 0) {
let name = request.name + " DNSCacheManager"; let name = request.name + " DNSCacheManager";
if (hosts.length > 0) { // 强化判断如果未匹配到合适的host则不开启DNSCache
//let domain = request.environment.protocol + "://" + request.environment.domain; let domain = request.environment.config.httpConfig.domain;
threadGroup.put(new DNSCacheManager(name, request.environment.config.httpConfig.domain, hosts)); let validHosts = [];
hosts.forEach(item => {
let d = item.domain.trim().replace("http://", "").replace("https://", "");
if (item && d === domain.trim()) {
item.domain = d; // 域名去掉协议
validHosts.push(item);
}
});
if (validHosts.length > 0) {
threadGroup.put(new DNSCacheManager(name, validHosts));
} }
} }
} }