fix(接口测试): 修复 github#10601 认证No Auth导致执行报错问题
--bug=1010304 --user=赵勇 [接口自动化] github#10601接口测试或者自动化测试中,认证设置如果误选了“No Auth”,会导致接口运行报错 https://www.tapd.cn/55049933/s/1104807
This commit is contained in:
parent
3d9d9dffe8
commit
3009e27a1a
|
@ -57,28 +57,30 @@ public class MsAuthManager extends MsTestElement {
|
||||||
if (!this.isEnable()) {
|
if (!this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ParameterConfig config = (ParameterConfig) msParameter;
|
if (StringUtils.equals(this.getVerification(), "Basic Auth")) {
|
||||||
AuthManager authManager = new AuthManager();
|
ParameterConfig config = (ParameterConfig) msParameter;
|
||||||
authManager.setEnabled(true);
|
AuthManager authManager = new AuthManager();
|
||||||
authManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "AuthManager");
|
authManager.setEnabled(true);
|
||||||
authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName());
|
authManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "AuthManager");
|
||||||
authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AuthPanel"));
|
authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName());
|
||||||
Authorization auth = new Authorization();
|
authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AuthPanel"));
|
||||||
if (this.url != null) {
|
Authorization auth = new Authorization();
|
||||||
auth.setURL(this.url);
|
if (this.url != null) {
|
||||||
} else {
|
auth.setURL(this.url);
|
||||||
if (config != null && config.isEffective(this.getProjectId())) {
|
} else {
|
||||||
if (config.isEffective(this.getProjectId())) {
|
if (config != null && config.isEffective(this.getProjectId())) {
|
||||||
String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
|
if (config.isEffective(this.getProjectId())) {
|
||||||
auth.setURL(url);
|
String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
|
||||||
|
auth.setURL(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auth.setUser(this.username);
|
||||||
|
auth.setPass(this.password);
|
||||||
|
auth.setMechanism(AuthManager.Mechanism.DIGEST);
|
||||||
|
authManager.addAuth(auth);
|
||||||
|
tree.add(authManager);
|
||||||
}
|
}
|
||||||
auth.setUser(this.username);
|
|
||||||
auth.setPass(this.password);
|
|
||||||
auth.setMechanism(AuthManager.Mechanism.DIGEST);
|
|
||||||
authManager.addAuth(auth);
|
|
||||||
tree.add(authManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuth(HashTree tree, MsAuthManager msAuthManager, HTTPSamplerProxy samplerProxy) {
|
public void setAuth(HashTree tree, MsAuthManager msAuthManager, HTTPSamplerProxy samplerProxy) {
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()), httpConfig);
|
MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()), httpConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.authManager != null) {
|
if (this.authManager != null && StringUtils.equals(this.authManager.getVerification(), "Basic Auth")) {
|
||||||
this.authManager.setAuth(httpSamplerTree, this.authManager, sampler);
|
this.authManager.setAuth(httpSamplerTree, this.authManager, sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,6 @@ export default {
|
||||||
if (this.request.hashTree == undefined) {
|
if (this.request.hashTree == undefined) {
|
||||||
this.request.hashTree = [];
|
this.request.hashTree = [];
|
||||||
}
|
}
|
||||||
this.request.hashTree.push(authManager);
|
|
||||||
// 这里做个判断,如果原来有值则不覆盖
|
// 这里做个判断,如果原来有值则不覆盖
|
||||||
if (this.authConfig.username == undefined && this.authConfig.password == undefined) {
|
if (this.authConfig.username == undefined && this.authConfig.password == undefined) {
|
||||||
this.authConfig = authManager;
|
this.authConfig = authManager;
|
||||||
|
@ -107,7 +106,6 @@ export default {
|
||||||
if (this.request.hashTree == undefined) {
|
if (this.request.hashTree == undefined) {
|
||||||
this.request.hashTree = [];
|
this.request.hashTree = [];
|
||||||
}
|
}
|
||||||
this.request.hashTree.push(authManager);
|
|
||||||
this.authConfig = authManager;
|
this.authConfig = authManager;
|
||||||
this.request.authManager = this.authConfig;
|
this.request.authManager = this.authConfig;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue