From 3d6e72d7fceea791a14b50cf4d401366e0705294 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 28 Mar 2024 11:07:23 +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=E6=97=A0=E6=8A=A5=E5=91=8A=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E4=BB=A5=E7=9C=8B=E5=88=B0=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1037903 --user=王孝刚 【接口测试】无接口报告查新权限-仍展示报告标签-提示无权限 https://www.tapd.cn/55049933/s/1482584 --- .../ResponseHeaderAssertionConverter.java | 27 ++++++++----------- .../ApiScenarioReportControllerTests.java | 2 ++ frontend/src/router/routes/modules/apiTest.ts | 6 ++--- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseHeaderAssertionConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseHeaderAssertionConverter.java index b260308212..3640da3634 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseHeaderAssertionConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseHeaderAssertionConverter.java @@ -1,18 +1,14 @@ package io.metersphere.api.parser.jmeter.processor.assertion; -import io.metersphere.project.api.assertion.MsResponseHeaderAssertion; -import io.metersphere.sdk.util.EnumValidator; import io.metersphere.plugin.api.dto.ParameterConfig; +import io.metersphere.project.api.assertion.MsResponseHeaderAssertion; import io.metersphere.sdk.constants.MsAssertionCondition; +import io.metersphere.sdk.util.EnumValidator; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.assertions.ResponseAssertion; import org.apache.jorphan.collections.HashTree; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - /** * @Author: jianxing * @CreateTime: 2023-12-27 21:01 @@ -53,16 +49,15 @@ public class ResponseHeaderAssertionConverter extends AssertionConverter> regexgenerateMap = new HashMap<>(); - regexgenerateMap.put(MsAssertionCondition.EQUALS, value -> StringUtils.join("\\b", msAssertion.getHeader(),": ",value, "\\b")); - regexgenerateMap.put(MsAssertionCondition.NOT_EQUALS, value -> StringUtils.join("\\b", msAssertion.getHeader(),": (?!", value,"\\b)\\d+")); - regexgenerateMap.put(MsAssertionCondition.CONTAINS, value -> StringUtils.join("\\b", msAssertion.getHeader(),": .*", value, ".*\\b")); - regexgenerateMap.put(MsAssertionCondition.NOT_CONTAINS, value -> StringUtils.join("\\b", msAssertion.getHeader(),": (?!.*", value, ").*\\b")); - if (msAssertionCondition != null && regexgenerateMap.get(msAssertionCondition) != null) { - assertion.addTestString(regexgenerateMap.get(msAssertionCondition).apply(expectedValue)); - } else { - assertion.addTestString(expectedValue); - } + String header = msAssertion.getHeader(); + String testString = switch (msAssertionCondition) { + case CONTAINS -> StringUtils.join("\\b", msAssertion.getHeader(),": .*", expectedValue, ".*\\b"); + case NOT_CONTAINS -> StringUtils.join("\\b", msAssertion.getHeader(),": (?!.*", expectedValue, ").*\\b"); + case EQUALS -> StringUtils.join("\\b", header,": ",expectedValue, "\\b"); + case NOT_EQUALS -> StringUtils.join("\\b", msAssertion.getHeader(),": (?!", expectedValue,"\\b)\\d+"); + default -> expectedValue; + }; + assertion.addTestString(testString); assertion.setToContainsType(); assertion.setTestFieldResponseHeaders(); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java index a981bf3219..31030a9e9c 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java @@ -297,6 +297,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { apiReportDetail.setId("test-report-detail-id" + i + 2); apiReportDetail.setReportId("test-scenario-report-id"); apiReportDetail.setStepId("test-scenario-report-step-id" + i); + apiReportDetail.setSort((long) i); if (i % 2 == 0) { apiReportDetail.setStatus(ApiReportStatus.SUCCESS.name()); apiReportDetail.setResponseSize(1L); @@ -381,6 +382,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { apiReportDetail.setStatus("success"); apiReportDetail.setResponseSize(0L); apiReportDetail.setRequestTime((long) i); + apiReportDetail.setSort((long) i); apiReportDetail.setContent("{\"resourceId\":\"\",\"stepId\":null,\"threadName\":\"Thread Group\",\"name\":\"HTTP Request1\",\"url\":\"https://www.baidu.com/\",\"requestSize\":195,\"startTime\":1705570589125,\"endTime\":1705570589310,\"error\":1,\"headers\":\"Connection: keep-alive\\nContent-Length: 0\\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\\nHost: www.baidu.com\\nUser-Agent: Apache-HttpClient/4.5.14 (Java/21)\\n\",\"cookies\":\"\",\"body\":\"POST https://www.baidu.com/\\n\\nPOST data:\\n\\n\\n[no cookies]\\n\",\"status\":\"ERROR\",\"method\":\"POST\",\"assertionTotal\":1,\"passAssertionsTotal\":0,\"subRequestResults\":[],\"responseResult\":{\"responseCode\":\"200\",\"responseMessage\":\"OK\",\"responseTime\":185,\"latency\":180,\"responseSize\":2559,\"headers\":\"HTTP/1.1 200 OK\\nContent-Length: 2443\\nContent-Type: text/html\\nServer: bfe\\nDate: Thu, 18 Jan 2024 09:36:29 GMT\\n\",\"body\":\"\\r\\n 百度一下,你就知道

关于百度 About Baidu

©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号 

\\r\\n\",\"contentType\":\"text/html\",\"vars\":null,\"imageUrl\":null,\"socketInitTime\":14,\"dnsLookupTime\":0,\"tcpHandshakeTime\":0,\"sslHandshakeTime\":0,\"transferStartTime\":166,\"downloadTime\":5,\"bodySize\":2443,\"headerSize\":116,\"assertions\":[{\"name\":\"JSON Assertion\",\"content\":null,\"script\":null,\"message\":\"Expected to find an object with property ['test'] in path $ but found 'java.lang.String'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.\",\"pass\":false}]},\"isSuccessful\":false,\"fakeErrorMessage\":\"\",\"fakeErrorCode\":null}\n".getBytes()); reports.add(apiReportDetail); } diff --git a/frontend/src/router/routes/modules/apiTest.ts b/frontend/src/router/routes/modules/apiTest.ts index 3e825eb283..6962295711 100644 --- a/frontend/src/router/routes/modules/apiTest.ts +++ b/frontend/src/router/routes/modules/apiTest.ts @@ -50,7 +50,7 @@ const ApiTest: AppRouteRecordRaw = { component: () => import('@/views/api-test/management/recycle.vue'), meta: { locale: 'common.recycle', - roles: ['FUNCTIONAL_CASE:READ'], + roles: ['PROJECT_API_DEFINITION:READ'], breadcrumbs: [ { name: ApiTestRouteEnum.API_TEST_MANAGEMENT, @@ -81,7 +81,7 @@ const ApiTest: AppRouteRecordRaw = { component: () => import('@/views/api-test/scenario/recycle.vue'), meta: { locale: 'menu.apiTest.scenario', - roles: ['*'], + roles: ['PROJECT_API_SCENARIO:READ'], isTopMenu: false, breadcrumbs: [ { @@ -102,7 +102,7 @@ const ApiTest: AppRouteRecordRaw = { component: () => import('@/views/api-test/report/index.vue'), meta: { locale: 'menu.apiTest.report', - roles: ['*'], + roles: ['PROJECT_API_REPORT:READ'], isTopMenu: true, }, },