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 3d9d9dffe8
commit 3009e27a1a
3 changed files with 22 additions and 22 deletions

View File

@ -57,6 +57,7 @@ public class MsAuthManager extends MsTestElement {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
} }
if (StringUtils.equals(this.getVerification(), "Basic Auth")) {
ParameterConfig config = (ParameterConfig) msParameter; ParameterConfig config = (ParameterConfig) msParameter;
AuthManager authManager = new AuthManager(); AuthManager authManager = new AuthManager();
authManager.setEnabled(true); authManager.setEnabled(true);
@ -80,6 +81,7 @@ public class MsAuthManager extends MsTestElement {
authManager.addAuth(auth); authManager.addAuth(auth);
tree.add(authManager); tree.add(authManager);
} }
}
public void setAuth(HashTree tree, MsAuthManager msAuthManager, HTTPSamplerProxy samplerProxy) { public void setAuth(HashTree tree, MsAuthManager msAuthManager, HTTPSamplerProxy samplerProxy) {
try { try {

View File

@ -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);
} }

View File

@ -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;
} }