123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /*
- * 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/v2"
- "github.com/apisix/manager-api/test/e2e/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,
- }),
- 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,
- }),
- )
- })
|