bzp2010 commented on a change in pull request #2202:
URL: https://github.com/apache/apisix-dashboard/pull/2202#discussion_r757928639



##########
File path: api/test/e2enew/global_rule/global_rule_test.go
##########
@@ -0,0 +1,201 @@
+/*
+ * 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 global_rule_test
+
+import (
+       "net/http"
+
+       . "github.com/onsi/ginkgo"
+       . "github.com/onsi/ginkgo/extensions/table"
+
+       "github.com/apisix/manager-api/test/e2enew/base"
+)
+
+var _ = Describe("Global Rule", func() {
+       var _ = DescribeTable("test global rule curd",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               Entry("create global rule", base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/global_rules/1",
+                       Body: `{
+                               "plugins": {
+                                       "response-rewrite": {
+                                               "headers": {
+                                                       "X-VERSION":"1.0"
+                                               }
+                                       }
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"X-VERSION\":\"1.0\"",
+               }),
+               Entry("full update global rule", base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/global_rules/1",
+                       Body: `{
+                               "plugins": {
+                                       "response-rewrite": {
+                                               "headers": {
+                                                       "X-TEST":"1.0"
+                                               }
+                                       }
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"X-TEST\":\"1.0\"",
+               }),
+               Entry("partial update global rule", base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPatch,
+                       Path:   "/apisix/admin/global_rules/1/plugins",
+                       Body: `{
+                               "response-rewrite": {
+                                       "headers": {
+                                               "X-VERSION":"1.0"
+                                       }
+                               },
+                               "key-auth": {}
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"key-auth\":{}",
+               }),
+               Entry("delete global rule", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/global_rules/1",
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+               }),
+       )
+
+       var _ = DescribeTable("test global rule integration",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               Entry("create route", base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/routes/r1",
+                       Body: `{
+                               "name": "route1",
+                               "uri": "/hello",
+                               "upstream": {
+                                       "type": "roundrobin",
+                                       "nodes": [{
+                                               "host": "` + base.UpstreamIp + 
`",
+                                               "port": 1981,
+                                               "weight": 1
+                                       }]
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+               }),
+               Entry("create global rule", base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/global_rules/1",
+                       Body: `{
+                               "plugins": {
+                                       "response-rewrite": {
+                                               "headers": {
+                                                       "X-VERSION":"1.0"
+                                               }
+                                       },
+                                       "uri-blocker": {
+                                               "block_rules": 
["select.+(from|limit)", "(?:(union(.*?)select))"]
+                                       }
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"X-VERSION\":\"1.0\"",
+               }),
+               Entry("verify route with header", base.HttpTestCase{
+                       Object:        base.APISIXExpect(),
+                       Method:        http.MethodGet,
+                       Path:          "/hello",
+                       ExpectStatus:  http.StatusOK,
+                       ExpectBody:    "hello world",
+                       ExpectHeaders: map[string]string{"X-VERSION": "1.0"},
+               }),
+               Entry("verify route that should be blocked", base.HttpTestCase{
+                       Object:        base.APISIXExpect(),
+                       Method:        http.MethodGet,
+                       Path:          "/hello",
+                       Query:         "name=%3Bselect%20from%20sys",
+                       ExpectStatus:  http.StatusForbidden,
+                       ExpectHeaders: map[string]string{"X-VERSION": "1.0"},
+               }),
+               Entry("update route with same plugin response-rewrite", 
base.HttpTestCase{
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/routes/r1",
+                       Body: `{
+                               "name": "route1",
+                               "uri": "/hello",
+                               "plugins": {
+                                       "response-rewrite": {
+                                               "headers": {
+                                                       "X-VERSION":"2.0"
+                                               }
+                                       }
+                               },
+                               "upstream": {
+                                       "type": "roundrobin",
+                                       "nodes": [{
+                                               "host": "` + base.UpstreamIp + 
`",
+                                               "port": 1981,
+                                               "weight": 1
+                                       }]
+                               }
+                        }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"X-VERSION\":\"2.0\"",
+               }),
+               Entry("verify route that header should override", 
base.HttpTestCase{
+                       Object:        base.APISIXExpect(),
+                       Method:        http.MethodGet,
+                       Path:          "/hello",
+                       ExpectStatus:  http.StatusOK,
+                       ExpectBody:    "hello world",
+                       ExpectHeaders: map[string]string{"X-VERSION": "2.0"},
+               }),
+               Entry("delete global rule", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/global_rules/1",
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+               }),

Review comment:
       Hi, @nic-chen, sorry for the delayed response.
   This will be executed in the `AfterSuite` phase, i.e. he will remove the 
content involved after the test is completed for each type of data.
   
[https://github.com/apache/apisix-dashboard/blob/665c3480a22e8bd1d4a232aa813ad214156af5b9/api/test/e2enew/global_rule/global_rule_suite_test.go#L34-L38](https://github.com/apache/apisix-dashboard/blob/665c3480a22e8bd1d4a232aa813ad214156af5b9/api/test/e2enew/global_rule/global_rule_suite_test.go#L34-L38)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to