fix(接口测试): 修复无报告权限的可以看到报告按钮的缺陷
--bug=1037903 --user=王孝刚 【接口测试】无接口报告查新权限-仍展示报告标签-提示无权限 https://www.tapd.cn/55049933/s/1482584
This commit is contained in:
parent
b9b122b4cc
commit
3d6e72d7fc
|
@ -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<MsRespo
|
|||
String condition = msAssertion.getCondition();
|
||||
assertion.setName(String.format("Response header %s %s", condition.toLowerCase().replace("_", ""), expectedValue));
|
||||
MsAssertionCondition msAssertionCondition = EnumValidator.validateEnum(MsAssertionCondition.class, condition);
|
||||
Map<MsAssertionCondition, Function<String, String>> 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();
|
||||
|
|
|
@ -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\":\"<!DOCTYPE html>\\r\\n<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class=\\\"bg s_ipt_wr\\\"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus=autofocus></span><span class=\\\"bg s_btn_wr\\\"><input type=submit id=su value=百度一下 class=\\\"bg s_btn\\\" autofocus></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=https://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href=\\\"http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === \\\"\\\" ? \\\"?\\\" : \\\"&\\\")+ \\\"bdorz_come=1\\\")+ '\\\" name=\\\"tj_login\\\" class=\\\"lb\\\">登录</a>');\\r\\n </script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style=\\\"display: block;\\\">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>\\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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue