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/12/03 05:33:25 UTC

[apisix-dashboard] branch master updated: test: migrate route remote addr e2e (#2201)

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 af06e08  test: migrate route remote addr e2e (#2201)
af06e08 is described below

commit af06e08e6f924d953bb2327fc49ef005ba70344e
Author: Yu.Bozhong <y....@foxmail.com>
AuthorDate: Fri Dec 3 13:33:20 2021 +0800

    test: migrate route remote addr e2e (#2201)
---
 api/test/e2e/route_remote_addr_test.go             | 124 -------------
 ...addr_test.go => route_with_remote_addr_test.go} | 196 +++++++++++++++------
 2 files changed, 145 insertions(+), 175 deletions(-)

diff --git a/api/test/e2e/route_remote_addr_test.go b/api/test/e2e/route_remote_addr_test.go
deleted file mode 100644
index 6047aa6..0000000
--- a/api/test/e2e/route_remote_addr_test.go
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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 e2e
-
-import (
-	"net/http"
-	"testing"
-)
-
-func TestRoute_add_with_invalid_remote_addr(t *testing.T) {
-	tests := []HttpTestCase{
-		{
-			Desc:   "config route with invalid remote_addr",
-			Object: ManagerApiExpect(t),
-			Method: http.MethodPut,
-			Path:   "/apisix/admin/routes/r1",
-			Body: `{
-					"name": "route1",
-					"uri": "/hello",
-					"remote_addr": "127.0.0.",
-					"upstream": {
-						"type": "roundrobin",
-						"nodes": [{
-							"host": "` + UpstreamIp + `",
-							"port": 1980,
-							"weight": 1
-						}]
-					}
-				}`,
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusBadRequest,
-			ExpectBody:   "\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"",
-		},
-		{
-			Desc:         "verify route",
-			Object:       APISIXExpect(t),
-			Method:       http.MethodGet,
-			Path:         "/hello",
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusNotFound,
-			Sleep:        sleepTime,
-		},
-		{
-			Desc:   "config route with invalid remote_addr",
-			Object: ManagerApiExpect(t),
-			Method: http.MethodPut,
-			Path:   "/apisix/admin/routes/r1",
-			Body: `{
-					"name": "route1",
-					"uri": "/hello",
-					"remote_addr": "127.0.0.aa",
-					"upstream": {
-						"type": "roundrobin",
-						"nodes": [{
-							"host": "` + UpstreamIp + `",
-							"port": 1980,
-							"weight": 1
-						}]
-					}
-				}`,
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusBadRequest,
-			ExpectBody:   "\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"",
-		},
-		{
-			Desc:         "verify route",
-			Object:       APISIXExpect(t),
-			Method:       http.MethodGet,
-			Path:         "/hello",
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusNotFound,
-			Sleep:        sleepTime,
-		},
-		{
-			Desc:   "config route with invalid remote_addrs",
-			Object: ManagerApiExpect(t),
-			Method: http.MethodPut,
-			Path:   "/apisix/admin/routes/r1",
-			Body: `{
-					"name": "route1",
-					"uri": "/hello",
-					"remote_addrs": ["127.0.0.1","192.168.0."],
-					"upstream": {
-						"type": "roundrobin",
-						"nodes": [{
-							"host": "` + UpstreamIp + `",
-							"port": 1980,
-							"weight": 1
-						}]
-					}
-				}`,
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusBadRequest,
-			ExpectBody:   "\"code\":10000,\"message\":\"schema validate failed: remote_addrs.1: Must validate at least one schema (anyOf)\\nremote_addrs.1: Does not match format 'ipv4'\"",
-		},
-		{
-			Desc:         "verify route",
-			Object:       APISIXExpect(t),
-			Method:       http.MethodGet,
-			Path:         "/hello",
-			Headers:      map[string]string{"Authorization": token},
-			ExpectStatus: http.StatusNotFound,
-			Sleep:        sleepTime,
-		},
-	}
-
-	for _, tc := range tests {
-		testCaseCheck(tc, t)
-	}
-}
diff --git a/api/test/e2enew/route/route_with_valid_remote_addr_test.go b/api/test/e2enew/route/route_with_remote_addr_test.go
similarity index 53%
rename from api/test/e2enew/route/route_with_valid_remote_addr_test.go
rename to api/test/e2enew/route/route_with_remote_addr_test.go
index 7bae238..d8f9b9e 100644
--- a/api/test/e2enew/route/route_with_valid_remote_addr_test.go
+++ b/api/test/e2enew/route/route_with_remote_addr_test.go
@@ -26,7 +26,6 @@ import (
 )
 
 var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
-	remote_addr := "172.16.238.1"
 	table.DescribeTable("test route with valid remote_addr remote_addrs",
 		func(tc base.HttpTestCase) {
 			base.RunTestCase(tc)
@@ -36,16 +35,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 			Method: http.MethodPut,
 			Path:   "/apisix/admin/routes/r1",
 			Body: `{
-				"name": "route1",
-				"uri": "/hello",
-				"remote_addr": "` + remote_addr + `",
-				"upstream": {
-					"type": "roundrobin",
-					"nodes": {
-						"` + base.UpstreamIp + `:1980": 1
-					}
-				}
-			}`,
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addr": "172.16.238.1",
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": {
+						 "` + base.UpstreamIp + `:1980": 1
+					 }
+				 }
+			 }`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
 		}),
@@ -63,16 +62,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 			Method: http.MethodPut,
 			Path:   "/apisix/admin/routes/r1",
 			Body: `{
-				"name": "route1",
-				"uri": "/hello",
-				"remote_addr": "` + remote_addr + `/24",
-				"upstream": {
-					"type": "roundrobin",
-					"nodes": {
-						"` + base.UpstreamIp + `:1980": 1
-					}
-				}
-			}`,
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addr": "172.16.238.1/24",
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": {
+						 "` + base.UpstreamIp + `:1980": 1
+					 }
+				 }
+			 }`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
 		}),
@@ -90,16 +89,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 			Method: http.MethodPut,
 			Path:   "/apisix/admin/routes/r1",
 			Body: `{
-				"name": "route1",
-				"uri": "/hello",
-				"remote_addrs": ["` + remote_addr + `","192.168.0.2/24"],
-				"upstream": {
-					"type": "roundrobin",
-					"nodes": {
-						"` + base.UpstreamIp + `:1980": 1
-					}
-				}
-			}`,
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addrs": ["172.16.238.1","192.168.0.2/24"],
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": {
+						 "` + base.UpstreamIp + `:1980": 1
+					 }
+				 }
+			 }`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
 		}),
@@ -117,16 +116,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 			Method: http.MethodPut,
 			Path:   "/apisix/admin/routes/r1",
 			Body: `{
-				"name": "route1",
-				"uri": "/hello",
-				"remote_addr": "10.10.10.10",
-				"upstream": {
-					"type": "roundrobin",
-					"nodes": {
-						"` + base.UpstreamIp + `:1980": 1
-					}
-				}
-			}`,
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addr": "10.10.10.10",
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": {
+						 "` + base.UpstreamIp + `:1980": 1
+					 }
+				 }
+			 }`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
 		}),
@@ -144,16 +143,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 			Method: http.MethodPut,
 			Path:   "/apisix/admin/routes/r1",
 			Body: `{
-				"name": "route1",
-				"uri": "/hello",
-				"remote_addrs": ["10.10.10.10","11.11.11.1/24"],
-				"upstream": {
-					"type": "roundrobin",
-					"nodes": {
-						"` + base.UpstreamIp + `:1980": 1
-					}
-				}
-			}`,
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addrs": ["10.10.10.10","11.11.11.1/24"],
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": {
+						 "` + base.UpstreamIp + `:1980": 1
+					 }
+				 }
+			 }`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
 		}),
@@ -185,3 +184,98 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
 		}),
 	)
 })
+
+var _ = ginkgo.Describe("route with invalid remote_addr", func() {
+	table.DescribeTable("route with remote_addr",
+		func(tc base.HttpTestCase) {
+			base.RunTestCase(tc)
+		},
+		table.Entry("config route with invalid remote_addr", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addr": "127.0.0.",
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": [{
+						 "host": "` + base.UpstreamIp + `",
+						 "port": 1980,
+						 "weight": 1
+					 }]
+				 }
+			 }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusBadRequest,
+			ExpectBody:   "{\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"}",
+		}),
+		table.Entry("verify route", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("config route with invalid remote_addr", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addr": "127.0.0.aa",
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": [{
+						 "host": "` + base.UpstreamIp + `",
+						 "port": 1980,
+						 "weight": 1
+					 }]
+				 }
+			 }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusBadRequest,
+			ExpectBody:   "{\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"}",
+		}),
+		table.Entry("verify route", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("config route with invalid remote_addrs", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/r1",
+			Body: `{
+				 "name": "route1",
+				 "uri": "/hello",
+				 "remote_addrs": ["127.0.0.1","192.168.0."],
+				 "upstream": {
+					 "type": "roundrobin",
+					 "nodes": [{
+						 "host": "` + base.UpstreamIp + `",
+						 "port": 1980,
+						 "weight": 1
+					 }]
+				 }
+			 }`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusBadRequest,
+			ExpectBody:   "{\"code\":10000,\"message\":\"schema validate failed: remote_addrs.1: Must validate at least one schema (anyOf)\\nremote_addrs.1: Does not match format 'ipv4'\"}",
+		}),
+		table.Entry("verify route", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        base.SleepTime,
+		}),
+	)
+})