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 52f1cf281 [type:Integration Test] Add rewrite-plugin Integration Test
(#3385)
52f1cf281 is described below
commit 52f1cf281800ef36ae3b9dd860ece87c7cbe50e5
Author: erdengk <[email protected]>
AuthorDate: Thu May 5 20:48:46 2022 +0800
[type:Integration Test] Add rewrite-plugin Integration Test (#3385)
* add cache test
* Revert "add cache test"
This reverts commit 2b8f8e390d4d70938a253d0b19709a92786ffb77.
* update Rewrite Plugin Test
* fix ci
---
.../shenyu-integrated-test-http/pom.xml | 8 ++
.../test/http/combination/RewritePluginTest.java | 95 ++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
index 9faec073f..231ff8175 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
@@ -146,6 +146,14 @@
</dependency>
<!--shenyu cache plugin end-->
+ <!-- apache shenyu rewrite plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-rewrite</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- apache shenyu rewrite plugin end-->
+
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-integrated-test-common</artifactId>
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
new file mode 100644
index 000000000..e91c1e907
--- /dev/null
+++
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RewritePluginTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.integrated.test.http.combination;
+
+import org.apache.shenyu.common.dto.ConditionData;
+import org.apache.shenyu.common.dto.convert.rule.RewriteHandle;
+import org.apache.shenyu.common.enums.OperatorEnum;
+import org.apache.shenyu.common.enums.ParamTypeEnum;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.JsonUtils;
+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;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public final class RewritePluginTest extends AbstractPluginDataInit {
+
+ private static final String TEST_REWRITE_PASS = "/http/test/waf/pass";
+
+ @BeforeEach
+ public void setup() throws IOException {
+ String pluginResult = initPlugin(PluginEnum.REWRITE.getName(), "");
+ assertThat(pluginResult, is("success"));
+ String selectorAndRulesResult =
+ initSelectorAndRules(PluginEnum.REWRITE.getName(), "",
buildSelectorConditionList(), buildRuleLocalDataList());
+ assertThat(selectorAndRulesResult, is("success"));
+ }
+
+ @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());
+ }
+
+ private static List<ConditionData> buildSelectorConditionList() {
+ ConditionData conditionData = new ConditionData();
+ conditionData.setParamType(ParamTypeEnum.URI.getName());
+ conditionData.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData.setParamName("/");
+ conditionData.setParamValue("/**");
+ return Collections.singletonList(conditionData);
+ }
+
+ private static List<RuleLocalData> buildRuleLocalDataList() {
+ final RuleLocalData ruleLocalData = new RuleLocalData();
+
+ ConditionData conditionData = new ConditionData();
+ conditionData.setParamType(ParamTypeEnum.URI.getName());
+ conditionData.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData.setParamName("/");
+ conditionData.setParamValue("/http/test/**");
+
ruleLocalData.setConditionDataList(Collections.singletonList(conditionData));
+ ruleLocalData.setRuleName("testRewrite");
+
+ RewriteHandle rewriteHandle = new RewriteHandle();
+ rewriteHandle.setRegex("/http/test/waf/pass");
+ rewriteHandle.setReplace("/test/waf/deny");
+
+ ruleLocalData.setRuleHandler(JsonUtils.toJson(rewriteHandle));
+ return Collections.singletonList(ruleLocalData);
+ }
+
+ @AfterEach
+ public void clean() throws IOException {
+ cleanPluginData(PluginEnum.REWRITE.getName());
+ }
+}