From 856a24a70af64414a144cf85f69149542e8f1a46 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Mon, 5 Apr 2021 17:14:09 +0800 Subject: [PATCH 01/15] test: add e2e test cases for proxy-rewrite plugin --- test/e2e/plugins/ proxy-rewrite.go | 150 +++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 test/e2e/plugins/ proxy-rewrite.go diff --git a/test/e2e/plugins/ proxy-rewrite.go b/test/e2e/plugins/ proxy-rewrite.go new file mode 100644 index 0000000000..8cc17a7a34 --- /dev/null +++ b/test/e2e/plugins/ proxy-rewrite.go @@ -0,0 +1,150 @@ +// 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 plugins + +import ( + "fmt" + "time" + + "github.com/stretchr/testify/assert" + "github.com/onsi/ginkgo" + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" +) + +var _ = ginkgo.Describe("proxy-rewrite plugin", func() { + opts := &scaffold.Options{ + Name: "default", + Kubeconfig: scaffold.GetKubeconfig(), + APISIXConfigPath: "testdata/apisix-gw-config.yaml", + APISIXDefaultConfigPath: "testdata/apisix-gw-config-default.yaml", + IngressAPISIXReplicas: 1, + HTTPBinServicePort: 80, + APISIXRouteVersion: "apisix.apache.org/v2alpha1", + } + s := scaffold.NewScaffold(opts) + ginkgo.It("proxy rewrite request uri", 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + uri: /ip +`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() + resp.Status(http.StatusOK) + resp.Header("Location").Equal("https://httpbin.org/ip") + }) + + ginkgo.It("proxy rewrite request uri and host", 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + uri: /ip + host: httpbin.org +`, 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("/hello").Expect() + resp.Status(http.StatusOK) + resp.Header("Location").Equal("https://httpbin.org/ip") + }) + + 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: false + config: + uri: /ip +`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() + resp.Status(404) + }) +}) From c00003c88ef1bcdd559aee714e9b5c59f5c92fa2 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Mon, 5 Apr 2021 17:27:24 +0800 Subject: [PATCH 02/15] update test cases --- test/e2e/plugins/proxy_rewrite.go | 150 ++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 test/e2e/plugins/proxy_rewrite.go diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go new file mode 100644 index 0000000000..cb4a731e28 --- /dev/null +++ b/test/e2e/plugins/proxy_rewrite.go @@ -0,0 +1,150 @@ +// 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 plugins + +import ( + "fmt" + "time" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" + "github.com/onsi/ginkgo" + "github.com/stretchr/testify/assert" +) + +var _ = ginkgo.Describe("proxy-rewrite plugin", func() { + opts := &scaffold.Options{ + Name: "default", + Kubeconfig: scaffold.GetKubeconfig(), + APISIXConfigPath: "testdata/apisix-gw-config.yaml", + APISIXDefaultConfigPath: "testdata/apisix-gw-config-default.yaml", + IngressAPISIXReplicas: 1, + HTTPBinServicePort: 80, + APISIXRouteVersion: "apisix.apache.org/v2alpha1", + } + s := scaffold.NewScaffold(opts) + ginkgo.It("proxy rewrite request uri", 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + uri: /ip +`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() + resp.Status(http.StatusOK) + resp.Header("Location").Equal("https://httpbin.org/ip") + }) + + ginkgo.It("proxy rewrite request uri and host", 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + uri: /ip + host: httpbin.org +`, 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("/hello").Expect() + resp.Status(http.StatusOK) + resp.Header("Location").Equal("https://httpbin.org/ip") + }) + + 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: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: false + config: + uri: /ip +`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() + resp.Status(404) + }) +}) From a03341b19e35e55540afd67ac36c295ceaac66eb Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Mon, 5 Apr 2021 17:36:33 +0800 Subject: [PATCH 03/15] remove proxy-rewrite.go file --- test/e2e/plugins/ proxy-rewrite.go | 150 ----------------------------- 1 file changed, 150 deletions(-) delete mode 100644 test/e2e/plugins/ proxy-rewrite.go diff --git a/test/e2e/plugins/ proxy-rewrite.go b/test/e2e/plugins/ proxy-rewrite.go deleted file mode 100644 index 8cc17a7a34..0000000000 --- a/test/e2e/plugins/ proxy-rewrite.go +++ /dev/null @@ -1,150 +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 plugins - -import ( - "fmt" - "time" - - "github.com/stretchr/testify/assert" - "github.com/onsi/ginkgo" - "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" -) - -var _ = ginkgo.Describe("proxy-rewrite plugin", func() { - opts := &scaffold.Options{ - Name: "default", - Kubeconfig: scaffold.GetKubeconfig(), - APISIXConfigPath: "testdata/apisix-gw-config.yaml", - APISIXDefaultConfigPath: "testdata/apisix-gw-config-default.yaml", - IngressAPISIXReplicas: 1, - HTTPBinServicePort: 80, - APISIXRouteVersion: "apisix.apache.org/v2alpha1", - } - s := scaffold.NewScaffold(opts) - ginkgo.It("proxy rewrite request uri", 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: - - /hello - backends: - - serviceName: %s - servicePort: %d - weight: 10 - plugins: - - name: proxy-rewrite - enable: true - config: - uri: /ip -`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() - resp.Status(http.StatusOK) - resp.Header("Location").Equal("https://httpbin.org/ip") - }) - - ginkgo.It("proxy rewrite request uri and host", 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: - - /hello - backends: - - serviceName: %s - servicePort: %d - weight: 10 - plugins: - - name: proxy-rewrite - enable: true - config: - uri: /ip - host: httpbin.org -`, 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("/hello").Expect() - resp.Status(http.StatusOK) - resp.Header("Location").Equal("https://httpbin.org/ip") - }) - - 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: - - /hello - backends: - - serviceName: %s - servicePort: %d - weight: 10 - plugins: - - name: proxy-rewrite - enable: false - config: - uri: /ip -`, 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("/hello").WithHeader("Host", "httpbin.org").Expect() - resp.Status(404) - }) -}) From 11a4e8e6b5f3bbeebaba9ad0bb86cd586ffed607 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Mon, 5 Apr 2021 17:55:25 +0800 Subject: [PATCH 04/15] update test cases --- test/e2e/plugins/proxy_rewrite.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index cb4a731e28..6001a88105 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -16,11 +16,11 @@ package plugins import ( "fmt" - "time" - "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" "github.com/onsi/ginkgo" "github.com/stretchr/testify/assert" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) var _ = ginkgo.Describe("proxy-rewrite plugin", func() { @@ -67,9 +67,9 @@ spec: err = s.EnsureNumApisixRoutesCreated(1) assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes") - resp := s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").Expect() - resp.Status(http.StatusOK) - resp.Header("Location").Equal("https://httpbin.org/ip") + s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org"). + Expect(). + Status(200) }) ginkgo.It("proxy rewrite request uri and host", func() { @@ -106,9 +106,8 @@ spec: err = s.EnsureNumApisixRoutesCreated(1) assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes") - resp := s.NewAPISIXClient().GET("/hello").Expect() - resp.Status(http.StatusOK) - resp.Header("Location").Equal("https://httpbin.org/ip") + s.NewAPISIXClient().GET("/hello").Expect(). + Status(200) }) ginkgo.It("disable plugin", func() { @@ -144,7 +143,8 @@ spec: err = s.EnsureNumApisixRoutesCreated(1) assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes") - resp := s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").Expect() - resp.Status(404) + s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org"). + Expect(). + Status(404) }) }) From 9795c3ff9e51cc06e527f77c3eaac348eee4f6cb Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 14:50:35 +0800 Subject: [PATCH 05/15] update test case --- test/e2e/plugins/proxy_rewrite.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 6001a88105..2defa5dd57 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -83,8 +83,6 @@ spec: http: - name: rule1 match: - hosts: - - httpbin.org paths: - /hello backends: From 25b249d9e714fe654384a0cba6f3d63652ae049e Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 15:33:19 +0800 Subject: [PATCH 06/15] update tests --- test/e2e/plugins/proxy_rewrite.go | 66 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 2defa5dd57..d9f560ae73 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -72,41 +72,43 @@ spec: Status(200) }) - ginkgo.It("proxy rewrite request uri and host", func() { - backendSvc, backendPorts := s.DefaultHTTPBackend() - ar := fmt.Sprintf(` -apiVersion: apisix.apache.org/v2alpha1 -kind: ApisixRoute -metadata: - name: httpbin-route -spec: - http: - - name: rule1 - match: - paths: - - /hello - backends: - - serviceName: %s - servicePort: %d - weight: 10 - plugins: - - name: proxy-rewrite - enable: true - config: - uri: /ip - host: httpbin.org -`, backendSvc, backendPorts[0]) +// ginkgo.It("proxy rewrite request uri and host", 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: +// - /hello +// backends: +// - serviceName: %s +// servicePort: %d +// weight: 10 +// plugins: +// - name: proxy-rewrite +// enable: true +// config: +// uri: /ip +// host: httpbin.org +// `, backendSvc, backendPorts[0]) - assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar)) +// 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") +// 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("/hello").Expect(). - Status(200) - }) +// s.NewAPISIXClient().GET("/hello").Expect(). +// Status(200) +// }) ginkgo.It("disable plugin", func() { backendSvc, backendPorts := s.DefaultHTTPBackend() From 8d34f6e58320f741a8e90e4f5cea8c6c52c169c0 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 15:40:30 +0800 Subject: [PATCH 07/15] tese case gofmt --- test/e2e/plugins/proxy_rewrite.go | 68 +++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index d9f560ae73..1e16397dd9 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -72,43 +72,43 @@ spec: Status(200) }) -// ginkgo.It("proxy rewrite request uri and host", 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: -// - /hello -// backends: -// - serviceName: %s -// servicePort: %d -// weight: 10 -// plugins: -// - name: proxy-rewrite -// enable: true -// config: -// uri: /ip -// host: httpbin.org -// `, backendSvc, backendPorts[0]) + // ginkgo.It("proxy rewrite request uri and host", 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: + // - /hello + // backends: + // - serviceName: %s + // servicePort: %d + // weight: 10 + // plugins: + // - name: proxy-rewrite + // enable: true + // config: + // uri: /ip + // host: httpbin.org + // `, backendSvc, backendPorts[0]) -// assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar)) + // 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") + // 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("/hello").Expect(). -// Status(200) -// }) + // s.NewAPISIXClient().GET("/hello").Expect(). + // Status(200) + // }) ginkgo.It("disable plugin", func() { backendSvc, backendPorts := s.DefaultHTTPBackend() From e6182ce6bb25464dbd37dcab15a022c2d7db4ec4 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 18:31:15 +0800 Subject: [PATCH 08/15] update cases --- test/e2e/plugins/proxy_rewrite.go | 69 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 1e16397dd9..e006624dbf 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -72,43 +72,44 @@ spec: Status(200) }) - // ginkgo.It("proxy rewrite request uri and host", 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: - // - /hello - // backends: - // - serviceName: %s - // servicePort: %d - // weight: 10 - // plugins: - // - name: proxy-rewrite - // enable: true - // config: - // uri: /ip - // host: httpbin.org - // `, backendSvc, backendPorts[0]) + ginkgo.It("proxy rewrite request uri and host", 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: + - test.com + paths: + - /hello + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + uri: /ip + host: httpbin.org +`, backendSvc, backendPorts[0]) - // assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar)) + 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") + 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("/hello").Expect(). - // Status(200) - // }) + s.NewAPISIXClient().GET("/hello").WithHeader("Host", "test.com"). + Expect(). + Status(200) + }) ginkgo.It("disable plugin", func() { backendSvc, backendPorts := s.DefaultHTTPBackend() From 15759c0155f9df4d374aa313413065844676c8fb Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 19:11:00 +0800 Subject: [PATCH 09/15] delete tab key --- test/e2e/plugins/proxy_rewrite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index e006624dbf..117babec92 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -95,7 +95,7 @@ spec: - name: proxy-rewrite enable: true config: - uri: /ip + uri: /ip host: httpbin.org `, backendSvc, backendPorts[0]) From e75471968685411541a59e3854bfd72d949d6425 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Tue, 6 Apr 2021 20:55:59 +0800 Subject: [PATCH 10/15] update yaml config --- test/e2e/plugins/proxy_rewrite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 117babec92..6646bb01b7 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -83,7 +83,7 @@ spec: http: - name: rule1 match: - hosts: + hosts: - test.com paths: - /hello From b15a15adf75f57f767e4b839c3e02752c72927ed Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Thu, 8 Apr 2021 11:37:35 +0800 Subject: [PATCH 11/15] add more test case and check the body --- test/e2e/plugins/proxy_rewrite.go | 56 +++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 6646bb01b7..ec3dca2271 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -69,7 +69,9 @@ spec: s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org"). Expect(). - Status(200) + Status(200). + Body(). + Contains("origin") }) ginkgo.It("proxy rewrite request uri and host", func() { @@ -108,7 +110,53 @@ spec: s.NewAPISIXClient().GET("/hello").WithHeader("Host", "test.com"). Expect(). - Status(200) + Status(200). + Body(). + Contains("origin") + }) + + ginkgo.It("proxy rewrite request regex_uri and headers", 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: + - test.com + paths: + - /hello/ip + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + regex_uri: + - ^/hello/(.*) + - /$1 + header: + host: httpbin.org +`, 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("/hello/ip"). + Expect(). + Status(200). + Body(). + Contains("origin") }) ginkgo.It("disable plugin", func() { @@ -146,6 +194,8 @@ spec: s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org"). Expect(). - Status(404) + Status(404). + Body(). + Contains("404 Route Not Found") }) }) From 14d9f61884eea8db5cf41d0ec7d1e6a3efbdaf1c Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Thu, 8 Apr 2021 13:01:56 +0800 Subject: [PATCH 12/15] update test case --- test/e2e/plugins/proxy_rewrite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index ec3dca2271..6cca343968 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -126,8 +126,6 @@ spec: http: - name: rule1 match: - hosts: - - test.com paths: - /hello/ip backends: @@ -141,7 +139,7 @@ spec: regex_uri: - ^/hello/(.*) - /$1 - header: + headers: host: httpbin.org `, backendSvc, backendPorts[0]) From 344afe1f05a600b15274ec990978f2383e5fee01 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Thu, 8 Apr 2021 14:50:18 +0800 Subject: [PATCH 13/15] fix ci --- test/e2e/plugins/proxy_rewrite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index 6cca343968..e22f8e8e3a 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -192,8 +192,6 @@ spec: s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org"). Expect(). - Status(404). - Body(). - Contains("404 Route Not Found") + Status(404) }) }) From b99c6d4174bbb53d08570a7f540be23d067b4dcd Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Thu, 8 Apr 2021 16:55:44 +0800 Subject: [PATCH 14/15] add plugin is not effective case --- test/e2e/plugins/proxy_rewrite.go | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index e22f8e8e3a..d1ee7121ca 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -157,6 +157,48 @@ spec: Contains("origin") }) + ginkgo.It("the regex_uri of the proxy-rewrite plugin does not match", func() { + backendSvc, backendPorts := s.DefaultHTTPBackend() + ar := fmt.Sprintf(` +apiVersion: apisix.apache.org/v2alpha1 +kind: ApisixRoute +metadata: + name: httpbin-route +spec: + http: + - name: rule1 + match: + paths: + - /hello/ip + backends: + - serviceName: %s + servicePort: %d + weight: 10 + plugins: + - name: proxy-rewrite + enable: true + config: + regex_uri: + - ^/world/(.*) + - /$1 + headers: + host: httpbin.org +`, 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("/hello/ip"). + Expect(). + Status(404). + Body(). + Contains("origin") + }) + ginkgo.It("disable plugin", func() { backendSvc, backendPorts := s.DefaultHTTPBackend() ar := fmt.Sprintf(` From 753631c6125ca3b6d60eb515f54de942f254e900 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Thu, 8 Apr 2021 17:39:11 +0800 Subject: [PATCH 15/15] fix ci faild --- test/e2e/plugins/proxy_rewrite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/plugins/proxy_rewrite.go b/test/e2e/plugins/proxy_rewrite.go index d1ee7121ca..51867592af 100644 --- a/test/e2e/plugins/proxy_rewrite.go +++ b/test/e2e/plugins/proxy_rewrite.go @@ -194,9 +194,7 @@ spec: s.NewAPISIXClient().GET("/hello/ip"). Expect(). - Status(404). - Body(). - Contains("origin") + Status(404) }) ginkgo.It("disable plugin", func() {