From 208176bbe519622889c043d3e81b8da13d2685da Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 17 Feb 2022 10:36:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20github#10601=20=E8=AE=A4=E8=AF=81No=20Auth?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=89=A7=E8=A1=8C=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1010304 --user=赵勇 [接口自动化] github#10601接口测试或者自动化测试中,认证设置如果误选了“No Auth”,会导致接口运行报错 https://www.tapd.cn/55049933/s/1104807 --- .../request/auth/MsAuthManager.java | 40 ++++++++++--------- .../request/sampler/MsHTTPSamplerProxy.java | 2 +- .../components/auth/ApiAuthConfig.vue | 2 - 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java index 5dff92897c..ec48eba466 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java @@ -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) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 734ed95ffd..5ffb469dca 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -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); } diff --git a/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue b/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue index 7af690f545..e18bf79339 100644 --- a/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue +++ b/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue @@ -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; }