From 41bf5c6b1560f1423f78f8a5e9ded5caf3810316 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 23 Mar 2021 10:24:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E9=99=84=E4=BB=B6=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/commons/utils/ShiroUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java index 7d2a0901a6..24cd86fc6d 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java @@ -52,6 +52,7 @@ public class ShiroUtils { filterChainDefinitionMap.put("/", "apikey, authc"); // 跳转到 / 不用校验 csrf filterChainDefinitionMap.put("/language", "apikey, authc");// 跳转到 /language 不用校验 csrf filterChainDefinitionMap.put("/document", "apikey, authc"); // 跳转到 /document 不用校验 csrf + filterChainDefinitionMap.put("/test/case/file/preview/**", "apikey, authc"); // 预览测试用例附件 不用校验 csrf } public static Cookie getSessionIdCookie(){ From 6351bd9f269f2e2bab64153e048014ccce2b8c92 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 23 Mar 2021 10:56:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/track/request/testcase/TrackCount.java | 2 +- .../java/io/metersphere/track/response/TrackStatisticsDTO.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/TrackCount.java b/backend/src/main/java/io/metersphere/track/request/testcase/TrackCount.java index b795deb9da..6cd0dd3002 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/TrackCount.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/TrackCount.java @@ -6,7 +6,7 @@ public class TrackCount { public static final String P2 = "P2"; public static final String P3 = "P3"; - public static final String API = "api"; + public static final String TESTCASE = "testcase"; public static final String PERFORMANCE = "performance"; public static final String AUTOMATION = "automation"; } diff --git a/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java b/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java index 264e0cf9cb..4749cf47e2 100644 --- a/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java +++ b/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java @@ -145,7 +145,7 @@ public class TrackStatisticsDTO { public void countRelevance(List relevanceResults) { for (TrackCountResult countResult : relevanceResults) { switch (countResult.getGroupField()){ - case TrackCount.API: + case TrackCount.TESTCASE: this.apiCaseCount += countResult.getCountNumber(); this.allRelevanceCaseCount += countResult.getCountNumber(); break; From 113c689f173792f0240d29cc3be1ca7fcf02656b Mon Sep 17 00:00:00 2001 From: BugKing Date: Tue, 23 Mar 2021 11:09:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E8=A7=84=E8=8C=83=E9=83=A8=E5=88=86=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/i18n/en-US.js | 4 ++-- frontend/src/i18n/zh-CN.js | 4 ++-- frontend/src/i18n/zh-TW.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 502c42e06a..4ac574b7af 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -945,9 +945,9 @@ export default { export_tip: "Export Tip", ms_tip: "Support for MeterSphere JSON format", ms_export_tip: "Export jSON-formatted files via MeterSphere website or browser plug-ins", - har_export_tip: "Export Har files by browser dev-tool", + har_export_tip: "Export HAR files by browser dev-tool", swagger_tip: "Swagger 2.0 and 3.0 json files are supported", - har_tip: "Only Har files are supported", + har_tip: "Only HAR files are supported", postman_tip: "Only Postman Collection V2.1 json files are supported", postman_export_tip: "Export the test collection by Postman", swagger_export_tip: "Export jSON-formatted files via Swagger website", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 684f4abf22..93d1c867ba 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -948,10 +948,10 @@ export default { export_tip: "导出方法", ms_tip: "支持 MeterSphere json 格式", ms_export_tip: "通过 MeterSphere 接口测试页面或者浏览器插件导出 json 格式文件", - har_export_tip: "通过 浏览器的开发者工具 导出 Har 格式文件", + har_export_tip: "通过 浏览器的开发者工具 导出 HAR 格式文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", swagger_tip: "支持 Swagger 2.0 与 3.0 版本的 json 文件", - har_tip: "只支持 Har 文件", + har_tip: "只支持 HAR 文件", post_export_tip: "通过 Postman 导出测试集合", swagger_export_tip: "通过 Swagger 页面导出", jmeter_export_tip: "通过 JMeter 生成JMX文件", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 54185a8feb..bb0d61b714 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -947,10 +947,10 @@ export default { export_tip: "導出方法", ms_tip: "支持 MeterSphere json 格式", ms_export_tip: "通過 MeterSphere 接口測試頁面或者瀏覽器插件導出 json 格式文件", - har_export_tip: "通过 瀏覽器到開發者工具 导出 Har 格式文件", + har_export_tip: "通过 瀏覽器到開發者工具 导出 HAR 格式文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", swagger_tip: "支持 Swagger 2.0 與 3.0 版本的 json 文件", - har_tip: "只支持 Har 文件", + har_tip: "只支持 HAR 文件", post_export_tip: "通過 Postman 導出測試集合", swagger_export_tip: "通過 Swagger 頁面導出", jmeter_export_tip: "通過 JMeter 生成JMX文件", From 5b87b340715d5b7735afbd5a691c11af2882bf68 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 23 Mar 2021 11:11:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E8=A7=A3=E5=86=B3while=E5=BE=AA=E7=8E=AF=20?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E5=BD=B1=E5=93=8D=E5=90=8E?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=AF=B7=E6=B1=82=E4=B8=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/controller/MsLoopController.java | 47 +++++++++++++++++-- .../definition/request/extract/MsExtract.java | 6 +-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java index b1d038c51f..30543eeb31 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java @@ -17,6 +17,8 @@ import org.apache.jmeter.control.LoopController; import org.apache.jmeter.control.RunTime; import org.apache.jmeter.control.WhileController; import org.apache.jmeter.modifiers.CounterConfig; +import org.apache.jmeter.modifiers.JSR223PreProcessor; +import org.apache.jmeter.protocol.java.sampler.JSR223Sampler; import org.apache.jmeter.reporters.ResultAction; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; @@ -24,6 +26,7 @@ import org.apache.jmeter.timers.ConstantTimer; import org.apache.jorphan.collections.HashTree; import java.util.List; +import java.util.UUID; @Data @EqualsAndHashCode(callSuper = true) @@ -42,6 +45,9 @@ public class MsLoopController extends MsTestElement { @JSONField(ordinal = 23) private MsWhileController whileController; + + private String ms_current_timer = UUID.randomUUID().toString(); + @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { // 非导出操作,且不是启用状态则跳过执行 @@ -122,7 +128,8 @@ public class MsLoopController extends MsTestElement { operator = ""; value = ""; } - return "${__jexl3(" + variable + operator + value + ")}"; + ms_current_timer = UUID.randomUUID().toString(); + return "${__jexl3(" + variable + operator + value + " && \"${" + ms_current_timer + "}\" !=\"stop\")}"; } private WhileController initWhileController() { @@ -151,6 +158,32 @@ public class MsLoopController extends MsTestElement { return controller; } + private String script() { + String script = "\n" + + "import java.util.*;\n" + + "import java.text.SimpleDateFormat;\n" + + "import org.apache.jmeter.threads.JMeterContextService;\n" + + "\n" + + "// 循环控制器超时后结束循环\n" + + "try{\n" + + "\tString ms_current_timer = vars.get(\"" + ms_current_timer + "\");\n" + + "\tlong _nowTime = System.currentTimeMillis(); \n" + + "\tif(ms_current_timer == null ){\n" + + "\t\tvars.put(\"" + ms_current_timer + "\",_nowTime.toString());\n" + + "\t}\n" + + "\tlong time = Long.parseLong(vars.get(\"" + ms_current_timer + "\"));\n" + + "\t if((_nowTime - time) > " + this.whileController.getTimeout() + " ){\n" + + "\t \tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + + "\t \tlog.info( \"结束循环\");\n" + + "\t }\n" + + "}catch (Exception e){\n" + + "\tlog.info( e.getMessage());\n" + + "\tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + + "}\n"; + + return script; + } + private HashTree controller(HashTree tree) { if (StringUtils.equals(this.loopType, LoopConstants.WHILE.name()) && this.whileController != null) { RunTime runTime = new RunTime(); @@ -162,9 +195,17 @@ public class MsLoopController extends MsTestElement { timeout = 1; } runTime.setRuntime(timeout); + HashTree hashTree = tree.add(initWhileController()); // 添加超时处理,防止死循环 - HashTree hashTree = tree.add(runTime); - return hashTree.add(initWhileController()); + JSR223PreProcessor jsr223PreProcessor = new JSR223PreProcessor(); + jsr223PreProcessor.setName("循环超时处理"); + jsr223PreProcessor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName()); + jsr223PreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); + jsr223PreProcessor.setProperty("cacheKey", "true"); + jsr223PreProcessor.setProperty("scriptLanguage", "beanshell"); + jsr223PreProcessor.setProperty("script", script()); + hashTree.add(jsr223PreProcessor); + return hashTree; } if (StringUtils.equals(this.loopType, LoopConstants.FOREACH.name()) && this.forEachController != null) { return tree.add(initForeachController()); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java index 6a41b3d039..2c1c86c777 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java @@ -34,10 +34,10 @@ public class MsExtract extends MsTestElement { if (!config.isOperating() && !this.isEnable()) { return; } - addRequestExtractors(tree); + addRequestExtractors(tree, config); } - private void addRequestExtractors(HashTree samplerHashTree) { + private void addRequestExtractors(HashTree samplerHashTree, ParameterConfig config) { StringJoiner extract = new StringJoiner(";"); if (CollectionUtils.isNotEmpty(this.getRegex())) { @@ -55,7 +55,7 @@ public class MsExtract extends MsTestElement { samplerHashTree.add(jsonPostProcessor(extractJSONPath, extract)) ); } - if (Optional.ofNullable(extract).orElse(extract).length() > 0) { + if (Optional.ofNullable(extract).orElse(extract).length() > 0 && !config.isOperating()) { JSR223PostProcessor shell = new JSR223PostProcessor(); shell.setEnabled(true); shell.setName(StringUtils.isEmpty(this.getName()) ? "JSR223PostProcessor" : this.getName());