You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by bz...@apache.org on 2021/10/31 10:14:19 UTC

[apisix-dashboard] branch master updated: test(route): add update route with plugin uri blocker case (#2187)

This is an automated email from the ASF dual-hosted git repository.

bzp2010 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e1e83e3  test(route): add update route with plugin uri blocker case (#2187)
e1e83e3 is described below

commit e1e83e3d9a57de26dcb924d2f1b708bb778e0547
Author: Yu.Bozhong <y....@foxmail.com>
AuthorDate: Sun Oct 31 18:14:14 2021 +0800

    test(route): add update route with plugin uri blocker case (#2187)
---
 .../route/route_with_plugin_uri_blocker_test.go    | 145 +++++++++++++++++++++
 1 file changed, 145 insertions(+)

diff --git a/api/test/e2enew/route/route_with_plugin_uri_blocker_test.go b/api/test/e2enew/route/route_with_plugin_uri_blocker_test.go
new file mode 100644
index 0000000..5bb43cc
--- /dev/null
+++ b/api/test/e2enew/route/route_with_plugin_uri_blocker_test.go
@@ -0,0 +1,145 @@
+/*
+ * 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 route
+
+import (
+	"net/http"
+
+	"github.com/onsi/ginkgo"
+	"github.com/onsi/ginkgo/extensions/table"
+
+	"github.com/apisix/manager-api/test/e2enew/base"
+)
+
+var _ = ginkgo.Describe("route with plugin uri blocker", func() {
+	table.DescribeTable("test route with plugin uri blocker",
+		func(tc base.HttpTestCase) {
+			base.RunTestCase(tc)
+		},
+		table.Entry("make sure the route is not created", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/*",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		}),
+		table.Entry("create route1", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+				  "name": "route1",
+				  "uri": "/*",
+				  "upstream": {
+					  "type": "roundrobin",
+					  "nodes": {
+						  "` + base.UpstreamIp + `:1982": 1
+					  }
+				  }
+			  }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		}),
+		table.Entry("make sure the plugin uri blocker is not worked", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/root.exe",
+			ExpectStatus: http.StatusNotFound,
+		}),
+		table.Entry("update route with uri blocker", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+					  "name": "route1",
+					  "uri": "/*",
+					  "plugins": {
+						 "uri-blocker": {
+							 "block_rules": ["hello"]
+						 }
+					  },
+					  "upstream": {
+						  "type": "roundrobin",
+						  "nodes": {
+							  "` + base.UpstreamIp + `:1980": 1
+						  }
+					  }
+				  }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		}),
+		table.Entry("verify route that block uri", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusForbidden,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("update route with uri blocker", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+					  "name": "route1",
+					  "uri": "/*",
+					  "plugins": {
+						 "uri-blocker": {
+							 "block_rules": ["robots.txt"]
+						 }
+					  },
+					  "upstream": {
+						  "type": "roundrobin",
+						  "nodes": {
+							  "` + base.UpstreamIp + `:1980": 1
+						  }
+					  }
+				  }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		}),
+		table.Entry("verify route that old block uri rule", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusOK,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("verify route that block uri", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/robots.txt",
+			ExpectStatus: http.StatusForbidden,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("delete route", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/routes/r1",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("make sure the route deleted", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+			Sleep:        base.SleepTime,
+		}),
+	)
+})