You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by sa...@apache.org on 2021/08/09 14:25:19 UTC
[incubator-shenyu] branch master updated: test plugin-redirect: add
integrated test.(#1903) (#1904)
This is an automated email from the ASF dual-hosted git repository.
sabersola 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 420ad6c test plugin-redirect: add integrated test.(#1903) (#1904)
420ad6c is described below
commit 420ad6c54f8170ee0780238e51de25ae9e718876
Author: fengzhenbing <fe...@126.com>
AuthorDate: Mon Aug 9 22:25:10 2021 +0800
test plugin-redirect: add integrated test.(#1903) (#1904)
---
.../admin-config/schema.sql | 11 +++++
.../shenyu-integrated-test-http/pom.xml | 8 ++++
.../shenyu/integratedtest/http/RedirectTest.java | 53 ++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/admin-config/schema.sql b/shenyu-integrated-test/shenyu-integrated-test-http/admin-config/schema.sql
index 8de59d4..1d032b2 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/admin-config/schema.sql
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/admin-config/schema.sql
@@ -44,3 +44,14 @@ INSERT IGNORE INTO rule (id, selector_id, match_mode, name, enabled, loged, sort
INSERT IGNORE INTO rule (id, selector_id, match_mode, name, enabled, loged, sort, handle, date_created, date_updated) VALUES ('1422826385177350144', '1422826261990641664', 0, '/http/test/waf/deny', 1, 1, 1, '{"permission":"reject","statusCode":"403"}', '2021-08-04 13:09:32','2021-08-04 13:09:32');
INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1422826330122915840', '1422826330114527232', 'uri', '=', '/', '/http/test/waf/pass','2021-08-04 13:09:32','2021-08-04 13:09:32');
INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1422826385185738752', '1422826385177350144', 'uri', '=', '/', '/http/test/waf/deny','2021-08-04 13:09:32','2021-08-04 13:09:32');
+
+/** prepare redirect **/
+UPDATE plugin SET enabled = 1 WHERE id = '16';
+INSERT IGNORE INTO selector (id, plugin_id, name, match_mode, type, sort, handle, enabled, loged, continued, date_created, date_updated) VALUES ('1424403439680131072', '16', 'http-redirect', 0, 1, 1, null, 1, 1, 1, '2021-08-09 00:13:39', '2021-08-09 11:47:23');
+INSERT IGNORE INTO selector_condition (id, selector_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1424403439684325376', '1424403439680131072', 'uri', '=', '/', '/http/test/path/111', '2021-08-09 11:47:23', '2021-08-09 11:47:23');
+INSERT IGNORE INTO rule (id, selector_id, match_mode, name, enabled, loged, sort, handle, date_created, date_updated) VALUES ('1424403555619082240', '1424403439680131072', 0, 'http-redirect-outer-url', 1, 1, 1, '{"redirectURI":"http://localhost:9195/http/test/path/222?name=redirectToOuterPath"}', '2021-08-09 00:14:06', '2021-08-09 00:22:01');
+INSERT IGNORE INTO rule (id, selector_id, match_mode, name, enabled, loged, sort, handle, date_created, date_updated) VALUES ('1424405341335621632', '1424403439680131072', 0, 'http-redirect-inner-path', 1, 1, 2, '{"redirectURI":"/actuator/health"}', '2021-08-09 00:21:12', '2021-08-09 00:30:22');
+INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1424403555627470848', '1424403555619082240', 'uri', '=', '/', '/http/test/path/111', '2021-08-09 00:22:01', '2021-08-09 00:22:01');
+INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1424404768645353472', '1424403555619082240', 'query', '=', 'name', 'redirectToOuterPath', '2021-08-09 00:22:01', '2021-08-09 00:22:01');
+INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1424405341339815936', '1424405341335621632', 'uri', '=', '/', '/http/test/path/111', '2021-08-09 00:30:21', '2021-08-09 00:30:22');
+INSERT IGNORE INTO rule_condition (id, rule_id, param_type, operator, param_name, param_value, date_created, date_updated) VALUES ('1424405341344010240', '1424405341335621632', 'query', '=', 'name', 'redirectToInnerPath', '2021-08-09 00:30:21', '2021-08-09 00:30:22');
\ No newline at end of file
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
index b357d6d..03c3cb4 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
@@ -73,6 +73,14 @@
</dependency>
<!-- shenyu waf plugin end-->
+ <!-- apache shenyu redirect plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-redirect</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- apache shenyu redirect plugin end-->
+
<!--shenyu data sync start use websocket-->
<dependency>
<groupId>org.apache.shenyu</groupId>
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integratedtest/http/RedirectTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integratedtest/http/RedirectTest.java
new file mode 100644
index 0000000..957457c
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integratedtest/http/RedirectTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.integratedtest.http;
+
+import org.apache.shenyu.integratedtest.http.helper.HttpHelper;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public final class RedirectTest extends AbstractTest {
+
+ @Test
+ public void test() throws IOException {
+ final String redirectUserId = "111";
+ final String redirectToInnerPathUrl = "/http/test/path/" + redirectUserId + "?name=redirectToInnerPath";
+ Map<String, Object> result = HttpHelper.INSTANCE.getFromGateway(redirectToInnerPathUrl, Map.class);
+ assertNotNull(result);
+ assertNull(result.get("userId"));
+ assertEquals("UP", result.get("status"));
+
+ final String redirectToOuterPathUrl = "/http/test/path/" + redirectUserId + "?name=redirectToOuterPath";
+ result = HttpHelper.INSTANCE.getFromGateway(redirectToOuterPathUrl, Map.class);
+ assertNotEquals(redirectUserId, result.get("userId"));
+ assertEquals("222", result.get("userId"));
+
+ final String notRedirectUserId = "333";
+ final String notRedirectUrl = "/http/test/path/" + notRedirectUserId + "?name=notRedirect";
+ result = HttpHelper.INSTANCE.getFromGateway(notRedirectUrl, Map.class);
+ assertNotNull(result);
+ assertEquals(notRedirectUserId, result.get("userId"));
+ }
+}