You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by jo...@apache.org on 2022/06/21 11:25:33 UTC
[incubator-shenyu] branch master updated: [type:Integration Test] Add new test for rewrite-plugin (#3596)
This is an automated email from the ASF dual-hosted git repository.
jooks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 72dfcd8f9 [type:Integration Test] Add new test for rewrite-plugin (#3596)
72dfcd8f9 is described below
commit 72dfcd8f9625e36b293fae8b458c9d63ed47ee69
Author: 尔等同学 <37...@users.noreply.github.com>
AuthorDate: Tue Jun 21 19:25:28 2022 +0800
[type:Integration Test] Add new test for rewrite-plugin (#3596)
* add new test
* fix ci
---
.../test/http/combination/RewritePluginTest.java | 36 +++++++++++++---------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RewritePluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RewritePluginTest.java
index e91c1e907..19e2d08e1 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RewritePluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RewritePluginTest.java
@@ -27,8 +27,6 @@ import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.integratedtest.common.result.ResultBean;
import org.apache.shenyu.web.controller.LocalPluginController.RuleLocalData;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -45,19 +43,31 @@ public final class RewritePluginTest extends AbstractPluginDataInit {
private static final String TEST_REWRITE_PASS = "/http/test/waf/pass";
- @BeforeEach
- public void setup() throws IOException {
+ @Test
+ public void testRewritePlugin() throws IOException, ExecutionException, InterruptedException {
String pluginResult = initPlugin(PluginEnum.REWRITE.getName(), "");
assertThat(pluginResult, is("success"));
String selectorAndRulesResult =
- initSelectorAndRules(PluginEnum.REWRITE.getName(), "", buildSelectorConditionList(), buildRuleLocalDataList());
+ initSelectorAndRules(PluginEnum.REWRITE.getName(), "", buildSelectorConditionList(), buildRuleLocalDataList("", ""));
assertThat(selectorAndRulesResult, is("success"));
+ assertEquals(200, test());
+ cleanPluginData(PluginEnum.REWRITE.getName());
}
@Test
- public void testPass() throws ExecutionException, InterruptedException {
- Future<ResultBean> resp0 = this.getService().submit(() -> HttpHelper.INSTANCE.postGateway(TEST_REWRITE_PASS, ResultBean.class));
- assertEquals(403, resp0.get().getCode());
+ public void testReturnNewURIForRewritePlugin() throws IOException, ExecutionException, InterruptedException {
+ String pluginResult = initPlugin(PluginEnum.REWRITE.getName(), "");
+ assertThat(pluginResult, is("success"));
+ String selectorAndRulesResult =
+ initSelectorAndRules(PluginEnum.REWRITE.getName(), "", buildSelectorConditionList(), buildRuleLocalDataList("/http/test/waf/pass", "/test/waf/deny"));
+ assertThat(selectorAndRulesResult, is("success"));
+ assertEquals(403, test());
+ cleanPluginData(PluginEnum.REWRITE.getName());
+ }
+
+ private Integer test() throws ExecutionException, InterruptedException {
+ Future<ResultBean> resp = this.getService().submit(() -> HttpHelper.INSTANCE.postGateway(TEST_REWRITE_PASS, ResultBean.class));
+ return resp.get().getCode();
}
private static List<ConditionData> buildSelectorConditionList() {
@@ -69,7 +79,7 @@ public final class RewritePluginTest extends AbstractPluginDataInit {
return Collections.singletonList(conditionData);
}
- private static List<RuleLocalData> buildRuleLocalDataList() {
+ private static List<RuleLocalData> buildRuleLocalDataList(final String regex, final String replace) {
final RuleLocalData ruleLocalData = new RuleLocalData();
ConditionData conditionData = new ConditionData();
@@ -81,15 +91,11 @@ public final class RewritePluginTest extends AbstractPluginDataInit {
ruleLocalData.setRuleName("testRewrite");
RewriteHandle rewriteHandle = new RewriteHandle();
- rewriteHandle.setRegex("/http/test/waf/pass");
- rewriteHandle.setReplace("/test/waf/deny");
+ rewriteHandle.setRegex(regex);
+ rewriteHandle.setReplace(replace);
ruleLocalData.setRuleHandler(JsonUtils.toJson(rewriteHandle));
return Collections.singletonList(ruleLocalData);
}
- @AfterEach
- public void clean() throws IOException {
- cleanPluginData(PluginEnum.REWRITE.getName());
- }
}