fix(接口测试): 修复 github#10601 认证No Auth导致执行报错问题

--bug=1010304 --user=赵勇 [接口自动化] github#10601接口测试或者自动化测试中,认证设置如果误选了“No Auth”,会导致接口运行报错 https://www.tapd.cn/55049933/s/1104807
This commit is contained in:
fit2-zhao 2022-02-17 10:36:30 +08:00 committed by fit2-zhao
parent cc5bed4e0f
commit 208176bbe5
3 changed files with 22 additions and 22 deletions

View File

@ -57,28 +57,30 @@ public class MsAuthManager extends MsTestElement {
if (!this.isEnable()) {
return;
}
ParameterConfig config = (ParameterConfig) msParameter;
AuthManager authManager = new AuthManager();
authManager.setEnabled(true);
authManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "AuthManager");
authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName());
authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AuthPanel"));
Authorization auth = new Authorization();
if (this.url != null) {
auth.setURL(this.url);
} else {
if (config != null && config.isEffective(this.getProjectId())) {
if (config.isEffective(this.getProjectId())) {
String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
auth.setURL(url);
if (StringUtils.equals(this.getVerification(), "Basic Auth")) {
ParameterConfig config = (ParameterConfig) msParameter;
AuthManager authManager = new AuthManager();
authManager.setEnabled(true);
authManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "AuthManager");
authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName());
authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AuthPanel"));
Authorization auth = new Authorization();
if (this.url != null) {
auth.setURL(this.url);
} else {
if (config != null && config.isEffective(this.getProjectId())) {
if (config.isEffective(this.getProjectId())) {
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) {

View File

@ -224,7 +224,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
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);
}

View File

@ -95,7 +95,6 @@ export default {
if (this.request.hashTree == undefined) {
this.request.hashTree = [];
}
this.request.hashTree.push(authManager);
//
if (this.authConfig.username == undefined && this.authConfig.password == undefined) {
this.authConfig = authManager;
@ -107,7 +106,6 @@ export default {
if (this.request.hashTree == undefined) {
this.request.hashTree = [];
}
this.request.hashTree.push(authManager);
this.authConfig = authManager;
this.request.authManager = this.authConfig;
}