This is an automated email from the ASF dual-hosted git repository. chenjunxu 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 8755d1c test: add route with valid remote_address (E2E) (#884) 8755d1c is described below commit 8755d1c5cb6e5701df1a9bd371a1c72eaa666a05 Author: idbeta <idb...@gmail.com> AuthorDate: Sun Nov 29 07:58:14 2020 +0800 test: add route with valid remote_address (E2E) (#884) * test: add route with vaild remote_address (E2E) * test: verify again after delete route * chore: fix the typo * fix: fix the typo * fix: modify the typo in casefile name * fix: use the right remote_addr in testcase * fix: update English and revert `ExpectStatus` * chore: update English comment * test: add test case about invalid remote_addr and remote_addrs * chore: update caseDesc --- api/test/e2e/route_with_valid_remote_addr_test.go | 197 ++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/api/test/e2e/route_with_valid_remote_addr_test.go b/api/test/e2e/route_with_valid_remote_addr_test.go new file mode 100644 index 0000000..75afaa5 --- /dev/null +++ b/api/test/e2e/route_with_valid_remote_addr_test.go @@ -0,0 +1,197 @@ +/* + * 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_with_valid_remote_addr(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "add route with valid remote_addr", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "remote_addr": "172.16.238.1", + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "update route with valid remote_addr (CIDR)", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "remote_addr": "172.16.238.1/24", + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "update route with valid remote_addrs", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "remote_addrs": ["172.16.238.1","192.168.0.2/24"], + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "update remote_addr to not be hit", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "remote_addr": "10.10.10.10", + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusNotFound, + Sleep: sleepTime, + }, + { + caseDesc: "update remote_addrs to not be hit", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "remote_addrs": ["10.10.10.10","11.11.11.1/24"] + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusNotFound, + Sleep: sleepTime, + }, + { + caseDesc: "delete route", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r1", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + Sleep: sleepTime, + }, + { + caseDesc: "verify it again after deleting the 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) + } +}