You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by to...@apache.org on 2021/04/09 08:59:44 UTC
[apisix-ingress-controller] branch master updated: fix: use put
(instead of patch) as the method when updating resources. (#353)
This is an automated email from the ASF dual-hosted git repository.
tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 438bb0f fix: use put (instead of patch) as the method when updating resources. (#353)
438bb0f is described below
commit 438bb0f400d6c1e89185ba3528cb6b3182bbcb84
Author: Alex Zhang <zc...@gmail.com>
AuthorDate: Fri Apr 9 16:59:36 2021 +0800
fix: use put (instead of patch) as the method when updating resources. (#353)
---
pkg/apisix/cluster.go | 2 +-
pkg/apisix/route.go | 22 +++----
pkg/apisix/upstream.go | 16 ++++--
test/e2e/plugins/cors.go | 76 ++++++++++++++++++++++++
test/e2e/plugins/echo.go | 111 ++++++++++++++++++++++++++++++++++++
test/e2e/plugins/fault_injection.go | 68 ++++++++++++++++++++++
test/e2e/plugins/limit_count.go | 93 ++++++++++++++++++++++++++++++
test/e2e/plugins/redirect.go | 68 ++++++++++++++++++++++
test/e2e/plugins/request_id.go | 67 ++++++++++++++++++++++
test/e2e/plugins/uri_blocker.go | 94 ++++++++++++++++++++++++++++++
10 files changed, 600 insertions(+), 17 deletions(-)
diff --git a/pkg/apisix/cluster.go b/pkg/apisix/cluster.go
index bd739c9..9445386 100644
--- a/pkg/apisix/cluster.go
+++ b/pkg/apisix/cluster.go
@@ -355,7 +355,7 @@ func (s *cluster) createResource(ctx context.Context, url string, body io.Reader
}
func (s *cluster) updateResource(ctx context.Context, url string, body io.Reader) (*updateResponse, error) {
- req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, body)
+ req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, body)
if err != nil {
return nil, err
}
diff --git a/pkg/apisix/route.go b/pkg/apisix/route.go
index 551e1b7..70c4f35 100644
--- a/pkg/apisix/route.go
+++ b/pkg/apisix/route.go
@@ -233,21 +233,23 @@ func (r *routeClient) Update(ctx context.Context, obj *v1.Route) (*v1.Route, err
return nil, err
}
body, err := json.Marshal(routeReqBody{
- Priority: obj.Priority,
- Desc: obj.Name,
- Name: obj.Name,
- Host: obj.Host,
- Hosts: obj.Hosts,
- URI: obj.Path,
- ServiceId: obj.ServiceId,
- Plugins: obj.Plugins,
- Vars: obj.Vars,
+ Priority: obj.Priority,
+ Desc: obj.Name,
+ Name: obj.Name,
+ URI: obj.Path,
+ Host: obj.Host,
+ Hosts: obj.Hosts,
+ ServiceId: obj.ServiceId,
+ UpstreamId: obj.UpstreamId,
+ Uris: obj.Uris,
+ Plugins: obj.Plugins,
+ Vars: obj.Vars,
})
if err != nil {
return nil, err
}
url := r.url + "/" + obj.ID
- log.Debugw("updating route", zap.ByteString("body", body), zap.String("url", r.url))
+ log.Debugw("updating route", zap.ByteString("body", body), zap.String("url", url))
resp, err := r.cluster.updateResource(ctx, url, bytes.NewReader(body))
if err != nil {
return nil, err
diff --git a/pkg/apisix/upstream.go b/pkg/apisix/upstream.go
index 826f725..94c5178 100644
--- a/pkg/apisix/upstream.go
+++ b/pkg/apisix/upstream.go
@@ -275,12 +275,16 @@ func (u *upstreamClient) Update(ctx context.Context, obj *v1.Upstream) (*v1.Upst
})
}
body, err := json.Marshal(upstreamReqBody{
- LBType: obj.Type,
- HashOn: obj.HashOn,
- Key: obj.Key,
- Nodes: nodes,
- Desc: obj.Name,
- Name: obj.Name,
+ LBType: obj.Type,
+ HashOn: obj.HashOn,
+ Key: obj.Key,
+ Nodes: nodes,
+ Desc: obj.Name,
+ Name: obj.Name,
+ Scheme: obj.Scheme,
+ Checks: obj.Checks,
+ Retries: obj.Retries,
+ Timeout: obj.Timeout,
})
if err != nil {
return nil, err
diff --git a/test/e2e/plugins/cors.go b/test/e2e/plugins/cors.go
index aa5ada8..bf81de0 100644
--- a/test/e2e/plugins/cors.go
+++ b/test/e2e/plugins/cors.go
@@ -251,4 +251,80 @@ spec:
resp.Header("Access-Control-Max-Age").Empty()
resp.Body().Contains("origin")
})
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: cors
+ enable: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+
+ resp.Header("Access-Control-Allow-Origin").Equal("*")
+ resp.Header("Access-Control-Allow-Methods").Equal("*")
+ resp.Header("Access-Control-Allow-Headers").Equal("*")
+ resp.Header("Access-Control-Expose-Headers").Equal("*")
+ resp.Header("Access-Control-Max-Age").Equal("5")
+ resp.Body().Contains("origin")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+
+ // httpbin sets this header by itself.
+ //resp.Header("Access-Control-Allow-Origin").Empty()
+ resp.Header("Access-Control-Allow-Methods").Empty()
+ resp.Header("Access-Control-Allow-Headers").Empty()
+ resp.Header("Access-Control-Expose-Headers").Empty()
+ resp.Header("Access-Control-Max-Age").Empty()
+ resp.Body().Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/echo.go b/test/e2e/plugins/echo.go
index a352284..06434b4 100644
--- a/test/e2e/plugins/echo.go
+++ b/test/e2e/plugins/echo.go
@@ -164,4 +164,115 @@ spec:
resp.Status(http.StatusOK)
resp.Body().Equal("my custom body")
})
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: echo
+ enable: false
+ config:
+ body: "my custom body"
+
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ resp.Body().NotContains("my custom body")
+ })
+
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: echo
+ enable: true
+ config:
+ body: "my custom body"
+
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Equal("my custom body")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().NotContains("my custom body")
+ resp.Body().Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/fault_injection.go b/test/e2e/plugins/fault_injection.go
index 6dd3b52..a55a8e7 100644
--- a/test/e2e/plugins/fault_injection.go
+++ b/test/e2e/plugins/fault_injection.go
@@ -172,4 +172,72 @@ spec:
resp = s.NewAPISIXClient().GET("/ip").WithQuery("name", "bob").WithHeader("Host", "httpbin.org").WithHeader("X-Foo", "bar").Expect()
resp.Status(http.StatusOK)
})
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: fault-injection
+ enable: true
+ config:
+ abort:
+ http_status: 500
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithQuery("name", "bob").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusInternalServerError)
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp = s.NewAPISIXClient().GET("/ip").WithQuery("name", "bob").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/limit_count.go b/test/e2e/plugins/limit_count.go
index e16b615..e7ff31f 100644
--- a/test/e2e/plugins/limit_count.go
+++ b/test/e2e/plugins/limit_count.go
@@ -144,4 +144,97 @@ spec:
Body().
Contains("origin")
})
+
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: limit-count
+ enable: true
+ config:
+ rejected_code: 503
+ count: 2
+ time_window: 3
+ key: remote_addr
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(503)
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/redirect.go b/test/e2e/plugins/redirect.go
index cb094d0..0cdc3b2 100644
--- a/test/e2e/plugins/redirect.go
+++ b/test/e2e/plugins/redirect.go
@@ -148,4 +148,72 @@ spec:
resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
resp.Status(http.StatusOK)
})
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: redirect
+ enable: true
+ config:
+ uri: "$uri/ipip"
+ ret_code: 308
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusPermanentRedirect)
+ resp.Header("Location").Equal("/ip/ipip")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/request_id.go b/test/e2e/plugins/request_id.go
index 3943588..2d40c9e 100644
--- a/test/e2e/plugins/request_id.go
+++ b/test/e2e/plugins/request_id.go
@@ -107,4 +107,71 @@ spec:
resp.Header("X-Request-Id").Empty()
resp.Body().Contains("origin")
})
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: request-id
+ enable: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(200)
+ resp.Header("X-Request-Id").NotEmpty()
+ resp.Body().Contains("origin")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(200)
+ resp.Header("X-Request-Id").Empty()
+ resp.Body().Contains("origin")
+ })
})
diff --git a/test/e2e/plugins/uri_blocker.go b/test/e2e/plugins/uri_blocker.go
index 8f1c8f9..1d6c9d0 100644
--- a/test/e2e/plugins/uri_blocker.go
+++ b/test/e2e/plugins/uri_blocker.go
@@ -16,6 +16,7 @@ package plugins
import (
"fmt"
+ "net/http"
"github.com/stretchr/testify/assert"
@@ -147,4 +148,97 @@ spec:
Body().
Contains("origin")
})
+
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ - /status/200
+ - /headers
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: uri-blocker
+ enable: true
+ config:
+ rejected_code: 403
+ block_rules:
+ - /status/200
+ - /headers
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusForbidden)
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusForbidden)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /ip
+ - /status/200
+ - /headers
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+ s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK).
+ Body().
+ Contains("httpbin.org")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
})