You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by zh...@apache.org on 2022/07/01 07:41:44 UTC
[apisix-ingress-controller] branch master updated: test: support ApisixRoute v2 and split suit-plugins (#1103)
This is an automated email from the ASF dual-hosted git repository.
zhangjintao 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 4aa2ca5a test: support ApisixRoute v2 and split suit-plugins (#1103)
4aa2ca5a is described below
commit 4aa2ca5a80149e2cd5bddf8b1fb51ef2f64cfbc3
Author: Xin Rong <ro...@api7.ai>
AuthorDate: Fri Jul 1 15:41:40 2022 +0800
test: support ApisixRoute v2 and split suit-plugins (#1103)
---
.github/workflows/e2e-test-ci.yml | 2 +-
pkg/ingress/status.go | 17 +
samples/deploy/crd/v1/ApisixRoute.yaml | 12 +
test/e2e/e2e.go | 6 +-
test/e2e/scaffold/consumer.go | 19 +-
test/e2e/scaffold/ingress.go | 3 +-
test/e2e/scaffold/scaffold.go | 153 ++--
test/e2e/suite-endpoints/endpoints.go | 130 ++--
test/e2e/suite-features/consumer.go | 40 +-
test/e2e/suite-features/global_rule.go | 10 +-
test/e2e/suite-features/healthcheck.go | 90 +--
test/e2e/suite-features/remote_addrs_match.go | 59 +-
test/e2e/suite-features/retries.go | 178 ++---
test/e2e/suite-features/route_match_exprs.go | 768 +++++++++++----------
test/e2e/suite-features/scheme.go | 134 ++--
test/e2e/suite-features/subset.go | 127 ++--
test/e2e/suite-features/traffic_split.go | 142 ++--
test/e2e/suite-features/websocket.go | 84 +--
test/e2e/suite-ingress/compare.go | 2 +-
test/e2e/suite-ingress/namespace.go | 142 ++--
test/e2e/suite-ingress/resourcepushing.go | 633 ++++++++---------
test/e2e/suite-ingress/resourcesync.go | 271 ++++----
test/e2e/suite-ingress/sanity.go | 295 ++++----
test/e2e/suite-ingress/secret.go | 216 +++---
test/e2e/suite-ingress/ssl.go | 2 +-
test/e2e/suite-ingress/status.go | 48 +-
test/e2e/suite-ingress/stream.go | 93 ++-
test/e2e/suite-ingress/upstream_tls.go | 92 +--
test/e2e/suite-ingress/webhook.go | 58 +-
.../suite-plugins-general/echo.go | 236 +++++++
.../suite-plugins-general/redirect.go | 221 ++++++
.../suite-plugins-general}/server-info.go | 2 +-
.../suite-plugins-other}/plugin_config.go | 24 +-
.../suite-plugins-other}/serverless.go | 55 +-
.../suite-plugins-security/consumer-restriction.go | 231 +++++++
.../suite-plugins-security/cors.go | 331 +++++++++
.../suite-plugins-security/csrf.go | 142 ++++
.../suite-plugins-security/ip-restriction.go | 239 +++++++
.../suite-plugins-security/referer-restriction.go | 320 +++++++++
.../suite-plugins-security/uri_blocker.go | 246 +++++++
.../suite-plugins-traffic}/api_breaker.go | 93 +--
.../suite-plugins-traffic/client-control.go | 132 ++++
.../suite-plugins-traffic/limit_count.go | 240 +++++++
.../suite-plugins-traffic/request-validation.go | 197 ++++++
.../suite-plugins-traffic/request_id.go | 181 +++++
.../fault_injection.go | 244 +++++++
.../suite-plugins-transformation/proxy_rewrite.go | 241 +++++++
.../response_rewrite.go | 246 +++++++
test/e2e/suite-plugins/client-control.go | 131 ----
test/e2e/suite-plugins/consumer-restriction.go | 230 ------
test/e2e/suite-plugins/cors.go | 330 ---------
test/e2e/suite-plugins/csrf.go | 141 ----
test/e2e/suite-plugins/echo.go | 235 -------
test/e2e/suite-plugins/fault_injection.go | 243 -------
test/e2e/suite-plugins/ip-restriction.go | 238 -------
test/e2e/suite-plugins/limit_count.go | 239 -------
test/e2e/suite-plugins/proxy_rewrite.go | 240 -------
test/e2e/suite-plugins/redirect.go | 220 ------
test/e2e/suite-plugins/referer-restriction.go | 319 ---------
test/e2e/suite-plugins/request-validation.go | 196 ------
test/e2e/suite-plugins/request_id.go | 180 -----
test/e2e/suite-plugins/response_rewrite.go | 245 -------
test/e2e/suite-plugins/uri_blocker.go | 245 -------
test/e2e/testbackend/Dockerfile | 2 +-
64 files changed, 5524 insertions(+), 5357 deletions(-)
diff --git a/.github/workflows/e2e-test-ci.yml b/.github/workflows/e2e-test-ci.yml
index c24aeab5..d0cf2902 100644
--- a/.github/workflows/e2e-test-ci.yml
+++ b/.github/workflows/e2e-test-ci.yml
@@ -77,7 +77,7 @@ jobs:
- name: List test suites and set the matrix
id: set-matrix
run: |
- SUITES=($(find test/e2e -type d -iname 'suite-*' | grep -E -o '(\w|\-)*' | grep -v 'test' | grep -v 'e2e'))
+ SUITES=($(find test/e2e -type d -iname 'suite-*' | grep -E -o '(\w|\-)*' | grep -v 'test' | grep -v 'e2e' | sort | uniq))
echo $SUITES
echo "::set-output name=matrix::$(jq --compact-output --null-input '$ARGS.positional' --args "${SUITES[@]}")"
outputs:
diff --git a/pkg/ingress/status.go b/pkg/ingress/status.go
index 4a1a4975..590ac82d 100644
--- a/pkg/ingress/status.go
+++ b/pkg/ingress/status.go
@@ -121,6 +121,23 @@ func (c *Controller) recordStatus(at interface{}, reason string, err error, stat
)
}
}
+ case *configv2.ApisixRoute:
+ // set to status
+ if v.Status.Conditions == nil {
+ conditions := make([]metav1.Condition, 0)
+ v.Status.Conditions = conditions
+ }
+ if c.verifyGeneration(&v.Status.Conditions, condition) {
+ meta.SetStatusCondition(&v.Status.Conditions, condition)
+ if _, errRecord := client.ApisixV2().ApisixRoutes(v.Namespace).
+ UpdateStatus(context.TODO(), v, metav1.UpdateOptions{}); errRecord != nil {
+ log.Errorw("failed to record status change for ApisixRoute",
+ zap.Error(errRecord),
+ zap.String("name", v.Name),
+ zap.String("namespace", v.Namespace),
+ )
+ }
+ }
case *configv2beta2.ApisixRoute:
// set to status
if v.Status.Conditions == nil {
diff --git a/samples/deploy/crd/v1/ApisixRoute.yaml b/samples/deploy/crd/v1/ApisixRoute.yaml
index d0684a33..bccb647c 100644
--- a/samples/deploy/crd/v1/ApisixRoute.yaml
+++ b/samples/deploy/crd/v1/ApisixRoute.yaml
@@ -761,11 +761,23 @@ spec:
enum:
- "basicAuth"
- "keyAuth"
+ - "jwtAuth"
+ - "wolfRBAC"
+ - "hmacAuth"
keyAuth:
type: object
properties:
header:
type: string
+ jwtAuth:
+ type: object
+ properties:
+ header:
+ type: string
+ query:
+ type: string
+ cookie:
+ type: string
required:
- enable
stream:
diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go
index 64e6d62d..da2a92a9 100644
--- a/test/e2e/e2e.go
+++ b/test/e2e/e2e.go
@@ -22,7 +22,11 @@ import (
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-features"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-gateway"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-ingress"
- _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins"
+ _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-general"
+ _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-other"
+ _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-security"
+ _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-traffic"
+ _ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-transformation"
)
func runE2E() {}
diff --git a/test/e2e/scaffold/consumer.go b/test/e2e/scaffold/consumer.go
index 5aac1455..60235cf1 100644
--- a/test/e2e/scaffold/consumer.go
+++ b/test/e2e/scaffold/consumer.go
@@ -15,9 +15,7 @@
package scaffold
import (
- "errors"
"fmt"
- "strings"
)
var (
@@ -70,29 +68,20 @@ spec:
func (s *Scaffold) ApisixConsumerBasicAuthCreated(name, username, password string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuth, s.opts.APISIXConsumerVersion, name, username, password)
- return s.CreateResourceFromString(ac)
+ return s.CreateVersionedApisixResource(ac)
}
func (s *Scaffold) ApisixConsumerBasicAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
- return s.CreateResourceFromString(ac)
+ return s.CreateVersionedApisixResource(ac)
}
func (s *Scaffold) ApisixConsumerKeyAuthCreated(name, key string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuth, s.opts.APISIXConsumerVersion, name, key)
- return s.CreateResourceFromString(ac)
+ return s.CreateVersionedApisixResource(ac)
}
func (s *Scaffold) ApisixConsumerKeyAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
- return s.CreateResourceFromString(ac)
-}
-
-func (s *Scaffold) CreateVersionedApisixConsumer(yml string) error {
- if !strings.Contains(yml, "kind: ApisixConsumer") {
- return errors.New("not a ApisixConsumer")
- }
-
- ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
- return s.CreateResourceFromString(ac)
+ return s.CreateVersionedApisixResource(ac)
}
diff --git a/test/e2e/scaffold/ingress.go b/test/e2e/scaffold/ingress.go
index d9511be3..66296c44 100644
--- a/test/e2e/scaffold/ingress.go
+++ b/test/e2e/scaffold/ingress.go
@@ -235,6 +235,7 @@ spec:
initContainers:
- name: wait-apisix-admin
image: localhost:5000/busybox:1.28
+ imagePullPolicy: IfNotPresent
command: ['sh', '-c', "until nc -z apisix-service-e2e-test.%s.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"]
containers:
- livenessProbe:
@@ -263,7 +264,7 @@ spec:
fieldRef:
fieldPath: metadata.name
image: "localhost:5000/apache/apisix-ingress-controller:dev"
- imagePullPolicy: Always
+ imagePullPolicy: IfNotPresent
name: ingress-apisix-controller-deployment-e2e-test
ports:
- containerPort: 8080
diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go
index 1d03d809..4211f345 100644
--- a/test/e2e/scaffold/scaffold.go
+++ b/test/e2e/scaffold/scaffold.go
@@ -63,6 +63,7 @@ type Options struct {
disableNamespaceSelector bool
ApisixResourceSyncInterval string
EnableGatewayAPI bool
+ ApisixResourceVersion string
}
type Scaffold struct {
@@ -89,6 +90,18 @@ type Scaffold struct {
EtcdServiceFQDN string
}
+type apisixResourceVersionInfo struct {
+ V2 string
+ V2beta3 string
+}
+
+var (
+ apisixResourceVersion = &apisixResourceVersionInfo{
+ V2: "apisix.apache.org/v2",
+ V2beta3: "apisix.apache.org/v2beta3",
+ }
+)
+
// GetKubeconfig returns the kubeconfig file path.
// Order:
// env KUBECONFIG;
@@ -111,20 +124,38 @@ func GetKubeconfig() string {
// NewScaffold creates an e2e test scaffold.
func NewScaffold(o *Options) *Scaffold {
- if o.APISIXRouteVersion == "" {
- o.APISIXRouteVersion = kube.ApisixRouteV2beta3
- }
- if o.APISIXTlsVersion == "" {
- o.APISIXTlsVersion = config.ApisixV2beta3
- }
- if o.APISIXConsumerVersion == "" {
- o.APISIXConsumerVersion = config.ApisixV2beta3
- }
- if o.ApisixPluginConfigVersion == "" {
- o.ApisixPluginConfigVersion = config.ApisixV2beta3
- }
- if o.APISIXClusterConfigVersion == "" {
- o.APISIXClusterConfigVersion = config.ApisixV2beta3
+ if o.ApisixResourceVersion == ApisixResourceVersion().V2 {
+ if o.APISIXRouteVersion == "" {
+ o.APISIXRouteVersion = kube.ApisixRouteV2
+ }
+ if o.APISIXTlsVersion == "" {
+ o.APISIXTlsVersion = config.ApisixV2
+ }
+ if o.APISIXConsumerVersion == "" {
+ o.APISIXConsumerVersion = config.ApisixV2
+ }
+ if o.ApisixPluginConfigVersion == "" {
+ o.ApisixPluginConfigVersion = config.ApisixV2
+ }
+ if o.APISIXClusterConfigVersion == "" {
+ o.APISIXClusterConfigVersion = config.ApisixV2
+ }
+ } else {
+ if o.APISIXRouteVersion == "" {
+ o.APISIXRouteVersion = kube.ApisixRouteV2beta3
+ }
+ if o.APISIXTlsVersion == "" {
+ o.APISIXTlsVersion = config.ApisixV2beta3
+ }
+ if o.APISIXConsumerVersion == "" {
+ o.APISIXConsumerVersion = config.ApisixV2beta3
+ }
+ if o.ApisixPluginConfigVersion == "" {
+ o.ApisixPluginConfigVersion = config.ApisixV2beta3
+ }
+ if o.APISIXClusterConfigVersion == "" {
+ o.APISIXClusterConfigVersion = config.ApisixV2beta3
+ }
}
if o.APISIXAdminAPIKey == "" {
o.APISIXAdminAPIKey = "edd1c9f034335f136f87ad84b625c8f1"
@@ -148,19 +179,15 @@ func NewScaffold(o *Options) *Scaffold {
// NewDefaultScaffold creates a scaffold with some default options.
func NewDefaultScaffold() *Scaffold {
opts := &Options{
- Name: "default",
- Kubeconfig: GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: kube.ApisixRouteV2beta3,
- APISIXTlsVersion: config.ApisixV2beta3,
- APISIXConsumerVersion: config.ApisixV2beta3,
- ApisixPluginConfigVersion: config.ApisixV2beta3,
- APISIXClusterConfigVersion: config.ApisixV2beta3,
- EnableWebhooks: false,
- APISIXPublishAddress: "",
- EnableGatewayAPI: true,
+ Name: "default",
+ Kubeconfig: GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: ApisixResourceVersion().V2beta3,
+ EnableWebhooks: false,
+ APISIXPublishAddress: "",
+ EnableGatewayAPI: true,
}
return NewScaffold(opts)
}
@@ -168,19 +195,15 @@ func NewDefaultScaffold() *Scaffold {
// NewDefaultV2Scaffold creates a scaffold with some default options.
func NewDefaultV2Scaffold() *Scaffold {
opts := &Options{
- Name: "default",
- Kubeconfig: GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: kube.ApisixRouteV2,
- APISIXTlsVersion: config.ApisixV2,
- APISIXConsumerVersion: config.ApisixV2,
- ApisixPluginConfigVersion: config.ApisixV2,
- APISIXClusterConfigVersion: config.ApisixV2,
- EnableWebhooks: false,
- APISIXPublishAddress: "",
- EnableGatewayAPI: true,
+ Name: "default",
+ Kubeconfig: GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: ApisixResourceVersion().V2,
+ EnableWebhooks: false,
+ APISIXPublishAddress: "",
+ EnableGatewayAPI: true,
}
return NewScaffold(opts)
}
@@ -541,12 +564,19 @@ func (s *Scaffold) FormatNamespaceLabel(label string) string {
var (
versionRegex = regexp.MustCompile(`apiVersion: apisix.apache.org/v.*?\n`)
+ kindRegex = regexp.MustCompile(`kind: .*?\n`)
)
func (s *Scaffold) replaceApiVersion(yml, ver string) string {
return versionRegex.ReplaceAllString(yml, "apiVersion: "+ver+"\n")
}
+func (s *Scaffold) getKindValue(yml string) string {
+ kind := strings.Replace(kindRegex.FindString(yml), "\n", "", -1)
+ kindValue := strings.Replace(kind, "kind: ", "", -1)
+ return kindValue
+}
+
func (s *Scaffold) DisableNamespaceSelector() {
s.opts.disableNamespaceSelector = true
}
@@ -583,11 +613,40 @@ func (s *Scaffold) CreateVersionedApisixPluginConfig(yml string) error {
return s.CreateResourceFromString(ac)
}
-func (s *Scaffold) CreateVersionedApisixRoute(yml string) error {
- if !strings.Contains(yml, "kind: ApisixRoute") {
- return errors.New("not a ApisixRoute")
- }
-
- ac := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
- return s.CreateResourceFromString(ac)
+func (s *Scaffold) CreateVersionedApisixResource(yml string) error {
+ kindValue := s.getKindValue(yml)
+ switch kindValue {
+ case "ApisixRoute":
+ ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
+ return s.CreateResourceFromString(ar)
+ case "ApisixConsumer":
+ ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
+ return s.CreateResourceFromString(ac)
+ case "ApisixPluginConfig":
+ apc := s.replaceApiVersion(yml, s.opts.ApisixPluginConfigVersion)
+ return s.CreateResourceFromString(apc)
+ }
+ errString := fmt.Sprint("the resource ", kindValue, " does not support")
+ return errors.New(errString)
+}
+
+func (s *Scaffold) CreateVersionedApisixResourceWithNamespace(yml, namespace string) error {
+ kindValue := s.getKindValue(yml)
+ switch kindValue {
+ case "ApisixRoute":
+ ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
+ return s.CreateResourceFromStringWithNamespace(ar, namespace)
+ case "ApisixConsumer":
+ ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
+ return s.CreateResourceFromStringWithNamespace(ac, namespace)
+ case "ApisixPluginConfig":
+ apc := s.replaceApiVersion(yml, s.opts.ApisixPluginConfigVersion)
+ return s.CreateResourceFromStringWithNamespace(apc, namespace)
+ }
+ errString := fmt.Sprint("the resource ", kindValue, " does not support")
+ return errors.New(errString)
+}
+
+func ApisixResourceVersion() *apisixResourceVersionInfo {
+ return apisixResourceVersion
}
diff --git a/test/e2e/suite-endpoints/endpoints.go b/test/e2e/suite-endpoints/endpoints.go
index 67527f50..95f8db8a 100644
--- a/test/e2e/suite-endpoints/endpoints.go
+++ b/test/e2e/suite-endpoints/endpoints.go
@@ -26,20 +26,12 @@ import (
)
var _ = ginkgo.Describe("suite-endpoints: endpoints", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("ignore applied only if there is an ApisixRoute referenced", func() {
- time.Sleep(5 * time.Second)
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(0), "checking number of upstreams")
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ups := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("ignore applied only if there is an ApisixRoute referenced", func() {
+ time.Sleep(5 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(0), "checking number of upstreams")
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ups := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -56,14 +48,14 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ups))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ups))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
+ })
- ginkgo.It("upstream nodes should be reset to empty when Service/Endpoints was deleted", func() {
- ginkgo.Skip("now we don't handle endpoints delete event")
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("upstream nodes should be reset to empty when Service/Endpoints was deleted", func() {
+ ginkgo.Skip("now we don't handle endpoints delete event")
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -79,30 +71,29 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
- // Now delete the backend httpbin service resource.
- assert.Nil(ginkgo.GinkgoT(), s.DeleteHTTPBINService())
- time.Sleep(3 * time.Second)
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable)
+ // Now delete the backend httpbin service resource.
+ assert.Nil(ginkgo.GinkgoT(), s.DeleteHTTPBINService())
+ time.Sleep(3 * time.Second)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable)
+ })
+ }
+ ginkgo.Describe("suite-endpoints: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-endpoints: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
var _ = ginkgo.Describe("suite-endpoints: port usage", func() {
- opts := &scaffold.Options{
- Name: "endpoints-port",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 8080,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("service port != target port", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("service port != target port", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -119,27 +110,48 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- time.Sleep(12 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing APISIX upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 1)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ time.Sleep(12 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing APISIX upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 1)
- // port in nodes is still the targetPort, not the service port
- assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[0].Port, 80)
+ // port in nodes is still the targetPort, not the service port
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[0].Port, 80)
- // scale HTTPBIN, so the endpoints controller has the opportunity to update upstream.
- assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(3))
- time.Sleep(30 * time.Second)
- ups, err = s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing APISIX upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 3)
+ // scale HTTPBIN, so the endpoints controller has the opportunity to update upstream.
+ assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(3))
+ time.Sleep(30 * time.Second)
+ ups, err = s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing APISIX upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 3)
- // port in nodes is still the targetPort, not the service port
- assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[0].Port, 80)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[1].Port, 80)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[2].Port, 80)
+ // port in nodes is still the targetPort, not the service port
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[0].Port, 80)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[1].Port, 80)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Nodes[2].Port, 80)
+ })
+ }
+ ginkgo.Describe("suite-endpoints: scaffold v2beta3", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "endpoints-port",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 8080,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2beta3,
+ }))
+ })
+ ginkgo.Describe("suite-endpoints: scaffold v2", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "endpoints-port",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 8080,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2,
+ }))
})
})
diff --git a/test/e2e/suite-features/consumer.go b/test/e2e/suite-features/consumer.go
index 28575578..5c319c47 100644
--- a/test/e2e/suite-features/consumer.go
+++ b/test/e2e/suite-features/consumer.go
@@ -75,7 +75,7 @@ spec:
enable: true
type: basicAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with basicAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with basicAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -159,7 +159,7 @@ spec:
enable: true
type: basicAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with basicAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with basicAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -232,7 +232,7 @@ spec:
enable: true
type: keyAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with keyAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with keyAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -314,7 +314,7 @@ spec:
enable: true
type: keyAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with keyAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with keyAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -372,7 +372,7 @@ spec:
appid: "test-app"
header_prefix: "X-"
`, wolfSvr)
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating wolfRBAC ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating wolfRBAC ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -406,7 +406,7 @@ spec:
- name: public-api
enable: true
`, adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar1), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar1), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -431,7 +431,7 @@ spec:
enable: true
type: wolfRBAC
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar2), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar2), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(2), "Checking number of upstreams")
payload := []byte(`
@@ -497,7 +497,7 @@ spec:
secretRef:
name: rbac
`
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating wolfRBAC ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating wolfRBAC ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -531,7 +531,7 @@ spec:
- name: public-api
enable: true
`, adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar1), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar1), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -556,7 +556,7 @@ spec:
enable: true
type: wolfRBAC
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar2), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar2), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(2), "Checking number of upstreams")
payload := []byte(`
@@ -611,7 +611,7 @@ spec:
algorithm: "hmac-sha256"
clock_skew: 0
`
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating hmacAuth ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating hmacAuth ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -653,7 +653,7 @@ spec:
enable: true
type: hmacAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with hmacAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with hmacAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -717,7 +717,7 @@ spec:
secretRef:
name: hmac
`
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating hmacAuth ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating hmacAuth ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -759,7 +759,7 @@ spec:
enable: true
type: hmacAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with hmacAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with hmacAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -810,7 +810,7 @@ spec:
value:
key: foo-key
`
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating jwtAuth ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating jwtAuth ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -841,7 +841,7 @@ spec:
- name: public-api
enable: true
`, adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar1), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar1), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -915,7 +915,7 @@ spec:
secretRef:
name: jwt
`
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixConsumer(ac), "creating jwtAuth ApisixConsumer")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ac), "creating jwtAuth ApisixConsumer")
// Wait until the ApisixConsumer create event was delivered.
time.Sleep(6 * time.Second)
@@ -946,7 +946,7 @@ spec:
- name: public-api
enable: true
`, adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar1), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar1), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
@@ -971,7 +971,7 @@ spec:
enable: true
type: jwtAuth
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar2), "Creating ApisixRoute with jwtAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar2), "Creating ApisixRoute with jwtAuth")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(2), "Checking number of upstreams")
@@ -1025,7 +1025,7 @@ spec:
authentication:
enable: false
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute without authentication")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute without authentication")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
diff --git a/test/e2e/suite-features/global_rule.go b/test/e2e/suite-features/global_rule.go
index a5c8f9b6..56858020 100644
--- a/test/e2e/suite-features/global_rule.go
+++ b/test/e2e/suite-features/global_rule.go
@@ -60,7 +60,7 @@ spec:
enable: true
`, adminSvc, adminPort)
- err := s.CreateResourceFromString(ar)
+ err := s.CreateVersionedApisixResource(ar)
assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRouteConfig")
time.Sleep(3 * time.Second)
@@ -81,6 +81,10 @@ spec:
})
}
- suites(scaffold.NewDefaultScaffold)
- suites(scaffold.NewDefaultV2Scaffold)
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
})
diff --git a/test/e2e/suite-features/healthcheck.go b/test/e2e/suite-features/healthcheck.go
index a3cd5bb4..b37c3ea4 100644
--- a/test/e2e/suite-features/healthcheck.go
+++ b/test/e2e/suite-features/healthcheck.go
@@ -25,19 +25,12 @@ import (
)
var _ = ginkgo.Describe("suite-features: health check", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("active check", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("active check", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
- au := fmt.Sprintf(`
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -54,10 +47,10 @@ spec:
httpFailures: 2
interval: 1s
`, backendSvc)
- err := s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ err := s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- ar := fmt.Sprintf(`
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -74,27 +67,27 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendPorts[0])
- err = s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
+ err = s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(3 * time.Second)
+ time.Sleep(3 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, nil, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.Interval, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.HTTPStatuses, []int{200})
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.Interval, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.HTTPFailures, 2)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, nil, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.Interval, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.HTTPStatuses, []int{200})
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.Interval, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.HTTPFailures, 2)
- // It's difficult to test healthchecker since we cannot let partial httpbin endpoints
- // down, if all of them are down, apisix in turn uses all of them.
- })
+ // It's difficult to test healthchecker since we cannot let partial httpbin endpoints
+ // down, if all of them are down, apisix in turn uses all of them.
+ })
- ginkgo.It("passive check", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ginkgo.It("passive check", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
- au := fmt.Sprintf(`
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -116,10 +109,10 @@ spec:
unhealthy:
httpCodes: [502]
`, backendSvc)
- err := s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ err := s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- ar := fmt.Sprintf(`
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -136,17 +129,24 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendPorts[0])
- err = s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
+ err = s.CreateResourceFromString(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(3 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, nil, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.Interval, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.HTTPStatuses, []int{200})
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.Interval, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Passive.Healthy.HTTPStatuses, []int{200})
- assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Passive.Unhealthy.HTTPStatuses, []int{502})
+ time.Sleep(3 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, nil, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.Interval, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Healthy.HTTPStatuses, []int{200})
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Active.Unhealthy.Interval, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Passive.Healthy.HTTPStatuses, []int{200})
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Checks.Passive.Unhealthy.HTTPStatuses, []int{502})
+ })
+ }
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/remote_addrs_match.go b/test/e2e/suite-features/remote_addrs_match.go
index f48326fd..fa727ce8 100644
--- a/test/e2e/suite-features/remote_addrs_match.go
+++ b/test/e2e/suite-features/remote_addrs_match.go
@@ -25,18 +25,11 @@ import (
)
var _ = ginkgo.Describe("suite-features: traffic split", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("sanity", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -55,18 +48,18 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
- resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusNotFound)
- resp.Body().Contains("404 Route Not Found")
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusNotFound)
+ resp.Body().Contains("404 Route Not Found")
- ar = fmt.Sprintf(`
+ ar = fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -86,15 +79,23 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ })
+ }
- resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusOK)
- resp.Body().Contains("origin")
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/retries.go b/test/e2e/suite-features/retries.go
index 95b8fe82..e8c8a538 100644
--- a/test/e2e/suite-features/retries.go
+++ b/test/e2e/suite-features/retries.go
@@ -25,17 +25,10 @@ import (
)
var _ = ginkgo.Describe("suite-features: retries", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
- routeTpl := `
+ routeTpl := `
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -52,38 +45,38 @@ spec:
- serviceName: %s
servicePort: %d
`
- ginkgo.It("is missing", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
- err := s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(5 * time.Second)
-
- au := fmt.Sprintf(`
+ ginkgo.It("is missing", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
+ err := s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(5 * time.Second)
+
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
name: %s
spec:
`, backendSvc)
- err = s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(2 * time.Second)
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Nil(ginkgo.GinkgoT(), ups[0].Retries)
- })
-
- ginkgo.It("is zero", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
- err := s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(5 * time.Second)
-
- au := fmt.Sprintf(`
+ err = s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(2 * time.Second)
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Nil(ginkgo.GinkgoT(), ups[0].Retries)
+ })
+
+ ginkgo.It("is zero", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
+ err := s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(5 * time.Second)
+
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -91,24 +84,24 @@ metadata:
spec:
retries: 0
`, backendSvc)
- err = s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(2 * time.Second)
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), *ups[0].Retries, 0)
- })
-
- ginkgo.It("is a positive number", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
- err := s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(5 * time.Second)
-
- au := fmt.Sprintf(`
+ err = s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(2 * time.Second)
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), *ups[0].Retries, 0)
+ })
+
+ ginkgo.It("is a positive number", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(routeTpl, backendSvc, backendPorts[0])
+ err := s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(5 * time.Second)
+
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -116,31 +109,32 @@ metadata:
spec:
retries: 3
`, backendSvc)
- err = s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(2 * time.Second)
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), *ups[0].Retries, 3)
+ err = s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(2 * time.Second)
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), *ups[0].Retries, 3)
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
var _ = ginkgo.Describe("suite-features: retries timeout", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("active check", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("active check", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
- au := fmt.Sprintf(`
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -150,11 +144,11 @@ spec:
read: 10s
send: 10s
`, backendSvc)
- err := s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(2 * time.Second)
+ err := s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(2 * time.Second)
- ar := fmt.Sprintf(`
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -171,15 +165,23 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendPorts[0])
- err = s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(5 * time.Second)
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Connect, 60)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Read, 10)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Send, 10)
+ err = s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(5 * time.Second)
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Connect, 60)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Read, 10)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Timeout.Send, 10)
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/route_match_exprs.go b/test/e2e/suite-features/route_match_exprs.go
index c02d9c25..ffbd09c0 100644
--- a/test/e2e/suite-features/route_match_exprs.go
+++ b/test/e2e/suite-features/route_match_exprs.go
@@ -26,19 +26,12 @@ import (
)
var _ = ginkgo.Describe("suite-features: route match exprs", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("operator is equal", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("operator is equal", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -62,34 +55,34 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- time.Sleep(6 * time.Second)
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Foo", "bar").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Foo", "baz").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is not_equal", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Foo", "bar").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Foo", "baz").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is not_equal", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -113,32 +106,32 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Foo", "bar").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
- ginkgo.It("operator is greater_than", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ 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")
- ar := fmt.Sprintf(`
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Foo", "bar").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is greater_than", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -162,42 +155,42 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- time.Sleep(6 * time.Second)
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithQuery("id", 100).
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithQuery("id", 3).
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- msg = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is less_than", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithQuery("id", 100).
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithQuery("id", 3).
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ msg = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is less_than", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -221,42 +214,42 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- time.Sleep(6 * time.Second)
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithQuery("id", 12).
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithQuery("id", 13).
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- msg = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is in", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithQuery("id", 12).
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithQuery("id", 13).
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ msg = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is in", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -280,41 +273,41 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Content-Type", "text/html").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Content-Type", "image/png").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- msg = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is not_in", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Content-Type", "text/html").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Content-Type", "image/png").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ msg = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is not_in", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -338,40 +331,40 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Content-Type", "text/png").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Content-Type", "image/jpeg").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK).
- Body().
- Raw()
- })
-
- ginkgo.It("operator is regex match", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Content-Type", "text/png").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Content-Type", "image/jpeg").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK).
+ Body().
+ Raw()
+ })
+
+ ginkgo.It("operator is regex match", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -395,42 +388,42 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
- time.Sleep(6 * time.Second)
-
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/ip/098/v4").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/ip/0983/v4").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- msg = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is regex not match", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+ time.Sleep(6 * time.Second)
+
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/ip/098/v4").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/ip/0983/v4").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ msg = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is regex not match", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -454,41 +447,41 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- time.Sleep(6 * time.Second)
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/ip/0983/v4").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/ip/098/v4").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK).
- Body().
- Raw()
- })
-
- ginkgo.It("operator is regex match in case insensitive mode", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/ip/0983/v4").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/ip/098/v4").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK).
+ Body().
+ Raw()
+ })
+
+ ginkgo.It("operator is regex match in case insensitive mode", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -512,42 +505,42 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- time.Sleep(6 * time.Second)
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/IP/098/v4").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/ip/0983/v4").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- msg = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
- })
-
- ginkgo.It("operator is regex not match in case insensitive mode", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/IP/098/v4").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/ip/0983/v4").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ msg = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+ })
+
+ ginkgo.It("operator is regex not match in case insensitive mode", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -571,51 +564,52 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- 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")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/IP/0983/v4").
- Expect().
- Status(http.StatusOK)
-
- msg := s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/IP/098/v4").
- Expect().
- Status(http.StatusNotFound).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK).
- Body().
- Raw()
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ 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")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/IP/0983/v4").
+ Expect().
+ Status(http.StatusOK)
+
+ msg := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/IP/098/v4").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg, "404 Route Not Found")
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK).
+ Body().
+ Raw()
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
var _ = ginkgo.Describe("suite-features: route match exprs bugfixes", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("exprs scope", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("exprs scope", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -648,36 +642,44 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0], backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- err := s.EnsureNumApisixRoutesCreated(2)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
- time.Sleep(6 * time.Second)
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
-
- routes, err := s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), routes, 2)
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/IP/093/v4").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("X-Real-Uri", "/IP/0981/v4").
- Expect().
- Status(http.StatusNotFound).
- Body().Contains("404 Route Not Found")
-
- // If the exprs in rule1 escaped to rulel2, then the following request
- // will throw 404 Route Not Found.
- _ = s.NewAPISIXClient().GET("/headers").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK).
- Body().Contains("httpbin.org")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ err := s.EnsureNumApisixRoutesCreated(2)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+ time.Sleep(6 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+
+ routes, err := s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), routes, 2)
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/IP/093/v4").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("X-Real-Uri", "/IP/0981/v4").
+ Expect().
+ Status(http.StatusNotFound).
+ Body().Contains("404 Route Not Found")
+
+ // If the exprs in rule1 escaped to rulel2, then the following request
+ // will throw 404 Route Not Found.
+ _ = s.NewAPISIXClient().GET("/headers").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK).
+ Body().Contains("httpbin.org")
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/scheme.go b/test/e2e/suite-features/scheme.go
index a53c833c..6574001c 100644
--- a/test/e2e/suite-features/scheme.go
+++ b/test/e2e/suite-features/scheme.go
@@ -27,17 +27,11 @@ import (
)
var _ = ginkgo.Describe("suite-features: choose scheme", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("grpc", func() {
- err := s.CreateResourceFromString(`
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+
+ ginkgo.It("grpc", func() {
+ err := s.CreateResourceFromString(`
apiVersion: v1
kind: Pod
metadata:
@@ -62,8 +56,8 @@ spec:
protocol: TCP
targetPort: 50051
`)
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -73,7 +67,7 @@ spec:
- port: 50051
scheme: grpc
`))
- err = s.CreateResourceFromString(`
+ err = s.CreateVersionedApisixResource(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -90,52 +84,52 @@ spec:
- serviceName: grpc-server-service
servicePort: 50051
`)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(2 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Scheme, "grpc")
-
- // TODO enable the following test cases once APISIX supports HTTP/2 in plain.
- // ep, err := s.GetAPISIXEndpoint()
- // assert.Nil(ginkgo.GinkgoT(), err)
- // ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- // defer cancel()
- // dialFunc := func(ctx context.Context, addr string) (net.Conn, error) {
- // return (&net.Dialer{}).DialContext(ctx, "tcp", addr)
- // }
- //
- // grpcConn, err := grpc.DialContext(ctx, ep,
- // grpc.WithBlock(),
- // grpc.WithInsecure(),
- // grpc.WithContextDialer(dialFunc),
- // )
- // assert.Nil(ginkgo.GinkgoT(), err)
- // defer grpcConn.Close()
- // cli := helloworld.NewGreeterClient(grpcConn)
- // hr := &helloworld.HelloRequest{
- // Name: "Alex",
- // }
- // resp, err := cli.SayHello(context.TODO(), hr)
- // assert.Nil(ginkgo.GinkgoT(), err)
- // assert.Equal(ginkgo.GinkgoT(), resp.Message, "Alex")
- })
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(2 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Scheme, "grpc")
+
+ // TODO enable the following test cases once APISIX supports HTTP/2 in plain.
+ // ep, err := s.GetAPISIXEndpoint()
+ // assert.Nil(ginkgo.GinkgoT(), err)
+ // ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ // defer cancel()
+ // dialFunc := func(ctx context.Context, addr string) (net.Conn, error) {
+ // return (&net.Dialer{}).DialContext(ctx, "tcp", addr)
+ // }
+ //
+ // grpcConn, err := grpc.DialContext(ctx, ep,
+ // grpc.WithBlock(),
+ // grpc.WithInsecure(),
+ // grpc.WithContextDialer(dialFunc),
+ // )
+ // assert.Nil(ginkgo.GinkgoT(), err)
+ // defer grpcConn.Close()
+ // cli := helloworld.NewGreeterClient(grpcConn)
+ // hr := &helloworld.HelloRequest{
+ // Name: "Alex",
+ // }
+ // resp, err := cli.SayHello(context.TODO(), hr)
+ // assert.Nil(ginkgo.GinkgoT(), err)
+ // assert.Equal(ginkgo.GinkgoT(), resp.Message, "Alex")
+ })
- ginkgo.It("grpcs", func() {
- grpcSecret := `grpc-secret`
- f, err := ioutil.ReadFile("testbackend/tls/server.pem")
- assert.NoError(ginkgo.GinkgoT(), err, "read server cert")
- serverCert := string(f)
+ ginkgo.It("grpcs", func() {
+ grpcSecret := `grpc-secret`
+ f, err := ioutil.ReadFile("testbackend/tls/server.pem")
+ assert.NoError(ginkgo.GinkgoT(), err, "read server cert")
+ serverCert := string(f)
- f, err = ioutil.ReadFile("testbackend/tls/server.key")
- assert.NoError(ginkgo.GinkgoT(), err, "read server key")
- serverKey := string(f)
+ f, err = ioutil.ReadFile("testbackend/tls/server.key")
+ assert.NoError(ginkgo.GinkgoT(), err, "read server key")
+ serverKey := string(f)
- err = s.NewSecret(grpcSecret, serverCert, serverKey)
- assert.NoError(ginkgo.GinkgoT(), err, "create server cert secret")
+ err = s.NewSecret(grpcSecret, serverCert, serverKey)
+ assert.NoError(ginkgo.GinkgoT(), err, "create server cert secret")
- assert.NoError(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ assert.NoError(ginkgo.GinkgoT(), s.CreateResourceFromString(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -144,7 +138,7 @@ spec:
scheme: grpcs
`))
- assert.NoError(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ assert.NoError(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(`
apiVersion: apisix.apache.org/v2beta2
kind: ApisixRoute
metadata:
@@ -162,16 +156,24 @@ spec:
servicePort: 50052
`))
- assert.NoError(ginkgo.GinkgoT(), s.NewApisixTls("grpc-secret", "e2e.apisix.local", "grpc-secret"))
+ assert.NoError(ginkgo.GinkgoT(), s.NewApisixTls("grpc-secret", "e2e.apisix.local", "grpc-secret"))
- time.Sleep(2 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Scheme, "grpcs")
+ time.Sleep(2 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Scheme, "grpcs")
- ca, err := ioutil.ReadFile("testbackend/tls/ca.pem")
- assert.NoError(ginkgo.GinkgoT(), err, "read ca cert")
- assert.NoError(ginkgo.GinkgoT(), client.RequestHello(s.GetAPISIXHTTPSEndpoint(), ca), "request apisix using grpc protocol")
+ ca, err := ioutil.ReadFile("testbackend/tls/ca.pem")
+ assert.NoError(ginkgo.GinkgoT(), err, "read ca cert")
+ assert.NoError(ginkgo.GinkgoT(), client.RequestHello(s.GetAPISIXHTTPSEndpoint(), ca), "request apisix using grpc protocol")
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/subset.go b/test/e2e/suite-features/subset.go
index 4e96e056..b35477ee 100644
--- a/test/e2e/suite-features/subset.go
+++ b/test/e2e/suite-features/subset.go
@@ -26,20 +26,13 @@ import (
)
var _ = ginkgo.Describe("suite-features: service subset", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("subset not found", func() {
- assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
- assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("subset not found", func() {
+ assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
+ assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -57,23 +50,23 @@ spec:
servicePort: %d
subset: not_exist
`, backendSvc, backendSvcPort[0])
- err := s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
+ err := s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 0, "upstreams nodes not expect")
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 0, "upstreams nodes not expect")
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable).Body().Raw()
- })
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable).Body().Raw()
+ })
- ginkgo.It("subset with bad labels", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- au := fmt.Sprintf(`
+ ginkgo.It("subset with bad labels", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -85,10 +78,10 @@ spec:
aa: bb
cc: dd
`, backendSvc)
- err := s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(1 * time.Second)
- ar := fmt.Sprintf(`
+ err := s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(1 * time.Second)
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -106,26 +99,26 @@ spec:
servicePort: %d
subset: aa
`, backendSvc, backendSvcPort[0])
- err = s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
- time.Sleep(3 * time.Second)
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 0, "upstreams nodes not expect")
-
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable).Body().Raw()
- })
+ err = s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
+ time.Sleep(3 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 0, "upstreams nodes not expect")
- ginkgo.It("subset with good labels - all", func() {
- assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
- assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusServiceUnavailable).Body().Raw()
+ })
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- au := fmt.Sprintf(`
+ ginkgo.It("subset with good labels - all", func() {
+ assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
+ assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
+
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ au := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixUpstream
metadata:
@@ -136,10 +129,10 @@ spec:
labels:
app: httpbin-deployment-e2e-test
`, backendSvc)
- err := s.CreateResourceFromString(au)
- assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
- time.Sleep(1 * time.Second)
- ar := fmt.Sprintf(`
+ err := s.CreateResourceFromString(au)
+ assert.Nil(ginkgo.GinkgoT(), err, "create ApisixUpstream")
+ time.Sleep(1 * time.Second)
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -157,18 +150,26 @@ spec:
servicePort: %d
subset: all
`, backendSvc, backendSvcPort[0])
- err = s.CreateResourceFromString(ar)
- assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
+ err = s.CreateVersionedApisixResource(ar)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixRoute")
+
+ time.Sleep(6 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
- time.Sleep(6 * time.Second)
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 2, "upstreams nodes not expect")
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 2, "upstreams nodes not expect")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ })
+ }
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/traffic_split.go b/test/e2e/suite-features/traffic_split.go
index 130f6629..698596b5 100644
--- a/test/e2e/suite-features/traffic_split.go
+++ b/test/e2e/suite-features/traffic_split.go
@@ -26,19 +26,13 @@ import (
)
var _ = ginkgo.Describe("suite-features: traffic split", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("sanity", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- adminSvc, adminPort := s.ApisixAdminServiceAndPort()
- ar := fmt.Sprintf(`
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ adminSvc, adminPort := s.ApisixAdminServiceAndPort()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -60,41 +54,41 @@ spec:
weight: 5
`, backendSvc, backendPorts[0], adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
- err := s.EnsureNumApisixUpstreamsCreated(2)
- 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(2)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
- // Send requests to APISIX.
- var (
- num404 int
- num200 int
- )
- for i := 0; i < 90; i++ {
- // For requests sent to http-admin, 404 will be given.
- // For requests sent to httpbin, 200 will be given.
- resp := s.NewAPISIXClient().GET("/get").WithHeader("Host", "httpbin.org").Expect()
- status := resp.Raw().StatusCode
- if status != http.StatusOK && status != http.StatusNotFound {
- assert.FailNow(ginkgo.GinkgoT(), "invalid status code")
+ // Send requests to APISIX.
+ var (
+ num404 int
+ num200 int
+ )
+ for i := 0; i < 90; i++ {
+ // For requests sent to http-admin, 404 will be given.
+ // For requests sent to httpbin, 200 will be given.
+ resp := s.NewAPISIXClient().GET("/get").WithHeader("Host", "httpbin.org").Expect()
+ status := resp.Raw().StatusCode
+ if status != http.StatusOK && status != http.StatusNotFound {
+ assert.FailNow(ginkgo.GinkgoT(), "invalid status code")
+ }
+ if status == 200 {
+ num200++
+ resp.Body().Contains("origin")
+ } else {
+ num404++
+ }
}
- if status == 200 {
- num200++
- resp.Body().Contains("origin")
- } else {
- num404++
- }
- }
- dev := math.Abs(float64(num200)/float64(num404) - float64(2))
- assert.Less(ginkgo.GinkgoT(), dev, 0.2)
- })
+ dev := math.Abs(float64(num200)/float64(num404) - float64(2))
+ assert.Less(ginkgo.GinkgoT(), dev, 0.2)
+ })
- ginkgo.It("zero-weight", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- adminSvc, adminPort := s.ApisixAdminServiceAndPort()
- ar := fmt.Sprintf(`
+ ginkgo.It("zero-weight", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ adminSvc, adminPort := s.ApisixAdminServiceAndPort()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -116,34 +110,42 @@ spec:
weight: 0
`, backendSvc, backendPorts[0], adminSvc, adminPort)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
- err := s.EnsureNumApisixUpstreamsCreated(2)
- 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(2)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
- // Send requests to APISIX.
- var (
- num404 int
- num200 int
- )
- for i := 0; i < 90; i++ {
- // For requests sent to http-admin, 404 will be given.
- // For requests sent to httpbin, 200 will be given.
- resp := s.NewAPISIXClient().GET("/get").WithHeader("Host", "httpbin.org").Expect()
- status := resp.Raw().StatusCode
- if status != http.StatusOK && status != http.StatusNotFound {
- assert.FailNow(ginkgo.GinkgoT(), "invalid status code")
+ // Send requests to APISIX.
+ var (
+ num404 int
+ num200 int
+ )
+ for i := 0; i < 90; i++ {
+ // For requests sent to http-admin, 404 will be given.
+ // For requests sent to httpbin, 200 will be given.
+ resp := s.NewAPISIXClient().GET("/get").WithHeader("Host", "httpbin.org").Expect()
+ status := resp.Raw().StatusCode
+ if status != http.StatusOK && status != http.StatusNotFound {
+ assert.FailNow(ginkgo.GinkgoT(), "invalid status code")
+ }
+ if status == 200 {
+ num200++
+ resp.Body().Contains("origin")
+ } else {
+ num404++
+ }
}
- if status == 200 {
- num200++
- resp.Body().Contains("origin")
- } else {
- num404++
- }
- }
- assert.Equal(ginkgo.GinkgoT(), num404, 0)
- assert.Equal(ginkgo.GinkgoT(), num200, 90)
+ assert.Equal(ginkgo.GinkgoT(), num404, 0)
+ assert.Equal(ginkgo.GinkgoT(), num200, 90)
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-features/websocket.go b/test/e2e/suite-features/websocket.go
index d57d3614..e2402672 100644
--- a/test/e2e/suite-features/websocket.go
+++ b/test/e2e/suite-features/websocket.go
@@ -27,17 +27,11 @@ import (
)
var _ = ginkgo.Describe("suite-features: websocket", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("sanity", func() {
- resources := `
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+
+ ginkgo.It("sanity", func() {
+ resources := `
apiVersion: v1
kind: Pod
metadata:
@@ -64,11 +58,11 @@ spec:
protocol: TCP
targetPort: 8080
`
- err := s.CreateResourceFromString(resources)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(5 * time.Second)
+ err := s.CreateResourceFromString(resources)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(5 * time.Second)
- ar := `
+ ar := `
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -86,33 +80,41 @@ spec:
- serviceName: websocket-server-service
servicePort: 48733
`
- 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")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
- dialer := websocket.Dialer{}
- u := url.URL{
- Scheme: "ws",
- Host: s.APISIXGatewayServiceEndpoint(),
- Path: "/echo",
- }
- header := http.Header{
- "Host": []string{"httpbin.org"},
- }
- conn, resp, err := dialer.Dial(u.String(), header)
- assert.Nil(ginkgo.GinkgoT(), err, "websocket handshake failure")
- assert.Equal(ginkgo.GinkgoT(), resp.StatusCode, http.StatusSwitchingProtocols)
+ dialer := websocket.Dialer{}
+ u := url.URL{
+ Scheme: "ws",
+ Host: s.APISIXGatewayServiceEndpoint(),
+ Path: "/echo",
+ }
+ header := http.Header{
+ "Host": []string{"httpbin.org"},
+ }
+ conn, resp, err := dialer.Dial(u.String(), header)
+ assert.Nil(ginkgo.GinkgoT(), err, "websocket handshake failure")
+ assert.Equal(ginkgo.GinkgoT(), resp.StatusCode, http.StatusSwitchingProtocols)
- assert.Nil(ginkgo.GinkgoT(), conn.WriteMessage(websocket.TextMessage, []byte("hello, I'm gorilla")), "writing message")
- msgType, buf, err := conn.ReadMessage()
- assert.Nil(ginkgo.GinkgoT(), err, "reading message")
- assert.Equal(ginkgo.GinkgoT(), string(buf), "Request served by websocket-server")
- msgType, buf, err = conn.ReadMessage()
- assert.Nil(ginkgo.GinkgoT(), err, "reading message")
- assert.Equal(ginkgo.GinkgoT(), msgType, websocket.TextMessage)
- assert.Equal(ginkgo.GinkgoT(), string(buf), "hello, I'm gorilla")
- assert.Nil(ginkgo.GinkgoT(), conn.Close(), "closing ws connection")
+ assert.Nil(ginkgo.GinkgoT(), conn.WriteMessage(websocket.TextMessage, []byte("hello, I'm gorilla")), "writing message")
+ msgType, buf, err := conn.ReadMessage()
+ assert.Nil(ginkgo.GinkgoT(), err, "reading message")
+ assert.Equal(ginkgo.GinkgoT(), string(buf), "Request served by websocket-server")
+ msgType, buf, err = conn.ReadMessage()
+ assert.Nil(ginkgo.GinkgoT(), err, "reading message")
+ assert.Equal(ginkgo.GinkgoT(), msgType, websocket.TextMessage)
+ assert.Equal(ginkgo.GinkgoT(), string(buf), "hello, I'm gorilla")
+ assert.Nil(ginkgo.GinkgoT(), conn.Close(), "closing ws connection")
+ })
+ }
+
+ ginkgo.Describe("suite-features: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-features: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-ingress/compare.go b/test/e2e/suite-ingress/compare.go
index 5330da02..6c0a5b2f 100644
--- a/test/e2e/suite-ingress/compare.go
+++ b/test/e2e/suite-ingress/compare.go
@@ -46,7 +46,7 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixRoute(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
err := s.EnsureNumApisixRoutesCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
diff --git a/test/e2e/suite-ingress/namespace.go b/test/e2e/suite-ingress/namespace.go
index 712784af..19c1ad2e 100644
--- a/test/e2e/suite-ingress/namespace.go
+++ b/test/e2e/suite-ingress/namespace.go
@@ -37,81 +37,68 @@ type headers struct {
}
var _ = ginkgo.Describe("suite-ingress: namespacing filtering enable", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
+ s := scaffold.NewDefaultScaffold()
+
ginkgo.Context("with namespace_selector", func() {
ginkgo.It("resources in other namespaces should be ignored", func() {
backendSvc, backendSvcPort := s.DefaultHTTPBackend()
route := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
+apiVersion: networking.k8s.io/v1
+kind: Ingress
metadata:
name: httpbin-route
spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.com
+ ingressClassName: apisix
+ rules:
+ - host: httpbin.com
+ http:
paths:
- - /ip
- backends:
- - serviceName: %s
- servicePort: %d
+ - path: /ip
+ pathType: Exact
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating ingress")
time.Sleep(6 * time.Second)
- // assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "checking number of routes")
- // assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "checking number of upstreams")
body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
var placeholder ip
err := json.Unmarshal([]byte(body), &placeholder)
assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
- // Now create another ApisixRoute in default namespace.
+ // Now create another ingress in default namespace.
route = fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
+apiVersion: networking.k8s.io/v1
+kind: Ingress
metadata:
- name: httpbin-route
+ name: httpbin-route
spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.com
+ ingressClassName: apisix
+ rules:
+ - host: httpbin.com
+ http:
paths:
- - /headers
- backends:
- - serviceName: %s
- servicePort: %d
+ - path: /headers
+ pathType: Exact
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ingress")
_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
})
})
})
var _ = ginkgo.Describe("suite-ingress: namespacing filtering disable", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
+ s := scaffold.NewDefaultScaffold()
ginkgo.Context("without namespace_selector", func() {
// make namespace_selector empty
s.DisableNamespaceSelector()
@@ -136,46 +123,50 @@ var _ = ginkgo.Describe("suite-ingress: namespacing filtering disable", func() {
ginkgo.It("all resources will be watched", func() {
backendSvc, backendSvcPort := s.DefaultHTTPBackend()
route := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
+apiVersion: networking.k8s.io/v1
+kind: Ingress
metadata:
- name: httpbin-route
+ name: ingress-httpbin.com
spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.com
+ ingressClassName: apisix
+ rules:
+ - host: local.httpbin.org.host.only.734212
+ http:
paths:
- - /ip
- backends:
- - serviceName: %s
- servicePort: %d
+ - path: /ip
+ pathType: Exact
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating first ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating first ingress")
time.Sleep(3 * time.Second)
- // Now create another ApisixRoute in another namespace.
+ // Now create another ingress in another namespace.
backendSvc, backendSvcPort = s.DefaultHTTPBackend()
route = fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
+apiVersion: networking.k8s.io/v1
+kind: Ingress
metadata:
- name: httpbin-route-second-httpbin-service-namespace
+ name: ingress-second-httpbin-service-namespace.httpbin.com
spec:
- http:
- - name: rule1
- match:
- hosts:
- - second-httpbin-service-namespace.httpbin.com
+ ingressClassName: apisix
+ rules:
+ - host: second-httpbin-service-namespace.httpbin.com
+ http:
paths:
- - /headers
- backends:
- - serviceName: %s
- servicePort: %d
+ - path: /headers
+ pathType: Exact
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, namespace), "creating second ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, namespace), "creating second ingress")
// restart ingress-controller
pods, err := s.GetIngressPodDetails()
@@ -184,11 +175,8 @@ spec:
ginkgo.GinkgoT().Logf("restart apisix-ingress-controller pod %s", pods[0].Name)
assert.Nil(ginkgo.GinkgoT(), s.KillPod(pods[0].Name))
time.Sleep(6 * time.Second)
- // Two ApisixRoutes have been created at this time.
- // assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2), "checking number of routes")
- // assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(2), "checking number of upstreams")
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "local.httpbin.org.host.only.734212").Expect().Status(http.StatusOK).Body().Raw()
var placeholder ip
err = json.Unmarshal([]byte(body), &placeholder)
assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
diff --git a/test/e2e/suite-ingress/resourcepushing.go b/test/e2e/suite-ingress/resourcepushing.go
index c6644277..c958a7fa 100644
--- a/test/e2e/suite-ingress/resourcepushing.go
+++ b/test/e2e/suite-ingress/resourcepushing.go
@@ -26,18 +26,11 @@ import (
)
var _ = ginkgo.Describe("suite-ingress: ApisixRoute Testing", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("create and then scale upstream pods to 2 ", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("create and then scale upstream pods to 2 ", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -54,26 +47,26 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
-
- 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")
- assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
- assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(10 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
- assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 2, "upstreams nodes not expect")
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
+
+ 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")
+ assert.Nil(ginkgo.GinkgoT(), s.ScaleHTTPBIN(2), "scaling number of httpbin instances")
+ assert.Nil(ginkgo.GinkgoT(), s.WaitAllHTTPBINPodsAvailable(), "waiting for all httpbin pods ready")
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(10 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
+ assert.Len(ginkgo.GinkgoT(), ups[0].Nodes, 2, "upstreams nodes not expect")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ })
- ginkgo.It("create, update, then remove", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("create, update, then remove", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -91,18 +84,18 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- 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.EnsureNumApisixPluginConfigCreated(0)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ 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.EnsureNumApisixPluginConfigCreated(0)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
- // update
- apisixRoute = fmt.Sprintf(`
+ // update
+ apisixRoute = fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -126,40 +119,40 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(10 * time.Second)
-
- 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.EnsureNumApisixPluginConfigCreated(0)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
-
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbaz").Expect().Status(http.StatusOK)
-
- // remove
- assert.Nil(ginkgo.GinkgoT(), s.RemoveResourceByString(apisixRoute))
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(10 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
- assert.Len(ginkgo.GinkgoT(), ups, 0, "upstreams nodes not expect")
- pluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "list pluginConfigs error")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0, "pluginConfigs nodes not expect")
-
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound).Body().Raw()
- assert.Contains(ginkgo.GinkgoT(), body, "404 Route Not Found")
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(10 * time.Second)
+
+ 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.EnsureNumApisixPluginConfigCreated(0)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbaz").Expect().Status(http.StatusOK)
+
+ // remove
+ assert.Nil(ginkgo.GinkgoT(), s.RemoveResourceByString(apisixRoute))
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(10 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
+ assert.Len(ginkgo.GinkgoT(), ups, 0, "upstreams nodes not expect")
+ pluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "list pluginConfigs error")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0, "pluginConfigs nodes not expect")
+
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound).Body().Raw()
+ assert.Contains(ginkgo.GinkgoT(), body, "404 Route Not Found")
+ })
- ginkgo.It("create, update, remove k8s service, remove ApisixRoute", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("create, update, remove k8s service, remove ApisixRoute", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -177,18 +170,18 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- 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.EnsureNumApisixPluginConfigCreated(0)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ 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.EnsureNumApisixPluginConfigCreated(0)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
- // update
- apisixRoute = fmt.Sprintf(`
+ // update
+ apisixRoute = fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -212,41 +205,41 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(10 * time.Second)
-
- 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.EnsureNumApisixPluginConfigCreated(0)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
-
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbaz").Expect().Status(http.StatusOK)
- // remove k8s service first
- // assert.Nil(ginkgo.GinkgoT(), s.DeleteHTTPBINService())
- // remove
- assert.Nil(ginkgo.GinkgoT(), s.RemoveResourceByString(apisixRoute))
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(10 * time.Second)
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
- assert.Len(ginkgo.GinkgoT(), ups, 0, "upstreams nodes not expect")
- pluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "list pluginConfigs error")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0, "pluginConfigs nodes not expect")
-
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound).Body().Raw()
- assert.Contains(ginkgo.GinkgoT(), body, "404 Route Not Found")
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(10 * time.Second)
+
+ 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.EnsureNumApisixPluginConfigCreated(0)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of pluginConfigs")
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbaz").Expect().Status(http.StatusOK)
+ // remove k8s service first
+ // assert.Nil(ginkgo.GinkgoT(), s.DeleteHTTPBINService())
+ // remove
+ assert.Nil(ginkgo.GinkgoT(), s.RemoveResourceByString(apisixRoute))
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(10 * time.Second)
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
+ assert.Len(ginkgo.GinkgoT(), ups, 0, "upstreams nodes not expect")
+ pluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "list pluginConfigs error")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0, "pluginConfigs nodes not expect")
+
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound).Body().Raw()
+ assert.Contains(ginkgo.GinkgoT(), body, "404 Route Not Found")
+ })
- ginkgo.It("change route rule name", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("change route rule name", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -264,26 +257,26 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
- routes, err := s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes in APISIX")
- assert.Len(ginkgo.GinkgoT(), routes, 1)
+ routes, err := s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes in APISIX")
+ assert.Len(ginkgo.GinkgoT(), routes, 1)
- upstreams, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams in APISIX")
- assert.Len(ginkgo.GinkgoT(), upstreams, 1)
+ upstreams, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams in APISIX")
+ assert.Len(ginkgo.GinkgoT(), upstreams, 1)
- pluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs in APISIX")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
+ pluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs in APISIX")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
- apisixRoute = fmt.Sprintf(`
+ apisixRoute = fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -301,36 +294,36 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
-
- newRoutes, err := s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes in APISIX")
- assert.Len(ginkgo.GinkgoT(), newRoutes, 1)
- newUpstreams, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams in APISIX")
- assert.Len(ginkgo.GinkgoT(), newUpstreams, 1)
- newPluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs in APISIX")
- assert.Len(ginkgo.GinkgoT(), newPluginConfigs, 0)
-
- // Upstream doesn't change.
- assert.Equal(ginkgo.GinkgoT(), newUpstreams[0].ID, upstreams[0].ID)
- assert.Equal(ginkgo.GinkgoT(), newUpstreams[0].Name, upstreams[0].Name)
-
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().
- Status(http.StatusNotFound).
- Body().Contains("404 Route Not Found")
-
- s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().
- Status(http.StatusOK)
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
+
+ newRoutes, err := s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes in APISIX")
+ assert.Len(ginkgo.GinkgoT(), newRoutes, 1)
+ newUpstreams, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams in APISIX")
+ assert.Len(ginkgo.GinkgoT(), newUpstreams, 1)
+ newPluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs in APISIX")
+ assert.Len(ginkgo.GinkgoT(), newPluginConfigs, 0)
+
+ // Upstream doesn't change.
+ assert.Equal(ginkgo.GinkgoT(), newUpstreams[0].ID, upstreams[0].ID)
+ assert.Equal(ginkgo.GinkgoT(), newUpstreams[0].Name, upstreams[0].Name)
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().
+ Status(http.StatusNotFound).
+ Body().Contains("404 Route Not Found")
+
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().
+ Status(http.StatusOK)
+ })
- ginkgo.It("same route rule name between two ApisixRoute objects", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("same route rule name between two ApisixRoute objects", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -364,25 +357,25 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0], backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
-
- s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().
- Status(http.StatusOK).
- Body().
- Contains("origin")
- s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().
- Status(http.StatusOK).
- Body().
- Contains("headers").
- Contains("httpbin.com")
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
+
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().
+ Status(http.StatusOK).
+ Body().
+ Contains("origin")
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().
+ Status(http.StatusOK).
+ Body().
+ Contains("headers").
+ Contains("httpbin.com")
+ })
- ginkgo.It("route priority", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("route priority", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -420,27 +413,27 @@ spec:
enable: true
`, backendSvc, backendSvcPort[0], backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
-
- // Hit rule1
- resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusOK)
- resp.Body().Contains("origin")
- resp.Header("X-Request-Id").Empty()
-
- // Hit rule2
- resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbazbar").Expect()
- resp.Status(http.StatusOK)
- resp.Body().Contains("origin")
- resp.Header("X-Request-Id").NotEmpty()
- })
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
+
+ // Hit rule1
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ resp.Header("X-Request-Id").Empty()
+
+ // Hit rule2
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").WithHeader("X-Foo", "barbazbar").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ resp.Header("X-Request-Id").NotEmpty()
+ })
- ginkgo.It("verify route/upstream/pluginConfig items", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("verify route/upstream/pluginConfig items", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -459,49 +452,49 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
-
- routes, err := s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
- assert.Len(ginkgo.GinkgoT(), routes, 1)
- name := s.Namespace() + "_" + "httpbin-route" + "_" + "rule1"
- assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name)
- assert.Equal(ginkgo.GinkgoT(), routes[0].Uris, []string{"/ip"})
- assert.Equal(ginkgo.GinkgoT(), routes[0].Hosts, []string{"httpbin.com"})
- assert.Equal(ginkgo.GinkgoT(), routes[0].Desc,
- "Created by apisix-ingress-controller, DO NOT modify it manually")
- assert.Equal(ginkgo.GinkgoT(), routes[0].Labels, map[string]string{
- "managed-by": "apisix-ingress-controller",
- })
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].Desc,
- "Created by apisix-ingress-controller, DO NOT modify it manually")
- assert.Equal(ginkgo.GinkgoT(), ups[0].Labels, map[string]string{
- "managed-by": "apisix-ingress-controller",
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute), "creating ApisixRoute")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixPluginConfigCreated(0))
+
+ routes, err := s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
+ assert.Len(ginkgo.GinkgoT(), routes, 1)
+ name := s.Namespace() + "_" + "httpbin-route" + "_" + "rule1"
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name)
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Uris, []string{"/ip"})
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Hosts, []string{"httpbin.com"})
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Desc,
+ "Created by apisix-ingress-controller, DO NOT modify it manually")
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Labels, map[string]string{
+ "managed-by": "apisix-ingress-controller",
+ })
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Desc,
+ "Created by apisix-ingress-controller, DO NOT modify it manually")
+ assert.Equal(ginkgo.GinkgoT(), ups[0].Labels, map[string]string{
+ "managed-by": "apisix-ingress-controller",
+ })
+
+ pluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ resp = s.NewAPISIXClient().GET("/ip").Expect()
+ resp.Status(http.StatusNotFound)
+ resp.Body().Contains("404 Route Not Found")
})
- pluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
-
- resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusOK)
- resp.Body().Contains("origin")
-
- resp = s.NewAPISIXClient().GET("/ip").Expect()
- resp.Status(http.StatusNotFound)
- resp.Body().Contains("404 Route Not Found")
- })
-
- ginkgo.It("service is referenced by two ApisixRoutes", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ar1 := fmt.Sprintf(`
+ ginkgo.It("service is referenced by two ApisixRoutes", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ar1 := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -519,7 +512,7 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- ar2 := fmt.Sprintf(`
+ ar2 := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -538,79 +531,87 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- err := s.CreateResourceFromString(ar1)
- assert.Nil(ginkgo.GinkgoT(), err)
- err = s.CreateResourceFromString(ar2)
- assert.Nil(ginkgo.GinkgoT(), err)
-
- time.Sleep(6 * time.Second)
-
- routes, err := s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
- assert.Len(ginkgo.GinkgoT(), routes, 2)
-
- ups, err := s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[0].UpstreamId)
- assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[1].UpstreamId)
-
- pluginConfigs, err := s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
-
- resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusOK)
- resp.Body().Contains("origin")
-
- resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusOK)
-
- // Delete ar1
- err = s.RemoveResourceByString(ar1)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(6 * time.Second)
-
- routes, err = s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
- assert.Len(ginkgo.GinkgoT(), routes, 1)
- name := s.Namespace() + "_" + "httpbin-route-2" + "_" + "rule1"
- assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name)
-
- // As httpbin service is referenced by ar2, the corresponding upstream still exists.
- ups, err = s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 1)
- assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[0].UpstreamId)
-
- // As httpbin service is referenced by ar2, the corresponding PluginConfig still doesn't exist.
- pluginConfigs, err = s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
-
- resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusNotFound)
- resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusOK)
-
- // Delete ar2
- err = s.RemoveResourceByString(ar2)
- assert.Nil(ginkgo.GinkgoT(), err)
- time.Sleep(10 * time.Second)
-
- routes, err = s.ListApisixRoutes()
- assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
- assert.Len(ginkgo.GinkgoT(), routes, 0)
-
- ups, err = s.ListApisixUpstreams()
- assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
- assert.Len(ginkgo.GinkgoT(), ups, 0)
-
- pluginConfigs, err = s.ListApisixPluginConfig()
- assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
- assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
-
- resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
- resp.Status(http.StatusNotFound)
+ err := s.CreateVersionedApisixResource(ar1)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ err = s.CreateVersionedApisixResource(ar2)
+ assert.Nil(ginkgo.GinkgoT(), err)
+
+ time.Sleep(6 * time.Second)
+
+ routes, err := s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
+ assert.Len(ginkgo.GinkgoT(), routes, 2)
+
+ ups, err := s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[0].UpstreamId)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[1].UpstreamId)
+
+ pluginConfigs, err := s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
+
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusOK)
+
+ // Delete ar1
+ err = s.RemoveResourceByString(ar1)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(6 * time.Second)
+
+ routes, err = s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
+ assert.Len(ginkgo.GinkgoT(), routes, 1)
+ name := s.Namespace() + "_" + "httpbin-route-2" + "_" + "rule1"
+ assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name)
+
+ // As httpbin service is referenced by ar2, the corresponding upstream still exists.
+ ups, err = s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 1)
+ assert.Equal(ginkgo.GinkgoT(), ups[0].ID, routes[0].UpstreamId)
+
+ // As httpbin service is referenced by ar2, the corresponding PluginConfig still doesn't exist.
+ pluginConfigs, err = s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
+
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusNotFound)
+ resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusOK)
+
+ // Delete ar2
+ err = s.RemoveResourceByString(ar2)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ time.Sleep(10 * time.Second)
+
+ routes, err = s.ListApisixRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
+ assert.Len(ginkgo.GinkgoT(), routes, 0)
+
+ ups, err = s.ListApisixUpstreams()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing upstreams")
+ assert.Len(ginkgo.GinkgoT(), ups, 0)
+
+ pluginConfigs, err = s.ListApisixPluginConfig()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing pluginConfigs")
+ assert.Len(ginkgo.GinkgoT(), pluginConfigs, 0)
+
+ resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.com").Expect()
+ resp.Status(http.StatusNotFound)
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-ingress/resourcesync.go b/test/e2e/suite-ingress/resourcesync.go
index 559c36fe..e7b1f646 100644
--- a/test/e2e/suite-ingress/resourcesync.go
+++ b/test/e2e/suite-ingress/resourcesync.go
@@ -28,20 +28,11 @@ import (
)
var _ = ginkgo.Describe("suite-ingress: apisix resource sync", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- ApisixResourceSyncInterval: "60s",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.JustBeforeEach(func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- // Create ApisixRoute resource
- ar := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.JustBeforeEach(func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ // Create ApisixRoute resource
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -61,14 +52,14 @@ spec:
enable: true
type: keyAuth
`, 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")
-
- // Create Ingress resource
- ing := fmt.Sprintf(`
+ 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")
+
+ // Create Ingress resource
+ ing := fmt.Sprintf(`
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
@@ -88,25 +79,25 @@ spec:
port:
number: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ing))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ing))
- // Create ApisixConsumer resource
- err = s.ApisixConsumerKeyAuthCreated("foo", "foo-key")
- assert.Nil(ginkgo.GinkgoT(), err)
- })
+ // Create ApisixConsumer resource
+ err = s.ApisixConsumerKeyAuthCreated("foo", "foo-key")
+ assert.Nil(ginkgo.GinkgoT(), err)
+ })
- ginkgo.It("for modified resource sync consistency", func() {
- // crd resource sync interval
- readyTime := time.Now().Add(60 * time.Second)
+ ginkgo.It("for modified resource sync consistency", func() {
+ // crd resource sync interval
+ readyTime := time.Now().Add(60 * time.Second)
- routes, _ := s.ListApisixRoutes()
- assert.Len(ginkgo.GinkgoT(), routes, 2)
+ routes, _ := s.ListApisixRoutes()
+ assert.Len(ginkgo.GinkgoT(), routes, 2)
- consumers, _ := s.ListApisixConsumers()
- assert.Len(ginkgo.GinkgoT(), consumers, 1)
+ consumers, _ := s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 1)
- for _, route := range routes {
- _ = s.CreateApisixRouteByApisixAdmin(id.GenID(route.Name), []byte(`
+ for _, route := range routes {
+ _ = s.CreateApisixRouteByApisixAdmin(id.GenID(route.Name), []byte(`
{
"methods": ["GET"],
"uri": "/anything",
@@ -120,10 +111,10 @@ spec:
}
}
}`))
- }
+ }
- for _, consumer := range consumers {
- _ = s.CreateApisixConsumerByApisixAdmin([]byte(fmt.Sprintf(`
+ for _, consumer := range consumers {
+ _ = s.CreateApisixConsumerByApisixAdmin([]byte(fmt.Sprintf(`
{
"username": "%s",
"plugins": {
@@ -132,96 +123,120 @@ spec:
}
}
}`, consumer.Username)))
- }
+ }
+
+ _ = s.NewAPISIXClient().
+ GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound)
+
+ _ = s.NewAPISIXClient().
+ GET("/headers").
+ WithHeader("Host", "local.httpbin.org").
+ Expect().
+ Status(http.StatusNotFound)
+
+ waitTime := time.Until(readyTime).Seconds()
+ time.Sleep(time.Duration(waitTime) * time.Second)
+
+ _ = s.NewAPISIXClient().
+ GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("apikey", "foo-key").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().
+ GET("/headers").
+ WithHeader("Host", "local.httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ consumers, _ = s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 1)
+ data, _ := json.Marshal(consumers[0])
+ assert.Contains(ginkgo.GinkgoT(), string(data), "foo-key")
+ })
+
+ ginkgo.It("for deleted resource sync consistency", func() {
+ // crd resource sync interval
+ readyTime := time.Now().Add(60 * time.Second)
+
+ routes, _ := s.ListApisixRoutes()
+ assert.Len(ginkgo.GinkgoT(), routes, 2)
+
+ consumers, _ := s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 1)
+
+ for _, route := range routes {
+ _ = s.DeleteApisixRouteByApisixAdmin(id.GenID(route.Name))
+ }
+
+ for _, consumer := range consumers {
+ s.DeleteApisixConsumerByApisixAdmin(consumer.Username)
+ }
+
+ _ = s.NewAPISIXClient().
+ GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusNotFound)
+
+ _ = s.NewAPISIXClient().
+ GET("/headers").
+ WithHeader("Host", "local.httpbin.org").
+ Expect().
+ Status(http.StatusNotFound)
+
+ routes, _ = s.ListApisixRoutes()
+ assert.Len(ginkgo.GinkgoT(), routes, 0)
+ consumers, _ = s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 0)
+
+ waitTime := time.Until(readyTime).Seconds()
+ time.Sleep(time.Duration(waitTime) * time.Second)
+
+ _ = s.NewAPISIXClient().
+ GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("apikey", "foo-key").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().
+ GET("/headers").
+ WithHeader("Host", "local.httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ consumers, _ = s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 1)
+ data, _ := json.Marshal(consumers[0])
+ assert.Contains(ginkgo.GinkgoT(), string(data), "foo-key")
+ })
+ }
- _ = s.NewAPISIXClient().
- GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound)
-
- _ = s.NewAPISIXClient().
- GET("/headers").
- WithHeader("Host", "local.httpbin.org").
- Expect().
- Status(http.StatusNotFound)
-
- waitTime := time.Until(readyTime).Seconds()
- time.Sleep(time.Duration(waitTime) * time.Second)
-
- _ = s.NewAPISIXClient().
- GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("apikey", "foo-key").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().
- GET("/headers").
- WithHeader("Host", "local.httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- consumers, _ = s.ListApisixConsumers()
- assert.Len(ginkgo.GinkgoT(), consumers, 1)
- data, _ := json.Marshal(consumers[0])
- assert.Contains(ginkgo.GinkgoT(), string(data), "foo-key")
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "sync",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2beta3,
+ ApisixResourceSyncInterval: "60s",
+ }))
})
-
- ginkgo.It("for deleted resource sync consistency", func() {
- // crd resource sync interval
- readyTime := time.Now().Add(60 * time.Second)
-
- routes, _ := s.ListApisixRoutes()
- assert.Len(ginkgo.GinkgoT(), routes, 2)
-
- consumers, _ := s.ListApisixConsumers()
- assert.Len(ginkgo.GinkgoT(), consumers, 1)
-
- for _, route := range routes {
- _ = s.DeleteApisixRouteByApisixAdmin(id.GenID(route.Name))
- }
-
- for _, consumer := range consumers {
- s.DeleteApisixConsumerByApisixAdmin(consumer.Username)
- }
-
- _ = s.NewAPISIXClient().
- GET("/ip").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusNotFound)
-
- _ = s.NewAPISIXClient().
- GET("/headers").
- WithHeader("Host", "local.httpbin.org").
- Expect().
- Status(http.StatusNotFound)
-
- routes, _ = s.ListApisixRoutes()
- assert.Len(ginkgo.GinkgoT(), routes, 0)
- consumers, _ = s.ListApisixConsumers()
- assert.Len(ginkgo.GinkgoT(), consumers, 0)
-
- waitTime := time.Until(readyTime).Seconds()
- time.Sleep(time.Duration(waitTime) * time.Second)
-
- _ = s.NewAPISIXClient().
- GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("apikey", "foo-key").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().
- GET("/headers").
- WithHeader("Host", "local.httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- consumers, _ = s.ListApisixConsumers()
- assert.Len(ginkgo.GinkgoT(), consumers, 1)
- data, _ := json.Marshal(consumers[0])
- assert.Contains(ginkgo.GinkgoT(), string(data), "foo-key")
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "sync",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2,
+ ApisixResourceSyncInterval: "60s",
+ }))
})
})
diff --git a/test/e2e/suite-ingress/sanity.go b/test/e2e/suite-ingress/sanity.go
index 65b96092..bdfce469 100644
--- a/test/e2e/suite-ingress/sanity.go
+++ b/test/e2e/suite-ingress/sanity.go
@@ -31,18 +31,10 @@ type ip struct {
}
var _ = ginkgo.Describe("suite-ingress: single-route", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("/ip should return your ip", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("/ip should return your ip", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -57,39 +49,39 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
- 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")
-
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(3 * time.Second)
-
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
- var placeholder ip
- err = json.Unmarshal([]byte(body), &placeholder)
- assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
- assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
- // It's not our focus point to check the IP address returned by httpbin,
- // so here skip the IP address validation.
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+ 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")
+
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(3 * time.Second)
+
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var placeholder ip
+ err = json.Unmarshal([]byte(body), &placeholder)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
+ assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
+ // It's not our focus point to check the IP address returned by httpbin,
+ // so here skip the IP address validation.
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
var _ = ginkgo.Describe("suite-ingress: double-routes", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("double routes work independently", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ar := `
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("double routes work independently", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ar := `
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -111,97 +103,112 @@ spec:
- serviceName: %s
servicePort: %d
`
- ar = fmt.Sprintf(ar, backendSvc, backendSvcPort[0], backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
- err := s.EnsureNumApisixRoutesCreated(2)
- assert.Nil(ginkgo.GinkgoT(), err, "checking number of routes")
- err = s.EnsureNumApisixUpstreamsCreated(1)
- assert.Nil(ginkgo.GinkgoT(), err, "checking number of upstreams")
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(3 * time.Second)
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
- var placeholder ip
- err = json.Unmarshal([]byte(body), &placeholder)
- assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
- assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
-
- body = s.NewAPISIXClient().GET("/json").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
- var dummy map[string]interface{}
- err = json.Unmarshal([]byte(body), &dummy)
- assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling json")
- // We don't care the json data, only make sure it's a normal json string.
- })
-})
+ ar = fmt.Sprintf(ar, backendSvc, backendSvcPort[0], backendSvc, backendSvcPort[0])
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ err := s.EnsureNumApisixRoutesCreated(2)
+ assert.Nil(ginkgo.GinkgoT(), err, "checking number of routes")
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "checking number of upstreams")
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(3 * time.Second)
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var placeholder ip
+ err = json.Unmarshal([]byte(body), &placeholder)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
+ assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
+
+ body = s.NewAPISIXClient().GET("/json").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var dummy map[string]interface{}
+ err = json.Unmarshal([]byte(body), &dummy)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling json")
+ // We don't care the json data, only make sure it's a normal json string.
+ })
+ }
-var _ = ginkgo.Describe("suite-ingress: leader election", func() {
- s := scaffold.NewScaffold(&scaffold.Options{
- Name: "leaderelection",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 2,
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
})
- ginkgo.It("lease check", func() {
- pods, err := s.GetIngressPodDetails()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), pods, 2)
- lease, err := s.WaitGetLeaderLease()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Equal(ginkgo.GinkgoT(), *lease.Spec.LeaseDurationSeconds, int32(15))
- if *lease.Spec.HolderIdentity != pods[0].Name && *lease.Spec.HolderIdentity != pods[1].Name {
- assert.Fail(ginkgo.GinkgoT(), "bad leader lease holder identity")
- }
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
+})
- ginkgo.It("leader failover", func() {
- pods, err := s.GetIngressPodDetails()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), pods, 2)
-
- lease, err := s.WaitGetLeaderLease()
- assert.Nil(ginkgo.GinkgoT(), err)
-
- leaderIdx := 0
- if *lease.Spec.HolderIdentity == pods[1].Name {
- leaderIdx = 1
- }
- ginkgo.GinkgoT().Logf("lease is %s", *lease.Spec.HolderIdentity)
- assert.Nil(ginkgo.GinkgoT(), s.KillPod(pods[leaderIdx].Name))
-
- // Wait the old leader given up lease and new leader was elected.
- time.Sleep(3 * time.Second)
-
- newLease, err := s.WaitGetLeaderLease()
- assert.Nil(ginkgo.GinkgoT(), err)
-
- newPods, err := s.GetIngressPodDetails()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), pods, 2)
-
- assert.NotEqual(ginkgo.GinkgoT(), *newLease.Spec.HolderIdentity, *lease.Spec.HolderIdentity)
- assert.Greater(ginkgo.GinkgoT(), *newLease.Spec.LeaseTransitions, *lease.Spec.LeaseTransitions)
+var _ = ginkgo.Describe("suite-ingress: leader election", func() {
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("lease check", func() {
+ pods, err := s.GetIngressPodDetails()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), pods, 2)
+ lease, err := s.WaitGetLeaderLease()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Equal(ginkgo.GinkgoT(), *lease.Spec.LeaseDurationSeconds, int32(15))
+ if *lease.Spec.HolderIdentity != pods[0].Name && *lease.Spec.HolderIdentity != pods[1].Name {
+ assert.Fail(ginkgo.GinkgoT(), "bad leader lease holder identity")
+ }
+ })
+
+ ginkgo.It("leader failover", func() {
+ pods, err := s.GetIngressPodDetails()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), pods, 2)
+
+ lease, err := s.WaitGetLeaderLease()
+ assert.Nil(ginkgo.GinkgoT(), err)
+
+ leaderIdx := 0
+ if *lease.Spec.HolderIdentity == pods[1].Name {
+ leaderIdx = 1
+ }
+ ginkgo.GinkgoT().Logf("lease is %s", *lease.Spec.HolderIdentity)
+ assert.Nil(ginkgo.GinkgoT(), s.KillPod(pods[leaderIdx].Name))
+
+ // Wait the old leader given up lease and new leader was elected.
+ time.Sleep(3 * time.Second)
+
+ newLease, err := s.WaitGetLeaderLease()
+ assert.Nil(ginkgo.GinkgoT(), err)
+
+ newPods, err := s.GetIngressPodDetails()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), pods, 2)
+
+ assert.NotEqual(ginkgo.GinkgoT(), *newLease.Spec.HolderIdentity, *lease.Spec.HolderIdentity)
+ assert.Greater(ginkgo.GinkgoT(), *newLease.Spec.LeaseTransitions, *lease.Spec.LeaseTransitions)
+
+ if *newLease.Spec.HolderIdentity != newPods[0].Name && *newLease.Spec.HolderIdentity != newPods[1].Name {
+ assert.Failf(ginkgo.GinkgoT(), "bad leader lease holder identity: %s, should be %s or %s",
+ *newLease.Spec.HolderIdentity, newPods[0].Name, newPods[1].Name)
+ }
+ })
+ }
- if *newLease.Spec.HolderIdentity != newPods[0].Name && *newLease.Spec.HolderIdentity != newPods[1].Name {
- assert.Failf(ginkgo.GinkgoT(), "bad leader lease holder identity: %s, should be %s or %s",
- *newLease.Spec.HolderIdentity, newPods[0].Name, newPods[1].Name)
- }
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "leaderelection",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 2,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2beta3,
+ }))
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "leaderelection",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 2,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2,
+ }))
})
})
var _ = ginkgo.Describe("suite-ingress: stream_routes disabled", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-stream-disabled.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("/ip should return your ip", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("/ip should return your ip", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -216,22 +223,30 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
- 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")
-
- // TODO When ingress controller can feedback the lifecycle of CRDs to the
- // status field, we can poll it rather than sleeping.
- time.Sleep(3 * time.Second)
-
- body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
- var placeholder ip
- err = json.Unmarshal([]byte(body), &placeholder)
- assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
- assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
- // It's not our focus point to check the IP address returned by httpbin,
- // so here skip the IP address validation.
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+ 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")
+
+ // TODO When ingress controller can feedback the lifecycle of CRDs to the
+ // status field, we can poll it rather than sleeping.
+ time.Sleep(3 * time.Second)
+
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var placeholder ip
+ err = json.Unmarshal([]byte(body), &placeholder)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
+ assert.NotEqual(ginkgo.GinkgoT(), ip{}, placeholder)
+ // It's not our focus point to check the IP address returned by httpbin,
+ // so here skip the IP address validation.
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
diff --git a/test/e2e/suite-ingress/secret.go b/test/e2e/suite-ingress/secret.go
index 6e1f0fd4..49b92698 100644
--- a/test/e2e/suite-ingress/secret.go
+++ b/test/e2e/suite-ingress/secret.go
@@ -28,18 +28,10 @@ import (
// TODO: FIXME
var _ = ginkgo.Describe("suite-ingress: secret Testing", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("create a SSL and then update secret ", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("create a SSL and then update secret ", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -56,10 +48,10 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
- secretName := "test-apisix-tls"
- cert := `-----BEGIN CERTIFICATE-----
+ secretName := "test-apisix-tls"
+ cert := `-----BEGIN CERTIFICATE-----
MIIFcjCCA1qgAwIBAgIJALDqPppBVXQ3MA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNV
BAYTAkNOMRAwDgYDVQQIDAdKaWFuZ3N1MQ8wDQYDVQQHDAZTdXpob3UxEDAOBgNV
BAoMB2FwaTcuYWkxEDAOBgNVBAsMB2FwaTcuYWkxDzANBgNVBAMMBmp3LmNvbTAg
@@ -91,7 +83,7 @@ bDs+00FijzHFBvC8cIhNffj0qqiv35g+9FTwnE9qpunlrtKG/sMgEXX6m8kL1YQ8
m5DPGhyEZyt5Js2kzzo8TyINPKmrqriYuiD4p4EH13eSRs3ayanQh6ckC7lb+WXq
3IrSc5hO
-----END CERTIFICATE-----`
- key := `-----BEGIN RSA PRIVATE KEY-----
+ key := `-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAuEPPnUMlSw41CTdxUNxkQ4gAZ7cPotwYY6sVLGtWoR8gKFSZ
ImQIor3UF+8HhN/ZOFRv5tSeeQ/MTE72cs2T5mp6eRU8OrSV0npk/TpZfaCx7zob
sfXB4YU1NZcVWKthFF5X8p//l5gxUMU8V4a01P0aDTmZ67wG3Fhr0AC067GVYvdw
@@ -142,28 +134,28 @@ gNnZmws4l3i7RlVMtACCenmof9VtOcMK/9Qr502WHEoGkQR1r6HZFb25841cehL2
do+oXlr8db++r87a8QQUkizzc6wXD9JffBNo9AO9Ed4HVOukpEA0gqVGBu85N3xW
jW4KB95bGOTa7r7DM1Up0MbAIwWoeLBGhOIXk7inurZGg+FNjZMA5Lzm6qo=
-----END RSA PRIVATE KEY-----`
- // key compare
- keyCompare := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofaOw61M98WSdvoWLaQa8YKSdemgQUz2W4MYk2rRZcVSzHfJOLRG7g4ieZau6peDYOmPmp/0ZZFpOzBKoWHN3QP/8i/7SF+JX+EDLD2JO2+GM6iR3f2Zj7v0vx+CcoQ1rjxaXNETSSHo8yvW6pdFZOLgJk4rOHKGypnqzygxxamM8Hq7WSPrWhNe47y1QAfz42kBQXRUJpNNd7W749cTsMWCqBlR+8klTlnSFHkjyijBZjg5ihqZsi/8JzHGrmAixZ54ugPgbufD0/ZJdo3w7opJc4WTnUI2GhiBL+ENCA0X1s/6H8JG8zsC50PvxOBpRgK455TTvejm1JHyt0GTh7c4WFEeQSrbEFzS89BpVrPtre2enO38pkILI8ty8r6tIbZzuOJhM6ZpxQQcAe8OUvFuIIlx21yBvlljbu3eH5Hg7X+wtJR [...]
- // create secret
- err := s.NewSecret(secretName, cert, key)
- assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
- // create ApisixTls resource
- tlsName := "tls-name"
- host := "api6.com"
- err = s.NewApisixTls(tlsName, host, secretName)
- assert.Nil(ginkgo.GinkgoT(), err, "create tls error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tls, err := s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
- assert.Len(ginkgo.GinkgoT(), tls, 1, "tls number not expect")
- assert.Equal(ginkgo.GinkgoT(), cert, tls[0].Cert, "tls cert not expect")
- assert.Equal(ginkgo.GinkgoT(), keyCompare, tls[0].Key, "tls key not expect")
+ // key compare
+ keyCompare := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofaOw61M98WSdvoWLaQa8YKSdemgQUz2W4MYk2rRZcVSzHfJOLRG7g4ieZau6peDYOmPmp/0ZZFpOzBKoWHN3QP/8i/7SF+JX+EDLD2JO2+GM6iR3f2Zj7v0vx+CcoQ1rjxaXNETSSHo8yvW6pdFZOLgJk4rOHKGypnqzygxxamM8Hq7WSPrWhNe47y1QAfz42kBQXRUJpNNd7W749cTsMWCqBlR+8klTlnSFHkjyijBZjg5ihqZsi/8JzHGrmAixZ54ugPgbufD0/ZJdo3w7opJc4WTnUI2GhiBL+ENCA0X1s/6H8JG8zsC50PvxOBpRgK455TTvejm1JHyt0GTh7c4WFEeQSrbEFzS89BpVrPtre2enO38pkILI8ty8r6tIbZzuOJhM6ZpxQQcAe8OUvFuIIlx21yBvlljbu3eH5Hg7X+wtJ [...]
+ // create secret
+ err := s.NewSecret(secretName, cert, key)
+ assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
+ // create ApisixTls resource
+ tlsName := "tls-name"
+ host := "api6.com"
+ err = s.NewApisixTls(tlsName, host, secretName)
+ assert.Nil(ginkgo.GinkgoT(), err, "create tls error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tls, err := s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
+ assert.Len(ginkgo.GinkgoT(), tls, 1, "tls number not expect")
+ assert.Equal(ginkgo.GinkgoT(), cert, tls[0].Cert, "tls cert not expect")
+ assert.Equal(ginkgo.GinkgoT(), keyCompare, tls[0].Key, "tls key not expect")
- // check DP
- s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
+ // check DP
+ s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
- certUpdate := `-----BEGIN CERTIFICATE-----
+ certUpdate := `-----BEGIN CERTIFICATE-----
MIIFcjCCA1qgAwIBAgIJAM7zkxmhGdNEMA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNV
BAYTAkNOMRAwDgYDVQQIDAdKaWFuZ3N1MQ8wDQYDVQQHDAZTdXpob3UxEDAOBgNV
BAoMB2FwaTcuYWkxEDAOBgNVBAsMB2FwaTcuYWkxDzANBgNVBAMMBmp3LmNvbTAg
@@ -195,7 +187,7 @@ XNsBIYSloIopKd7IY3V7Y8yASs7jKLrtJN4AE+SpssWuTa4p2LSO08sW3NP8r86G
FskpOMlyl8WZo6JMsbOjd+tVygf9QuhvH9MxYDvppfeHxS0B7mYGZDOV/4G2vn2A
C1K1xkvo
-----END CERTIFICATE-----`
- keyUpdate := `-----BEGIN RSA PRIVATE KEY-----
+ keyUpdate := `-----BEGIN RSA PRIVATE KEY-----
MIIJKQIBAAKCAgEAlXGEL4P5+mjllbb4VxkpqjsHny2wY7QZNbA0INfLdBq3B5av
L0Gp/nHk1iOMq+RkUu+DDb9i0wKw0j1ygaaN4WNXCa7/LZ7EIVDKcCKF7JQUi5za
9A36nTBMLb7ZbFwxnxGkCK2AwdIbUIB6Ciq/d+WEbZelspPQPtG9e8pVYTbNhRub
@@ -246,33 +238,33 @@ UnBVSIGJ/c0AhVSDuOAJiF36pvsDysTZXMTFE/9i5bkGOiwtzRNe4Hym/SEZUCpn
8Z1U5/a5LhrDtIKAsCCpRx99P++Eqt2M2YV7jZcTfEbEvxP4XBYcdh30nbq1uEhs
4zEnK1pMx5PnEljN1mcgmL2TPsMVN5DN9zXHW5eNQ6wfXR8rCfHwVIVcUuaB
-----END RSA PRIVATE KEY-----`
- keyCompareUpdate := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofY0a95jf9O5bkBT8pEwjhLvcZOysVlRXE9fYFZ7heHoaihZmZIcnNPPi/SnNr1qVExgIWFYCf6QzpMdv7bMKag8AnYlalvbEIAyJA2tjZ0Gt9aQ9YlzmbGtyFX344481bSfLR/3fpNABO2j/6C6IQxxaGOPRiUeBEJ4VwPxmCUecRPWOHgQfyROReELWwkTIXZ17j0YeABDHWpsHASTjMdupvdwma20TlA3ruNV9WqDn1VE8hDTB4waAImqbZI0bBMdqDFVE0q50DSl2uzzO8X825CLjIa/E0U6JPid41hGOdadZph5Gbpnlou8xwOgRfzG1yyptPCKrAJcgIvsSz/CsYCqaoPCpil4TFjUq4PH0cWo6GlXN95TPX0LrAOh8WMCb7lZYXq5Q2TZ/sn5jF1GIiZZFWVUZujXK2og0I042 [...]
- // key update compare
- err = s.NewSecret(secretName, certUpdate, keyUpdate)
- assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tlsUpdate, err := s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tlsUpdate error")
- assert.Len(ginkgo.GinkgoT(), tlsUpdate, 1, "tls number not expect")
- assert.Equal(ginkgo.GinkgoT(), certUpdate, tlsUpdate[0].Cert, "tls cert not expect")
- assert.Equal(ginkgo.GinkgoT(), keyCompareUpdate, tlsUpdate[0].Key, "tls key not expect")
- // check DP
- s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
+ keyCompareUpdate := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofY0a95jf9O5bkBT8pEwjhLvcZOysVlRXE9fYFZ7heHoaihZmZIcnNPPi/SnNr1qVExgIWFYCf6QzpMdv7bMKag8AnYlalvbEIAyJA2tjZ0Gt9aQ9YlzmbGtyFX344481bSfLR/3fpNABO2j/6C6IQxxaGOPRiUeBEJ4VwPxmCUecRPWOHgQfyROReELWwkTIXZ17j0YeABDHWpsHASTjMdupvdwma20TlA3ruNV9WqDn1VE8hDTB4waAImqbZI0bBMdqDFVE0q50DSl2uzzO8X825CLjIa/E0U6JPid41hGOdadZph5Gbpnlou8xwOgRfzG1yyptPCKrAJcgIvsSz/CsYCqaoPCpil4TFjUq4PH0cWo6GlXN95TPX0LrAOh8WMCb7lZYXq5Q2TZ/sn5jF1GIiZZFWVUZujXK2og0I04 [...]
+ // key update compare
+ err = s.NewSecret(secretName, certUpdate, keyUpdate)
+ assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tlsUpdate, err := s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tlsUpdate error")
+ assert.Len(ginkgo.GinkgoT(), tlsUpdate, 1, "tls number not expect")
+ assert.Equal(ginkgo.GinkgoT(), certUpdate, tlsUpdate[0].Cert, "tls cert not expect")
+ assert.Equal(ginkgo.GinkgoT(), keyCompareUpdate, tlsUpdate[0].Key, "tls key not expect")
+ // check DP
+ s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
- // delete ApisixTls
- err = s.DeleteApisixTls(tlsName, host, secretName)
- assert.Nil(ginkgo.GinkgoT(), err, "delete tls error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tls, err = s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
- assert.Len(ginkgo.GinkgoT(), tls, 0, "tls number not expect")
- })
+ // delete ApisixTls
+ err = s.DeleteApisixTls(tlsName, host, secretName)
+ assert.Nil(ginkgo.GinkgoT(), err, "delete tls error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tls, err = s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
+ assert.Len(ginkgo.GinkgoT(), tls, 0, "tls number not expect")
+ })
- ginkgo.It("create a kube style SSL and then update secret ", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ ginkgo.It("create a kube style SSL and then update secret ", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -289,10 +281,10 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
- secretName := "test-apisix-tls"
- cert := `-----BEGIN CERTIFICATE-----
+ secretName := "test-apisix-tls"
+ cert := `-----BEGIN CERTIFICATE-----
MIIFcjCCA1qgAwIBAgIJALDqPppBVXQ3MA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNV
BAYTAkNOMRAwDgYDVQQIDAdKaWFuZ3N1MQ8wDQYDVQQHDAZTdXpob3UxEDAOBgNV
BAoMB2FwaTcuYWkxEDAOBgNVBAsMB2FwaTcuYWkxDzANBgNVBAMMBmp3LmNvbTAg
@@ -324,7 +316,7 @@ bDs+00FijzHFBvC8cIhNffj0qqiv35g+9FTwnE9qpunlrtKG/sMgEXX6m8kL1YQ8
m5DPGhyEZyt5Js2kzzo8TyINPKmrqriYuiD4p4EH13eSRs3ayanQh6ckC7lb+WXq
3IrSc5hO
-----END CERTIFICATE-----`
- key := `-----BEGIN RSA PRIVATE KEY-----
+ key := `-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAuEPPnUMlSw41CTdxUNxkQ4gAZ7cPotwYY6sVLGtWoR8gKFSZ
ImQIor3UF+8HhN/ZOFRv5tSeeQ/MTE72cs2T5mp6eRU8OrSV0npk/TpZfaCx7zob
sfXB4YU1NZcVWKthFF5X8p//l5gxUMU8V4a01P0aDTmZ67wG3Fhr0AC067GVYvdw
@@ -375,28 +367,28 @@ gNnZmws4l3i7RlVMtACCenmof9VtOcMK/9Qr502WHEoGkQR1r6HZFb25841cehL2
do+oXlr8db++r87a8QQUkizzc6wXD9JffBNo9AO9Ed4HVOukpEA0gqVGBu85N3xW
jW4KB95bGOTa7r7DM1Up0MbAIwWoeLBGhOIXk7inurZGg+FNjZMA5Lzm6qo=
-----END RSA PRIVATE KEY-----`
- // key compare
- keyCompare := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofaOw61M98WSdvoWLaQa8YKSdemgQUz2W4MYk2rRZcVSzHfJOLRG7g4ieZau6peDYOmPmp/0ZZFpOzBKoWHN3QP/8i/7SF+JX+EDLD2JO2+GM6iR3f2Zj7v0vx+CcoQ1rjxaXNETSSHo8yvW6pdFZOLgJk4rOHKGypnqzygxxamM8Hq7WSPrWhNe47y1QAfz42kBQXRUJpNNd7W749cTsMWCqBlR+8klTlnSFHkjyijBZjg5ihqZsi/8JzHGrmAixZ54ugPgbufD0/ZJdo3w7opJc4WTnUI2GhiBL+ENCA0X1s/6H8JG8zsC50PvxOBpRgK455TTvejm1JHyt0GTh7c4WFEeQSrbEFzS89BpVrPtre2enO38pkILI8ty8r6tIbZzuOJhM6ZpxQQcAe8OUvFuIIlx21yBvlljbu3eH5Hg7X+wtJR [...]
- // create kube secret
- err := s.NewKubeTlsSecret(secretName, cert, key)
- assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
- // create ApisixTls resource
- tlsName := "tls-name"
- host := "api6.com"
- err = s.NewApisixTls(tlsName, host, secretName)
- assert.Nil(ginkgo.GinkgoT(), err, "create tls error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tls, err := s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
- assert.Len(ginkgo.GinkgoT(), tls, 1, "tls number not expect")
- assert.Equal(ginkgo.GinkgoT(), cert, tls[0].Cert, "tls cert not expect")
- assert.Equal(ginkgo.GinkgoT(), keyCompare, tls[0].Key, "tls key not expect")
+ // key compare
+ keyCompare := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofaOw61M98WSdvoWLaQa8YKSdemgQUz2W4MYk2rRZcVSzHfJOLRG7g4ieZau6peDYOmPmp/0ZZFpOzBKoWHN3QP/8i/7SF+JX+EDLD2JO2+GM6iR3f2Zj7v0vx+CcoQ1rjxaXNETSSHo8yvW6pdFZOLgJk4rOHKGypnqzygxxamM8Hq7WSPrWhNe47y1QAfz42kBQXRUJpNNd7W749cTsMWCqBlR+8klTlnSFHkjyijBZjg5ihqZsi/8JzHGrmAixZ54ugPgbufD0/ZJdo3w7opJc4WTnUI2GhiBL+ENCA0X1s/6H8JG8zsC50PvxOBpRgK455TTvejm1JHyt0GTh7c4WFEeQSrbEFzS89BpVrPtre2enO38pkILI8ty8r6tIbZzuOJhM6ZpxQQcAe8OUvFuIIlx21yBvlljbu3eH5Hg7X+wtJ [...]
+ // create kube secret
+ err := s.NewKubeTlsSecret(secretName, cert, key)
+ assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
+ // create ApisixTls resource
+ tlsName := "tls-name"
+ host := "api6.com"
+ err = s.NewApisixTls(tlsName, host, secretName)
+ assert.Nil(ginkgo.GinkgoT(), err, "create tls error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tls, err := s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
+ assert.Len(ginkgo.GinkgoT(), tls, 1, "tls number not expect")
+ assert.Equal(ginkgo.GinkgoT(), cert, tls[0].Cert, "tls cert not expect")
+ assert.Equal(ginkgo.GinkgoT(), keyCompare, tls[0].Key, "tls key not expect")
- // check DP
- s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
+ // check DP
+ s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
- certUpdate := `-----BEGIN CERTIFICATE-----
+ certUpdate := `-----BEGIN CERTIFICATE-----
MIIFcjCCA1qgAwIBAgIJAM7zkxmhGdNEMA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNV
BAYTAkNOMRAwDgYDVQQIDAdKaWFuZ3N1MQ8wDQYDVQQHDAZTdXpob3UxEDAOBgNV
BAoMB2FwaTcuYWkxEDAOBgNVBAsMB2FwaTcuYWkxDzANBgNVBAMMBmp3LmNvbTAg
@@ -428,7 +420,7 @@ XNsBIYSloIopKd7IY3V7Y8yASs7jKLrtJN4AE+SpssWuTa4p2LSO08sW3NP8r86G
FskpOMlyl8WZo6JMsbOjd+tVygf9QuhvH9MxYDvppfeHxS0B7mYGZDOV/4G2vn2A
C1K1xkvo
-----END CERTIFICATE-----`
- keyUpdate := `-----BEGIN RSA PRIVATE KEY-----
+ keyUpdate := `-----BEGIN RSA PRIVATE KEY-----
MIIJKQIBAAKCAgEAlXGEL4P5+mjllbb4VxkpqjsHny2wY7QZNbA0INfLdBq3B5av
L0Gp/nHk1iOMq+RkUu+DDb9i0wKw0j1ygaaN4WNXCa7/LZ7EIVDKcCKF7JQUi5za
9A36nTBMLb7ZbFwxnxGkCK2AwdIbUIB6Ciq/d+WEbZelspPQPtG9e8pVYTbNhRub
@@ -479,27 +471,35 @@ UnBVSIGJ/c0AhVSDuOAJiF36pvsDysTZXMTFE/9i5bkGOiwtzRNe4Hym/SEZUCpn
8Z1U5/a5LhrDtIKAsCCpRx99P++Eqt2M2YV7jZcTfEbEvxP4XBYcdh30nbq1uEhs
4zEnK1pMx5PnEljN1mcgmL2TPsMVN5DN9zXHW5eNQ6wfXR8rCfHwVIVcUuaB
-----END RSA PRIVATE KEY-----`
- keyCompareUpdate := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofY0a95jf9O5bkBT8pEwjhLvcZOysVlRXE9fYFZ7heHoaihZmZIcnNPPi/SnNr1qVExgIWFYCf6QzpMdv7bMKag8AnYlalvbEIAyJA2tjZ0Gt9aQ9YlzmbGtyFX344481bSfLR/3fpNABO2j/6C6IQxxaGOPRiUeBEJ4VwPxmCUecRPWOHgQfyROReELWwkTIXZ17j0YeABDHWpsHASTjMdupvdwma20TlA3ruNV9WqDn1VE8hDTB4waAImqbZI0bBMdqDFVE0q50DSl2uzzO8X825CLjIa/E0U6JPid41hGOdadZph5Gbpnlou8xwOgRfzG1yyptPCKrAJcgIvsSz/CsYCqaoPCpil4TFjUq4PH0cWo6GlXN95TPX0LrAOh8WMCb7lZYXq5Q2TZ/sn5jF1GIiZZFWVUZujXK2og0I042 [...]
- // key update compare
- err = s.NewKubeTlsSecret(secretName, certUpdate, keyUpdate)
- assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tlsUpdate, err := s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tlsUpdate error")
- assert.Len(ginkgo.GinkgoT(), tlsUpdate, 1, "tls number not expect")
- assert.Equal(ginkgo.GinkgoT(), certUpdate, tlsUpdate[0].Cert, "tls cert not expect")
- assert.Equal(ginkgo.GinkgoT(), keyCompareUpdate, tlsUpdate[0].Key, "tls key not expect")
- // check DP
- s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
+ keyCompareUpdate := "HrMHUvE9Esvn7GnZ+vAynaIg/8wlB3r0zm0htmnwofY0a95jf9O5bkBT8pEwjhLvcZOysVlRXE9fYFZ7heHoaihZmZIcnNPPi/SnNr1qVExgIWFYCf6QzpMdv7bMKag8AnYlalvbEIAyJA2tjZ0Gt9aQ9YlzmbGtyFX344481bSfLR/3fpNABO2j/6C6IQxxaGOPRiUeBEJ4VwPxmCUecRPWOHgQfyROReELWwkTIXZ17j0YeABDHWpsHASTjMdupvdwma20TlA3ruNV9WqDn1VE8hDTB4waAImqbZI0bBMdqDFVE0q50DSl2uzzO8X825CLjIa/E0U6JPid41hGOdadZph5Gbpnlou8xwOgRfzG1yyptPCKrAJcgIvsSz/CsYCqaoPCpil4TFjUq4PH0cWo6GlXN95TPX0LrAOh8WMCb7lZYXq5Q2TZ/sn5jF1GIiZZFWVUZujXK2og0I04 [...]
+ // key update compare
+ err = s.NewKubeTlsSecret(secretName, certUpdate, keyUpdate)
+ assert.Nil(ginkgo.GinkgoT(), err, "create secret error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tlsUpdate, err := s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tlsUpdate error")
+ assert.Len(ginkgo.GinkgoT(), tlsUpdate, 1, "tls number not expect")
+ assert.Equal(ginkgo.GinkgoT(), certUpdate, tlsUpdate[0].Cert, "tls cert not expect")
+ assert.Equal(ginkgo.GinkgoT(), keyCompareUpdate, tlsUpdate[0].Key, "tls key not expect")
+ // check DP
+ s.NewAPISIXHttpsClient(host).GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK).Body().Raw()
- // delete ApisixTls
- err = s.DeleteApisixTls(tlsName, host, secretName)
- assert.Nil(ginkgo.GinkgoT(), err, "delete tls error")
- // check ssl in APISIX
- time.Sleep(10 * time.Second)
- tls, err = s.ListApisixSsl()
- assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
- assert.Len(ginkgo.GinkgoT(), tls, 0, "tls number not expect")
+ // delete ApisixTls
+ err = s.DeleteApisixTls(tlsName, host, secretName)
+ assert.Nil(ginkgo.GinkgoT(), err, "delete tls error")
+ // check ssl in APISIX
+ time.Sleep(10 * time.Second)
+ tls, err = s.ListApisixSsl()
+ assert.Nil(ginkgo.GinkgoT(), err, "list tls error")
+ assert.Len(ginkgo.GinkgoT(), tls, 0, "tls number not expect")
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
diff --git a/test/e2e/suite-ingress/ssl.go b/test/e2e/suite-ingress/ssl.go
index 8098282d..bab445fd 100644
--- a/test/e2e/suite-ingress/ssl.go
+++ b/test/e2e/suite-ingress/ssl.go
@@ -511,7 +511,7 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
time.Sleep(10 * time.Second)
apisixRoutes, err := s.ListApisixRoutes()
diff --git a/test/e2e/suite-ingress/status.go b/test/e2e/suite-ingress/status.go
index 2d67595a..d7226e37 100644
--- a/test/e2e/suite-ingress/status.go
+++ b/test/e2e/suite-ingress/status.go
@@ -28,18 +28,10 @@ import (
)
var _ = ginkgo.Describe("suite-ingress: Status subresource Testing", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("check the status is recorded", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("check the status is recorded", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -56,19 +48,27 @@ spec:
- serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
- 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")
- // status should be recorded as successful
- output, err := s.GetOutputFromString("ar", "httpbin-route", "-o", "yaml")
- assert.Nil(ginkgo.GinkgoT(), err, "Get output of ApisixRoute resource")
- hasType := strings.Contains(output, "type: ResourcesAvailable")
- assert.True(ginkgo.GinkgoT(), hasType, "Status is recorded")
- hasMsg := strings.Contains(output, "message: Sync Successfully")
- assert.True(ginkgo.GinkgoT(), hasMsg, "Status is recorded")
+ 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")
+ // status should be recorded as successful
+ output, err := s.GetOutputFromString("ar", "httpbin-route", "-o", "yaml")
+ assert.Nil(ginkgo.GinkgoT(), err, "Get output of ApisixRoute resource")
+ hasType := strings.Contains(output, "type: ResourcesAvailable")
+ assert.True(ginkgo.GinkgoT(), hasType, "Status is recorded")
+ hasMsg := strings.Contains(output, "message: Sync Successfully")
+ assert.True(ginkgo.GinkgoT(), hasMsg, "Status is recorded")
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
diff --git a/test/e2e/suite-ingress/stream.go b/test/e2e/suite-ingress/stream.go
index 7841d0ad..7b1a91b8 100644
--- a/test/e2e/suite-ingress/stream.go
+++ b/test/e2e/suite-ingress/stream.go
@@ -27,18 +27,10 @@ import (
)
var _ = ginkgo.Describe("suite-ingress: ApisixRoute stream Testing with v2beta2", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("stream tcp proxy", func() {
- backendSvc, backendSvcPort := s.DefaultHTTPBackend()
- apisixRoute := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("stream tcp proxy", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -54,25 +46,25 @@ spec:
servicePort: %d
`, backendSvc, backendSvcPort[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- time.Sleep(12 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
+ time.Sleep(12 * time.Second)
- err := s.EnsureNumApisixStreamRoutesCreated(1)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+ err := s.EnsureNumApisixStreamRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
- sr, err := s.ListApisixStreamRoutes()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), sr, 1)
- assert.Equal(ginkgo.GinkgoT(), sr[0].ServerPort, int32(9100))
+ sr, err := s.ListApisixStreamRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), sr, 1)
+ assert.Equal(ginkgo.GinkgoT(), sr[0].ServerPort, int32(9100))
- resp := s.NewAPISIXClientWithTCPProxy().GET("/ip").Expect()
- resp.Body().Contains("origin")
+ resp := s.NewAPISIXClientWithTCPProxy().GET("/ip").Expect()
+ resp.Body().Contains("origin")
- resp = s.NewAPISIXClientWithTCPProxy().GET("/get").WithHeader("x-my-header", "x-my-value").Expect()
- resp.Body().Contains("x-my-value")
- })
- ginkgo.It("stream udp proxy", func() {
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ resp = s.NewAPISIXClientWithTCPProxy().GET("/get").WithHeader("x-my-header", "x-my-value").Expect()
+ resp.Body().Contains("x-my-value")
+ })
+ ginkgo.It("stream udp proxy", func() {
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -105,7 +97,7 @@ spec:
containerPort: 53
protocol: UDP
`))
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(`
kind: Service
apiVersion: v1
metadata:
@@ -120,9 +112,9 @@ spec:
protocol: UDP
`))
- s.EnsureNumEndpointsReady(ginkgo.GinkgoT(), "coredns", 1)
+ s.EnsureNumEndpointsReady(ginkgo.GinkgoT(), "coredns", 1)
- apisixRoute := fmt.Sprintf(`
+ apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -137,24 +129,31 @@ spec:
serviceName: coredns
servicePort: 53
`)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute))
- defer func() {
- err := s.RemoveResourceByString(apisixRoute)
- assert.Nil(ginkgo.GinkgoT(), err)
- }()
- time.Sleep(9 * time.Second)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(apisixRoute))
+ defer func() {
+ err := s.RemoveResourceByString(apisixRoute)
+ assert.Nil(ginkgo.GinkgoT(), err)
+ }()
+ time.Sleep(9 * time.Second)
- err := s.EnsureNumApisixStreamRoutesCreated(1)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+ err := s.EnsureNumApisixStreamRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
- sr, err := s.ListApisixStreamRoutes()
- assert.Nil(ginkgo.GinkgoT(), err)
- assert.Len(ginkgo.GinkgoT(), sr, 1)
- assert.Equal(ginkgo.GinkgoT(), sr[0].ServerPort, int32(9200))
- // test dns query
- r := s.DNSResolver()
- host := "httpbin.org"
- _, err = r.LookupIPAddr(context.Background(), host)
- assert.Nil(ginkgo.GinkgoT(), err, "dns query error")
+ sr, err := s.ListApisixStreamRoutes()
+ assert.Nil(ginkgo.GinkgoT(), err)
+ assert.Len(ginkgo.GinkgoT(), sr, 1)
+ assert.Equal(ginkgo.GinkgoT(), sr[0].ServerPort, int32(9200))
+ // test dns query
+ r := s.DNSResolver()
+ host := "httpbin.org"
+ _, err = r.LookupIPAddr(context.Background(), host)
+ assert.Nil(ginkgo.GinkgoT(), err, "dns query error")
+ })
+ }
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
diff --git a/test/e2e/suite-ingress/upstream_tls.go b/test/e2e/suite-ingress/upstream_tls.go
index 59ec42a7..5adc7743 100644
--- a/test/e2e/suite-ingress/upstream_tls.go
+++ b/test/e2e/suite-ingress/upstream_tls.go
@@ -38,15 +38,15 @@ var _ = ginkgo.Describe("suite-ingress: ApisixUpstreams mTLS test", func() {
assert.NoError(ginkgo.GinkgoT(), err, "read client key")
clientKey := string(f)
- s := scaffold.NewDefaultScaffold()
- ginkgo.It("create ApisixUpstreams with http mTLS", func() {
- // create client secret
- err := s.NewSecret(clientSecret, clientCert, clientKey)
- assert.NoError(ginkgo.GinkgoT(), err, "create client cert secret")
-
- err = s.NewApisixUpstreamsWithMTLS("test-backend-service-e2e-test", "https", clientSecret)
- assert.NoError(ginkgo.GinkgoT(), err, "create ApisixUpstreams with client secret")
- err = s.CreateResourceFromString(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("create ApisixUpstreams with http mTLS", func() {
+ // create client secret
+ err := s.NewSecret(clientSecret, clientCert, clientKey)
+ assert.NoError(ginkgo.GinkgoT(), err, "create client cert secret")
+
+ err = s.NewApisixUpstreamsWithMTLS("test-backend-service-e2e-test", "https", clientSecret)
+ assert.NoError(ginkgo.GinkgoT(), err, "create ApisixUpstreams with client secret")
+ err = s.CreateVersionedApisixResource(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -68,37 +68,37 @@ spec:
host: 'e2e.apisix.local'
name: upstream-is-mtls
`)
- assert.NoError(ginkgo.GinkgoT(), err, "create ApisixRoute for backend that require mTLS")
- time.Sleep(10 * time.Second)
- apisixRoutes, err := s.ListApisixRoutes()
- assert.NoError(ginkgo.GinkgoT(), err, "list routes error")
- assert.Len(ginkgo.GinkgoT(), apisixRoutes, 1, "route number not expect")
+ assert.NoError(ginkgo.GinkgoT(), err, "create ApisixRoute for backend that require mTLS")
+ time.Sleep(10 * time.Second)
+ apisixRoutes, err := s.ListApisixRoutes()
+ assert.NoError(ginkgo.GinkgoT(), err, "list routes error")
+ assert.Len(ginkgo.GinkgoT(), apisixRoutes, 1, "route number not expect")
- s.NewAPISIXClient().GET("/hello").WithHeader("Host", "upstream-is-mtls.httpbin.local").Expect().Status(http.StatusOK).Body().Raw()
- })
+ s.NewAPISIXClient().GET("/hello").WithHeader("Host", "upstream-is-mtls.httpbin.local").Expect().Status(http.StatusOK).Body().Raw()
+ })
- ginkgo.It("create ApisixUpstreams with grpc mTLS", func() {
- // create grpc secret for apisix grpc route
- grpcSecret := `grpc-secret`
- f, err := ioutil.ReadFile("testbackend/tls/server.pem")
- assert.NoError(ginkgo.GinkgoT(), err, "read server cert")
- serverCert := string(f)
+ ginkgo.It("create ApisixUpstreams with grpc mTLS", func() {
+ // create grpc secret for apisix grpc route
+ grpcSecret := `grpc-secret`
+ f, err := ioutil.ReadFile("testbackend/tls/server.pem")
+ assert.NoError(ginkgo.GinkgoT(), err, "read server cert")
+ serverCert := string(f)
- f, err = ioutil.ReadFile("testbackend/tls/server.key")
- assert.NoError(ginkgo.GinkgoT(), err, "read server key")
- serverKey := string(f)
+ f, err = ioutil.ReadFile("testbackend/tls/server.key")
+ assert.NoError(ginkgo.GinkgoT(), err, "read server key")
+ serverKey := string(f)
- err = s.NewSecret(grpcSecret, serverCert, serverKey)
- assert.NoError(ginkgo.GinkgoT(), err, "create server cert secret")
+ err = s.NewSecret(grpcSecret, serverCert, serverKey)
+ assert.NoError(ginkgo.GinkgoT(), err, "create server cert secret")
- // create client secret
- err = s.NewSecret(clientSecret, clientCert, clientKey)
- assert.NoError(ginkgo.GinkgoT(), err, "create client cert secret")
+ // create client secret
+ err = s.NewSecret(clientSecret, clientCert, clientKey)
+ assert.NoError(ginkgo.GinkgoT(), err, "create client cert secret")
- err = s.NewApisixUpstreamsWithMTLS("test-backend-service-e2e-test", "grpcs", clientSecret)
- assert.NoError(ginkgo.GinkgoT(), err, "create ApisixUpstreams with client secret")
+ err = s.NewApisixUpstreamsWithMTLS("test-backend-service-e2e-test", "grpcs", clientSecret)
+ assert.NoError(ginkgo.GinkgoT(), err, "create ApisixUpstreams with client secret")
- assert.NoError(ginkgo.GinkgoT(), s.CreateResourceFromString(`
+ assert.NoError(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -116,16 +116,24 @@ spec:
servicePort: 50053
`))
- assert.NoError(ginkgo.GinkgoT(), s.NewApisixTls("grpc-secret", "e2e.apisix.local", "grpc-secret"))
+ assert.NoError(ginkgo.GinkgoT(), s.NewApisixTls("grpc-secret", "e2e.apisix.local", "grpc-secret"))
+
+ assert.NoError(ginkgo.GinkgoT(), err, "create ApisixRoute for backend that require mTLS")
+ time.Sleep(10 * time.Second)
+ apisixRoutes, err := s.ListApisixRoutes()
+ assert.NoError(ginkgo.GinkgoT(), err, "list routes error")
+ assert.Len(ginkgo.GinkgoT(), apisixRoutes, 1, "route number not expect")
- assert.NoError(ginkgo.GinkgoT(), err, "create ApisixRoute for backend that require mTLS")
- time.Sleep(10 * time.Second)
- apisixRoutes, err := s.ListApisixRoutes()
- assert.NoError(ginkgo.GinkgoT(), err, "list routes error")
- assert.Len(ginkgo.GinkgoT(), apisixRoutes, 1, "route number not expect")
+ ca, err := ioutil.ReadFile("testbackend/tls/ca.pem")
+ assert.NoError(ginkgo.GinkgoT(), err, "read ca cert")
+ assert.NoError(ginkgo.GinkgoT(), client.RequestHello(s.GetAPISIXHTTPSEndpoint(), ca), "request apisix using grpc protocol")
+ })
+ }
- ca, err := ioutil.ReadFile("testbackend/tls/ca.pem")
- assert.NoError(ginkgo.GinkgoT(), err, "read ca cert")
- assert.NoError(ginkgo.GinkgoT(), client.RequestHello(s.GetAPISIXHTTPSEndpoint(), ca), "request apisix using grpc protocol")
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold())
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold())
})
})
diff --git a/test/e2e/suite-ingress/webhook.go b/test/e2e/suite-ingress/webhook.go
index 86cfccfe..abb0a8cf 100644
--- a/test/e2e/suite-ingress/webhook.go
+++ b/test/e2e/suite-ingress/webhook.go
@@ -25,22 +25,12 @@ import (
)
var _ = ginkgo.Describe("suite-ingress: Enable webhooks", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- // EnableWebhooks: true,
- }
- s := scaffold.NewScaffold(opts)
-
- ginkgo.It("should fail to create the ApisixRoute with invalid plugin configuration", func() {
- // #FIXME: just skip this case and we can enable it on other PR
- ginkgo.Skip("just skip this case")
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.It("should fail to create the ApisixRoute with invalid plugin configuration", func() {
+ // #FIXME: just skip this case and we can enable it on other PR
+ ginkgo.Skip("just skip this case")
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -64,11 +54,35 @@ spec:
break_response_code: 100 # should in [200, 599]
`, backendSvc, backendPorts[0])
- err := s.CreateResourceFromString(ar)
- assert.Error(ginkgo.GinkgoT(), err, "Failed to create ApisixRoute")
- assert.Contains(ginkgo.GinkgoT(), err.Error(), "admission webhook")
- assert.Contains(ginkgo.GinkgoT(), err.Error(), "denied the request")
- assert.Contains(ginkgo.GinkgoT(), err.Error(), "api-breaker plugin's config is invalid")
- assert.Contains(ginkgo.GinkgoT(), err.Error(), "Must be greater than or equal to 200")
+ err := s.CreateResourceFromString(ar)
+ assert.Error(ginkgo.GinkgoT(), err, "Failed to create ApisixRoute")
+ assert.Contains(ginkgo.GinkgoT(), err.Error(), "admission webhook")
+ assert.Contains(ginkgo.GinkgoT(), err.Error(), "denied the request")
+ assert.Contains(ginkgo.GinkgoT(), err.Error(), "api-breaker plugin's config is invalid")
+ assert.Contains(ginkgo.GinkgoT(), err.Error(), "Must be greater than or equal to 200")
+ })
+ }
+
+ ginkgo.Describe("suite-ingress: scaffold v2beta3", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "webhook",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2beta3,
+ EnableWebhooks: false,
+ }))
+ })
+ ginkgo.Describe("suite-ingress: scaffold v2", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "webhook",
+ Kubeconfig: scaffold.GetKubeconfig(),
+ APISIXConfigPath: "testdata/apisix-gw-config.yaml",
+ IngressAPISIXReplicas: 1,
+ HTTPBinServicePort: 80,
+ ApisixResourceVersion: scaffold.ApisixResourceVersion().V2,
+ EnableWebhooks: false,
+ }))
})
})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-general/echo.go b/test/e2e/suite-plugins-all/suite-plugins-general/echo.go
new file mode 100644
index 00000000..031a96b2
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-general/echo.go
@@ -0,0 +1,236 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-general: echo plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("insert preface and epilogue", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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:
+ before_body: "This is the preface"
+ after_body: "This is the epilogue"
+ headers:
+ X-Foo: v1
+ X-Foo2: v2
+
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("X-Foo").Equal("v1")
+ resp.Header("X-Foo2").Equal("v2")
+ resp.Body().Contains("This is the preface")
+ resp.Body().Contains("origin")
+ resp.Body().Contains("This is the epilogue")
+ })
+
+ ginkgo.It("replace body", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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/v2beta3
+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.CreateVersionedApisixResource(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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-general: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-general: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-general/redirect.go b/test/e2e/suite-plugins-all/suite-plugins-general/redirect.go
new file mode 100644
index 00000000..dbe25472
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-general/redirect.go
@@ -0,0 +1,221 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-general: redirect plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("http_to_https", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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:
+ http_to_https: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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.StatusMovedPermanently)
+ resp.Header("Location").Equal("https://httpbin.org/ip")
+ })
+ ginkgo.It("redirect to specific uri", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+ config:
+ http_to_https: true
+ uri: "$uri/ipip"
+ ret_code: 308
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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)
+ })
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+ time.Sleep(5 * time.Second)
+ 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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-general: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-general: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins/server-info.go b/test/e2e/suite-plugins-all/suite-plugins-general/server-info.go
similarity index 95%
rename from test/e2e/suite-plugins/server-info.go
rename to test/e2e/suite-plugins-all/suite-plugins-general/server-info.go
index d8246f2c..2fbe7673 100644
--- a/test/e2e/suite-plugins/server-info.go
+++ b/test/e2e/suite-plugins-all/suite-plugins-general/server-info.go
@@ -21,7 +21,7 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)
-var _ = ginkgo.Describe("suite-plugins: server-info plugin", func() {
+var _ = ginkgo.Describe("suite-plugins-general: server-info plugin", func() {
opts := &scaffold.Options{
Name: "default",
Kubeconfig: scaffold.GetKubeconfig(),
diff --git a/test/e2e/suite-plugins/plugin_config.go b/test/e2e/suite-plugins-all/suite-plugins-other/plugin_config.go
similarity index 94%
rename from test/e2e/suite-plugins/plugin_config.go
rename to test/e2e/suite-plugins-all/suite-plugins-other/plugin_config.go
index b223c927..545c865a 100644
--- a/test/e2e/suite-plugins/plugin_config.go
+++ b/test/e2e/suite-plugins-all/suite-plugins-other/plugin_config.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)
-var _ = ginkgo.Describe("suite-plugins: ApisixPluginConfig", func() {
+var _ = ginkgo.Describe("suite-plugins-other: ApisixPluginConfig", func() {
suites := func(scaffoldFunc func() *scaffold.Scaffold) {
s := scaffoldFunc()
ginkgo.It("add crd from definition", func() {
@@ -74,7 +74,7 @@ spec:
weight: 10
plugin_config_name: echo-and-cors-apc
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err = s.EnsureNumApisixRoutesCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
@@ -135,7 +135,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
@@ -185,7 +185,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
time.Sleep(6 * time.Second)
err := s.EnsureNumApisixUpstreamsCreated(1)
@@ -237,7 +237,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
@@ -310,7 +310,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixPluginConfigCreated(1)
@@ -368,7 +368,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixPluginConfigCreated(1)
@@ -435,7 +435,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixPluginConfigCreated(1)
@@ -487,7 +487,7 @@ spec:
plugin_config_name: test-apc-1
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixPluginConfigCreated(1)
@@ -517,7 +517,7 @@ spec:
`)
assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixPluginConfig(apc))
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
err = s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixPluginConfigCreated(1)
@@ -538,10 +538,10 @@ spec:
})
}
- ginkgo.Describe("suite-plugins: scaffold v2beta3", func() {
+ ginkgo.Describe("suite-plugins-other: scaffold v2beta3", func() {
suites(scaffold.NewDefaultScaffold)
})
- ginkgo.Describe("suite-plugins: scaffold v2", func() {
+ ginkgo.Describe("suite-plugins-other: scaffold v2", func() {
suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-plugins/serverless.go b/test/e2e/suite-plugins-all/suite-plugins-other/serverless.go
similarity index 59%
rename from test/e2e/suite-plugins/serverless.go
rename to test/e2e/suite-plugins-all/suite-plugins-other/serverless.go
index 587f1ef9..7ee87c36 100644
--- a/test/e2e/suite-plugins/serverless.go
+++ b/test/e2e/suite-plugins-all/suite-plugins-other/serverless.go
@@ -24,19 +24,12 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)
-var _ = ginkgo.Describe("suite-plugins: serverless plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("enable serverless plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+var _ = ginkgo.Describe("suite-plugins-other: serverless plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("enable serverless plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -60,18 +53,18 @@ spec:
functions: ["return function() local core = require(\"apisix.core\"); core.response.exit(403); end"]
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
- err := s.EnsureNumApisixRoutesCreated(1)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+ 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.StatusForbidden)
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusForbidden)
- })
- ginkgo.It("disable serverless plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ })
+ ginkgo.It("disable serverless plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -89,13 +82,21 @@ spec:
servicePort: %d
`, backendSvc, backendPorts[0])
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
- err := s.EnsureNumApisixRoutesCreated(1)
- assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+ 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 := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-other: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-other: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/consumer-restriction.go b/test/e2e/suite-plugins-all/suite-plugins-security/consumer-restriction.go
new file mode 100644
index 00000000..c0c09d70
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/consumer-restriction.go
@@ -0,0 +1,231 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: consumer-restriction plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+
+ ginkgo.It("restrict consumer_name", func() {
+ err := s.ApisixConsumerBasicAuthCreated("jack1", "jack1-username", "jack1-password")
+ assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
+
+ err = s.ApisixConsumerBasicAuthCreated("jack2", "jack2-username", "jack2-password")
+ assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
+
+ // Wait until the ApisixConsumer create event was delivered.
+ time.Sleep(6 * time.Second)
+
+ grs, err := s.ListApisixConsumers()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing consumer")
+ assert.Len(ginkgo.GinkgoT(), grs, 2)
+
+ assert.Len(ginkgo.GinkgoT(), grs[0].Plugins, 1)
+ assert.Len(ginkgo.GinkgoT(), grs[1].Plugins, 1)
+
+ username := grs[0].Username
+ basicAuth := grs[0].Plugins["basic-auth"]
+ assert.Equal(ginkgo.GinkgoT(), basicAuth, map[string]interface{}{
+ "username": "jack1-username",
+ "password": "jack1-password",
+ })
+
+ basicAuth2 := grs[1].Plugins["basic-auth"]
+ assert.Equal(ginkgo.GinkgoT(), basicAuth2, map[string]interface{}{
+ "username": "jack2-username",
+ "password": "jack2-password",
+ })
+
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ authentication:
+ enable: true
+ type: basicAuth
+ plugins:
+ - name: consumer-restriction
+ enable: true
+ config:
+ whitelist:
+ - "%s"
+`, backendSvc, backendPorts[0], username)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with basicAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
+
+ _ = s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusOK)
+
+ msg401 := s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusUnauthorized).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg401, "Missing authorization in request")
+
+ msg403 := s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusForbidden).
+ Body().
+ Raw()
+
+ assert.Contains(ginkgo.GinkgoT(), msg403, "The consumer_name is forbidden")
+ })
+
+ ginkgo.It("restrict allowed_by_methods", func() {
+ err := s.ApisixConsumerBasicAuthCreated("jack1", "jack1-username", "jack1-password")
+ assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
+
+ err = s.ApisixConsumerBasicAuthCreated("jack2", "jack2-username", "jack2-password")
+ assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
+
+ // Wait until the ApisixConsumer create event was delivered.
+ time.Sleep(6 * time.Second)
+
+ grs, err := s.ListApisixConsumers()
+ assert.Nil(ginkgo.GinkgoT(), err, "listing consumer")
+ assert.Len(ginkgo.GinkgoT(), grs, 2)
+
+ assert.Len(ginkgo.GinkgoT(), grs[0].Plugins, 1)
+ assert.Len(ginkgo.GinkgoT(), grs[1].Plugins, 1)
+
+ username := grs[0].Username
+ basicAuth := grs[0].Plugins["basic-auth"]
+ assert.Equal(ginkgo.GinkgoT(), basicAuth, map[string]interface{}{
+ "username": "jack1-username",
+ "password": "jack1-password",
+ })
+
+ username2 := grs[1].Username
+ basicAuth2 := grs[1].Plugins["basic-auth"]
+ assert.Equal(ginkgo.GinkgoT(), basicAuth2, map[string]interface{}{
+ "username": "jack2-username",
+ "password": "jack2-password",
+ })
+
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ authentication:
+ enable: true
+ type: basicAuth
+ plugins:
+ - name: consumer-restriction
+ enable: true
+ config:
+ allowed_by_methods:
+ - user: "%s"
+ methods:
+ - "POST"
+ - "GET"
+ - user: "%s"
+ methods:
+ - "GET"
+`, backendSvc, backendPorts[0], username, username2)
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar), "creating ApisixRoute with basicAuth")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
+ assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
+
+ _ = s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusOK)
+
+ msg403 := s.NewAPISIXClient().POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
+ Expect().
+ Status(http.StatusForbidden).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg403, "The consumer_name is forbidden")
+
+ msg401 := s.NewAPISIXClient().GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusUnauthorized).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg401, "Missing authorization in request")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/cors.go b/test/e2e/suite-plugins-all/suite-plugins-security/cors.go
new file mode 100644
index 00000000..43dfd865
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/cors.go
@@ -0,0 +1,331 @@
+// 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"
+ "net/http"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: fault-injection plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("empty config", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ ginkgo.It("finer granularity config", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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
+ config:
+ allow_origins: http://foo.bar.org
+ allow_methods: "GET,POST"
+ max_age: 3600
+ expose_headers: x-foo,x-baz
+ allow_headers: x-from-ingress
+ allow_credential: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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").
+ WithHeader("Origin", "http://foo.bar.org").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Header("Access-Control-Allow-Origin").Equal("http://foo.bar.org")
+ resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
+ resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
+ resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
+ resp.Header("Access-Control-Max-Age").Equal("3600")
+ resp.Header("Access-Control-Allow-Credentials").Equal("true")
+ resp.Body().Contains("origin")
+
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Origin", "http://foo.bar2.org").
+ Expect()
+ 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()
+ // httpbin set it by itself.
+ // resp.Header("Access-Control-Allow-Credentials").Empty()
+ resp.Body().Contains("origin")
+ })
+ ginkgo.It("allow_origins_by_regex", func() {
+ ginkgo.Skip("APISIX version priors to 2.5 doesn't contain allow_origins_by_regex in cors plugin")
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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
+ config:
+ allow_origins_by_regex:
+ - foo\\.(bar|baz)\\.org
+ allow_methods: "GET,POST"
+ max_age: 3600
+ expose_headers: x-foo,x-baz
+ allow_headers: x-from-ingress
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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").
+ WithHeader("Origin", "http://foo.bar.org").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Header("Access-Control-Allow-Origin").Equal("http://foo.bar.org")
+ resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
+ resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
+ resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
+ resp.Header("Access-Control-Max-Age").Equal("3600")
+ resp.Header("Access-Control-Allow-Credentials").Equal("true")
+ resp.Body().Contains("origin")
+
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Origin", "http://foo.baz.org").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Header("Access-Control-Allow-Origin").Equal("http://foo.baz.org")
+ resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
+ resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
+ resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
+ resp.Header("Access-Control-Max-Age").Equal("3600")
+ resp.Header("Access-Control-Allow-Credentials").Equal("true")
+ resp.Body().Contains("origin")
+
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Origin", "http://foo.bar2.org").
+ Expect()
+ 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()
+ // httpbin set it by itself.
+ // resp.Header("Access-Control-Allow-Credentials").Empty()
+ resp.Body().Contains("origin")
+ })
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+ })
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/csrf.go b/test/e2e/suite-plugins-all/suite-plugins-security/csrf.go
new file mode 100644
index 00000000..8af82f83
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/csrf.go
@@ -0,0 +1,142 @@
+// 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"
+ "net/http"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: csrf plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("prevent csrf", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ plugins:
+ - name: csrf
+ enable: true
+ config:
+ key: "edd1c9f034335f136f87ad84b625c8f1"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ msg401 := s.NewAPISIXClient().
+ POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusUnauthorized).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg401, "no csrf token in headers")
+
+ resp := s.NewAPISIXClient().
+ GET("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+ resp.Header("Set-Cookie").NotEmpty()
+
+ cookie := resp.Cookie("apisix-csrf-token")
+ token := cookie.Value().Raw()
+
+ _ = s.NewAPISIXClient().
+ POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("apisix-csrf-token", token).
+ WithCookie("apisix-csrf-token", token).
+ Expect().
+ Status(http.StatusOK)
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ plugins:
+ - name: csrf
+ enable: false
+ config:
+ key: "edd1c9f034335f136f87ad84b625c8f1"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().
+ POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/ip-restriction.go b/test/e2e/suite-plugins-all/suite-plugins-security/ip-restriction.go
new file mode 100644
index 00000000..59544ce1
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/ip-restriction.go
@@ -0,0 +1,239 @@
+// 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"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: ip-restriction plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("ip whitelist", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: ip-restriction
+ enable: true
+ config:
+ whitelist:
+ - "192.168.3.3"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // As we use port forwarding so the ip address is 127.0.0.1
+ s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(403).
+ Body().
+ Contains("Your IP address is not allowed")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: ip-restriction
+ enable: true
+ config:
+ whitelist:
+ - "127.0.0.1"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // As we use port forwarding so the ip address is 127.0.0.1
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+ ginkgo.It("ip blacklist", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: ip-restriction
+ enable: true
+ config:
+ blacklist:
+ - "127.0.0.1"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // As we use port forwarding so the ip address is 127.0.0.1
+ s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(403).
+ Body().
+ Contains("Your IP address is not allowed")
+
+ ar = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: ip-restriction
+ enable: true
+ config:
+ blacklist:
+ - "192.168.12.12"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // As we use port forwarding so the ip address is 127.0.0.1
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: ip-restriction
+ enable: false
+ config:
+ blacklist:
+ - "127.0.0.1"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // As we use port forwarding so the ip address is 127.0.0.1
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/referer-restriction.go b/test/e2e/suite-plugins-all/suite-plugins-security/referer-restriction.go
new file mode 100644
index 00000000..4597a077
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/referer-restriction.go
@@ -0,0 +1,320 @@
+// 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"
+ "net/http"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: referer-restriction plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("configure a access list", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: referer-restriction
+ enable: true
+ config:
+ whitelist:
+ - test.com
+ - "*.foo.com"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // "Referer" match passed
+ resp := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://test.com").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ // "Referer" match failed
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://www.test.com").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("Your referer host is not allowed")
+
+ // "Referer" match passed
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://www.foo.com").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ // "Referer" is missing
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("Your referer host is not allowed")
+ })
+
+ ginkgo.It("configure a deny access list", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: referer-restriction
+ enable: true
+ config:
+ blacklist:
+ - test.com
+ - "*.foo.com"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of routes")
+
+ // "Referer" match failed
+ resp := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://test.com").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("Your referer host is not allowed")
+
+ // "Referer" match passed
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://www.test.com").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ // "Referer" match failed
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://www.foo.com").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("Your referer host is not allowed")
+
+ // "Referer" is missing
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("Your referer host is not allowed")
+ })
+
+ ginkgo.It("customize return message", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: referer-restriction
+ enable: true
+ config:
+ whitelist:
+ - test.com
+ - "*.foo.com"
+ message: "You can customize the message any way you like"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of routes")
+
+ // "Referer" match failed
+ resp := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://www.test.com").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("You can customize the message any way you like")
+
+ // "Referer" is missing
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ Expect()
+ resp.Status(http.StatusForbidden)
+ resp.Body().Contains("You can customize the message any way you like")
+ })
+
+ ginkgo.It("configure bypass_missing field to true", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: referer-restriction
+ enable: true
+ config:
+ whitelist:
+ - test.com
+ bypass_missing: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ err := s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of upstreams")
+ err = s.EnsureNumApisixRoutesCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "Checking the number of routes")
+
+ // "Referer" is missing
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ // "Referer" format is incorrect
+ resp = s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "test.com").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: referer-restriction
+ enable: false
+ config:
+ whitelist:
+ - test.com
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // "Referer" is not in the whitelist.
+ resp := s.NewAPISIXClient().GET("/ip").
+ WithHeader("Host", "httpbin.org").
+ WithHeader("Referer", "http://foo.com").
+ Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+
+ // "Referer" is missing
+ resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ resp.Body().Contains("origin")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-security/uri_blocker.go b/test/e2e/suite-plugins-all/suite-plugins-security/uri_blocker.go
new file mode 100644
index 00000000..71a5a80d
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-security/uri_blocker.go
@@ -0,0 +1,246 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-security: uri-blocker plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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(403)
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(403)
+ s.NewAPISIXClient().GET("/status/206").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(404).
+ Body().
+ Contains("404 Route Not Found")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+ config:
+ rejected_code: 403
+ block_rules:
+ - /status/200
+ - /headers
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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(200)
+ s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("httpbin.org")
+ s.NewAPISIXClient().GET("/status/206").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(404).
+ Body().
+ Contains("404 Route Not Found")
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(2 * time.Second)
+ 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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-security: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-security: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins/api_breaker.go b/test/e2e/suite-plugins-all/suite-plugins-traffic/api_breaker.go
similarity index 54%
rename from test/e2e/suite-plugins/api_breaker.go
rename to test/e2e/suite-plugins-all/suite-plugins-traffic/api_breaker.go
index b05ee066..9f8fc629 100644
--- a/test/e2e/suite-plugins/api_breaker.go
+++ b/test/e2e/suite-plugins-all/suite-plugins-traffic/api_breaker.go
@@ -25,19 +25,12 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)
-var _ = ginkgo.Describe("suite-plugins: api-breaker plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("sanity", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+var _ = ginkgo.Describe("suite-plugins-traffic: api-breaker plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -70,31 +63,31 @@ spec:
successes: 2
`, 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")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/status/200").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusOK)
+ resp := s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
- for i := 0; i < 2; i++ {
- resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(505)
- }
+ for i := 0; i < 2; i++ {
+ resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(505)
+ }
- // Trigger the api-breaker threshold
- resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusBadGateway)
+ // Trigger the api-breaker threshold
+ resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusBadGateway)
- time.Sleep(3500 * time.Millisecond)
- resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusOK)
- })
- ginkgo.It("disable plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
+ time.Sleep(3500 * time.Millisecond)
+ resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ })
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
@@ -127,22 +120,30 @@ spec:
successes: 2
`, 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")
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/status/200").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
- resp := s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(http.StatusOK)
+ for i := 0; i < 2; i++ {
+ resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(505)
+ }
- for i := 0; i < 2; i++ {
+ // Trigger the api-breaker threshold
resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
resp.Status(505)
- }
+ })
+ }
- // Trigger the api-breaker threshold
- resp = s.NewAPISIXClient().GET("/status/505").WithHeader("Host", "httpbin.org").Expect()
- resp.Status(505)
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
})
})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-traffic/client-control.go b/test/e2e/suite-plugins-all/suite-plugins-traffic/client-control.go
new file mode 100644
index 00000000..03589bc4
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-traffic/client-control.go
@@ -0,0 +1,132 @@
+// 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"
+ "net/http"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-traffic: client-control plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("Limit requset body size", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ plugins:
+ - name: client-control
+ enable: true
+ config:
+ max_body_size: 1
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ msg413 := s.NewAPISIXClient().
+ POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithBytes([]byte("char number cannot be greater than 10")).
+ Expect().
+ Status(http.StatusRequestEntityTooLarge).
+ Body().
+ Raw()
+ assert.Contains(ginkgo.GinkgoT(), msg413, "Request Entity Too Large")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /anything
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ plugins:
+ - name: client-control
+ enable: false
+ config:
+ max_body_size: 1
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/anything").
+ WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(http.StatusOK)
+
+ _ = s.NewAPISIXClient().
+ POST("/anything").
+ WithHeader("Host", "httpbin.org").
+ WithBytes([]byte("char number can be greater than 10")).
+ Expect().
+ Status(http.StatusOK)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-traffic/limit_count.go b/test/e2e/suite-plugins-all/suite-plugins-traffic/limit_count.go
new file mode 100644
index 00000000..b7c01a38
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-traffic/limit_count.go
@@ -0,0 +1,240 @@
+// 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"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-traffic: limit-count plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("localized dimension, limited by remote address", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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)
+ time.Sleep(3 * time.Second)
+ s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+ config:
+ rejected_code: 503
+ count: 2
+ time_window: 3
+ key: remote_addr
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+ })
+
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-traffic/request-validation.go b/test/e2e/suite-plugins-all/suite-plugins-traffic/request-validation.go
new file mode 100644
index 00000000..1476f3a5
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-traffic/request-validation.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 plugins
+
+import (
+ "fmt"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-traffic: redirect plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /post
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: request-validation
+ enable: true
+ config:
+ body_schema:
+ type: object
+ properties:
+ name:
+ type: string
+ minLength: 5
+ id:
+ type: integer
+ minimum: 20
+ required:
+ - id
+ header_schema:
+ type: object
+ properties:
+ user-agent:
+ type: string
+ pattern: .*Mozilla.*
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+ // header schema check failure.
+ resp := s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "bad-ua").Expect()
+ resp.Status(400)
+
+ payload := []byte(`
+{
+ "name": "bob",
+ "id": 33
+}
+ `)
+ // body schema check failure.
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(400)
+
+ payload = []byte(`
+{
+ "name": "long-name",
+ "id": 11
+}
+ `)
+ // body schema check failure.
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(400)
+
+ payload = []byte(`
+{
+ "name": "long-name",
+ "id": 55
+}
+ `)
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(200)
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /post
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: request-validation
+ enable: false
+ config:
+ body_schema:
+ type: object
+ properties:
+ name:
+ type: string
+ minLength: 5
+ id:
+ type: integer
+ minimum: 20
+ required:
+ - id
+ header_schema:
+ type: object
+ properties:
+ user-agent:
+ type: string
+ pattern: .*Mozilla.*
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "bad-ua").Expect()
+ resp.Status(200)
+
+ payload := []byte(`
+{
+ "name": "bob",
+ "id": 33
+}
+ `)
+ // body schema check failure.
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(200)
+
+ payload = []byte(`
+{
+ "name": "long-name",
+ "id": 11
+}
+ `)
+ // body schema check failure.
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(200)
+
+ payload = []byte(`
+{
+ "name": "long-name",
+ "id": 55
+}
+ `)
+ resp = s.NewAPISIXClient().POST("/post").WithHeader("Host", "httpbin.org").WithHeader("User-Agent", "aaaMozillabb").WithBytes(payload).Expect()
+ resp.Status(200)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-traffic/request_id.go b/test/e2e/suite-plugins-all/suite-plugins-traffic/request_id.go
new file mode 100644
index 00000000..d700e80f
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-traffic/request_id.go
@@ -0,0 +1,181 @@
+// 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"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-traffic: request-id plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("sanity", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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")
+ })
+ ginkgo.It("enable plugin and then delete it", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-traffic: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-transformation/fault_injection.go b/test/e2e/suite-plugins-all/suite-plugins-transformation/fault_injection.go
new file mode 100644
index 00000000..6d67762b
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-transformation/fault_injection.go
@@ -0,0 +1,244 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-transformation: fault-injection plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("inject code and body to abort request", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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
+ body: "internal server error"
+ vars:
+ - [ ["http_x_foo", "==", "bar"], ["arg_name", "==", "bob"] ]
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // vars unsatisfied
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+
+ resp = s.NewAPISIXClient().GET("/ip").WithQuery("name", "bob").WithHeader("Host", "httpbin.org").WithHeader("X-Foo", "bar").Expect()
+ resp.Status(http.StatusInternalServerError)
+ resp.Body().Equal("internal server error")
+ })
+
+ ginkgo.It("delay request", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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:
+ delay:
+ duration: 3
+ vars:
+ - [ ["http_x_foo", "==", "bar"], ["arg_name", "==", "bob"] ]
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // vars unsatisfied
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+
+ now := time.Now()
+ resp = s.NewAPISIXClient().GET("/ip").WithQuery("name", "bob").WithHeader("Host", "httpbin.org").WithHeader("X-Foo", "bar").Expect()
+ resp.Status(http.StatusOK)
+ assert.Less(ginkgo.GinkgoT(), float64((3 * time.Second).Nanoseconds()), float64(time.Since(now).Nanoseconds()))
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: false
+ config:
+ abort:
+ http_status: 500
+ body: "internal server error"
+ vars:
+ - [ ["http_x_foo", "==", "bar"], ["arg_name", "==", "bob"] ]
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // vars unsatisfied
+ resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+
+ 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/v2beta3
+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.CreateVersionedApisixResource(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/v2beta3
+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.CreateVersionedApisixResource(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")
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-transformation/proxy_rewrite.go b/test/e2e/suite-plugins-all/suite-plugins-transformation/proxy_rewrite.go
new file mode 100644
index 00000000..c8897175
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-transformation/proxy_rewrite.go
@@ -0,0 +1,241 @@
+// 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"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-transformation: proxy-rewrite plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("proxy rewrite request uri", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(200).
+ Body().
+ Contains("origin")
+ })
+
+ ginkgo.It("proxy rewrite request uri and host", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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").WithHeader("Host", "test.com").
+ Expect().
+ 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/v2beta3
+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:
+ - ^/hello/(.*)
+ - /$1
+ headers:
+ host: httpbin.org
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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("the regex_uri of the proxy-rewrite plugin does not match", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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)
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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.CreateVersionedApisixResource(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").WithHeader("Host", "httpbin.org").
+ Expect().
+ Status(404)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins-all/suite-plugins-transformation/response_rewrite.go b/test/e2e/suite-plugins-all/suite-plugins-transformation/response_rewrite.go
new file mode 100644
index 00000000..4cae34c0
--- /dev/null
+++ b/test/e2e/suite-plugins-all/suite-plugins-transformation/response_rewrite.go
@@ -0,0 +1,246 @@
+// 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"
+ "net/http"
+ "time"
+
+ ginkgo "github.com/onsi/ginkgo/v2"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-plugins-transformation: response rewrite plugin", func() {
+ suites := func(scaffoldFunc func() *scaffold.Scaffold) {
+ s := scaffoldFunc()
+ ginkgo.It("rewrite status code and headers", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: response-rewrite
+ enable: true
+ config:
+ status_code: 301
+ headers:
+ location: https://my.location/path
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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.StatusMovedPermanently)
+ resp.Header("Location").Equal("https://my.location/path")
+ })
+
+ ginkgo.It("rewrite body", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: response-rewrite
+ enable: true
+ config:
+ body: "hello\nworld"
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(ar))
+
+ time.Sleep(6 * time.Second)
+ 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("hello\nworld")
+ })
+
+ ginkgo.It("rewrite body in base64", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+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: response-rewrite
+ enable: true
+ config:
+ body: "aGVsbG9cbndvcmxk"
+ body_base64: true
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("hello\\nworld")
+ })
+
+ ginkgo.It("conditional execution", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /status/*
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: response-rewrite
+ enable: true
+ config:
+ body: "aGVsbG9cbndvcmxk"
+ body_base64: true
+ status_code: 308
+ headers:
+ location: https://a.com/b/c
+ x-changed-by: apisix
+ vars:
+ - ["status", "==", 200]
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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")
+
+ // vars unsatisfied
+ resp := s.NewAPISIXClient().GET("/status/500").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusInternalServerError)
+ resp.Header("X-Changed-By").Empty()
+ resp.Header("Location").Empty()
+
+ resp = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusPermanentRedirect)
+ resp.Header("X-Changed-By").Equal("apisix")
+ resp.Header("Location").Equal("https://a.com/b/c")
+ resp.Body().Equal("hello\\nworld")
+ })
+
+ ginkgo.It("disable plugin", func() {
+ backendSvc, backendPorts := s.DefaultHTTPBackend()
+ ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+ match:
+ hosts:
+ - httpbin.org
+ paths:
+ - /status/*
+ backends:
+ - serviceName: %s
+ servicePort: %d
+ weight: 10
+ plugins:
+ - name: response-rewrite
+ enable: false
+ config:
+ status_code: 206
+`, backendSvc, backendPorts[0])
+
+ assert.Nil(ginkgo.GinkgoT(), s.CreateVersionedApisixResource(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("/status/200").WithHeader("Host", "httpbin.org").Expect()
+ resp.Status(http.StatusOK)
+ })
+ }
+
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2beta3", func() {
+ suites(scaffold.NewDefaultScaffold)
+ })
+ ginkgo.Describe("suite-plugins-transformation: scaffold v2", func() {
+ suites(scaffold.NewDefaultV2Scaffold)
+ })
+})
diff --git a/test/e2e/suite-plugins/client-control.go b/test/e2e/suite-plugins/client-control.go
deleted file mode 100644
index 3990b77a..00000000
--- a/test/e2e/suite-plugins/client-control.go
+++ /dev/null
@@ -1,131 +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"
- "net/http"
-
- ginkgo "github.com/onsi/ginkgo/v2"
- "github.com/stretchr/testify/assert"
-
- "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
-)
-
-var _ = ginkgo.Describe("suite-plugins: client-control plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("Limit requset body size", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- plugins:
- - name: client-control
- enable: true
- config:
- max_body_size: 1
-`, 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("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- msg413 := s.NewAPISIXClient().
- POST("/anything").
- WithHeader("Host", "httpbin.org").
- WithBytes([]byte("char number cannot be greater than 10")).
- Expect().
- Status(http.StatusRequestEntityTooLarge).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg413, "Request Entity Too Large")
- })
-
- ginkgo.It("disable plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- plugins:
- - name: client-control
- enable: false
- config:
- max_body_size: 1
-`, 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("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().
- POST("/anything").
- WithHeader("Host", "httpbin.org").
- WithBytes([]byte("char number can be greater than 10")).
- Expect().
- Status(http.StatusOK)
- })
-})
diff --git a/test/e2e/suite-plugins/consumer-restriction.go b/test/e2e/suite-plugins/consumer-restriction.go
deleted file mode 100644
index 3f755000..00000000
--- a/test/e2e/suite-plugins/consumer-restriction.go
+++ /dev/null
@@ -1,230 +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"
- "net/http"
- "time"
-
- ginkgo "github.com/onsi/ginkgo/v2"
- "github.com/stretchr/testify/assert"
-
- "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
-)
-
-var _ = ginkgo.Describe("suite-plugins: consumer-restriction plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
-
- ginkgo.It("restrict consumer_name", func() {
- err := s.ApisixConsumerBasicAuthCreated("jack1", "jack1-username", "jack1-password")
- assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
-
- err = s.ApisixConsumerBasicAuthCreated("jack2", "jack2-username", "jack2-password")
- assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
-
- // Wait until the ApisixConsumer create event was delivered.
- time.Sleep(6 * time.Second)
-
- grs, err := s.ListApisixConsumers()
- assert.Nil(ginkgo.GinkgoT(), err, "listing consumer")
- assert.Len(ginkgo.GinkgoT(), grs, 2)
-
- assert.Len(ginkgo.GinkgoT(), grs[0].Plugins, 1)
- assert.Len(ginkgo.GinkgoT(), grs[1].Plugins, 1)
-
- username := grs[0].Username
- basicAuth := grs[0].Plugins["basic-auth"]
- assert.Equal(ginkgo.GinkgoT(), basicAuth, map[string]interface{}{
- "username": "jack1-username",
- "password": "jack1-password",
- })
-
- basicAuth2 := grs[1].Plugins["basic-auth"]
- assert.Equal(ginkgo.GinkgoT(), basicAuth2, map[string]interface{}{
- "username": "jack2-username",
- "password": "jack2-password",
- })
-
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- authentication:
- enable: true
- type: basicAuth
- plugins:
- - name: consumer-restriction
- enable: true
- config:
- whitelist:
- - "%s"
-`, backendSvc, backendPorts[0], username)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with basicAuth")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
-
- _ = s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusOK)
-
- msg401 := s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusUnauthorized).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg401, "Missing authorization in request")
-
- msg403 := s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusForbidden).
- Body().
- Raw()
-
- assert.Contains(ginkgo.GinkgoT(), msg403, "The consumer_name is forbidden")
- })
-
- ginkgo.It("restrict allowed_by_methods", func() {
- err := s.ApisixConsumerBasicAuthCreated("jack1", "jack1-username", "jack1-password")
- assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
-
- err = s.ApisixConsumerBasicAuthCreated("jack2", "jack2-username", "jack2-password")
- assert.Nil(ginkgo.GinkgoT(), err, "creating basicAuth ApisixConsumer")
-
- // Wait until the ApisixConsumer create event was delivered.
- time.Sleep(6 * time.Second)
-
- grs, err := s.ListApisixConsumers()
- assert.Nil(ginkgo.GinkgoT(), err, "listing consumer")
- assert.Len(ginkgo.GinkgoT(), grs, 2)
-
- assert.Len(ginkgo.GinkgoT(), grs[0].Plugins, 1)
- assert.Len(ginkgo.GinkgoT(), grs[1].Plugins, 1)
-
- username := grs[0].Username
- basicAuth := grs[0].Plugins["basic-auth"]
- assert.Equal(ginkgo.GinkgoT(), basicAuth, map[string]interface{}{
- "username": "jack1-username",
- "password": "jack1-password",
- })
-
- username2 := grs[1].Username
- basicAuth2 := grs[1].Plugins["basic-auth"]
- assert.Equal(ginkgo.GinkgoT(), basicAuth2, map[string]interface{}{
- "username": "jack2-username",
- "password": "jack2-password",
- })
-
- backendSvc, backendPorts := s.DefaultHTTPBackend()
-
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- authentication:
- enable: true
- type: basicAuth
- plugins:
- - name: consumer-restriction
- enable: true
- config:
- allowed_by_methods:
- - user: "%s"
- methods:
- - "POST"
- - "GET"
- - user: "%s"
- methods:
- - "GET"
-`, backendSvc, backendPorts[0], username, username2)
- assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar), "creating ApisixRoute with basicAuth")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1), "Checking number of routes")
- assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")
-
- _ = s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().POST("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazEtdXNlcm5hbWU6amFjazEtcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusOK)
-
- msg403 := s.NewAPISIXClient().POST("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("Authorization", "Basic amFjazItdXNlcm5hbWU6amFjazItcGFzc3dvcmQ=").
- Expect().
- Status(http.StatusForbidden).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg403, "The consumer_name is forbidden")
-
- msg401 := s.NewAPISIXClient().GET("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusUnauthorized).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg401, "Missing authorization in request")
- })
-})
diff --git a/test/e2e/suite-plugins/cors.go b/test/e2e/suite-plugins/cors.go
deleted file mode 100644
index 9fed0020..00000000
--- a/test/e2e/suite-plugins/cors.go
+++ /dev/null
@@ -1,330 +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"
- "net/http"
-
- ginkgo "github.com/onsi/ginkgo/v2"
- "github.com/stretchr/testify/assert"
-
- "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
-)
-
-var _ = ginkgo.Describe("suite-plugins: fault-injection plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("empty config", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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")
- })
- ginkgo.It("finer granularity config", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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
- config:
- allow_origins: http://foo.bar.org
- allow_methods: "GET,POST"
- max_age: 3600
- expose_headers: x-foo,x-baz
- allow_headers: x-from-ingress
- allow_credential: 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").
- WithHeader("Origin", "http://foo.bar.org").
- Expect()
- resp.Status(http.StatusOK)
- resp.Header("Access-Control-Allow-Origin").Equal("http://foo.bar.org")
- resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
- resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
- resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
- resp.Header("Access-Control-Max-Age").Equal("3600")
- resp.Header("Access-Control-Allow-Credentials").Equal("true")
- resp.Body().Contains("origin")
-
- resp = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Origin", "http://foo.bar2.org").
- Expect()
- 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()
- // httpbin set it by itself.
- // resp.Header("Access-Control-Allow-Credentials").Empty()
- resp.Body().Contains("origin")
- })
- ginkgo.It("allow_origins_by_regex", func() {
- ginkgo.Skip("APISIX version priors to 2.5 doesn't contain allow_origins_by_regex in cors plugin")
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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
- config:
- allow_origins_by_regex:
- - foo\\.(bar|baz)\\.org
- allow_methods: "GET,POST"
- max_age: 3600
- expose_headers: x-foo,x-baz
- allow_headers: x-from-ingress
-`, 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").
- WithHeader("Origin", "http://foo.bar.org").
- Expect()
- resp.Status(http.StatusOK)
- resp.Header("Access-Control-Allow-Origin").Equal("http://foo.bar.org")
- resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
- resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
- resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
- resp.Header("Access-Control-Max-Age").Equal("3600")
- resp.Header("Access-Control-Allow-Credentials").Equal("true")
- resp.Body().Contains("origin")
-
- resp = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Origin", "http://foo.baz.org").
- Expect()
- resp.Status(http.StatusOK)
- resp.Header("Access-Control-Allow-Origin").Equal("http://foo.baz.org")
- resp.Header("Access-Control-Allow-Methods").Equal("GET,POST")
- resp.Header("Access-Control-Allow-Headers").Equal("x-from-ingress")
- resp.Header("Access-Control-Expose-Headers").Equal("x-foo,x-baz")
- resp.Header("Access-Control-Max-Age").Equal("3600")
- resp.Header("Access-Control-Allow-Credentials").Equal("true")
- resp.Body().Contains("origin")
-
- resp = s.NewAPISIXClient().GET("/ip").
- WithHeader("Host", "httpbin.org").
- WithHeader("Origin", "http://foo.bar2.org").
- Expect()
- 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()
- // httpbin set it by itself.
- // resp.Header("Access-Control-Allow-Credentials").Empty()
- resp.Body().Contains("origin")
- })
- ginkgo.It("disable plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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: false
-`, 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")
- })
- ginkgo.It("enable plugin and then delete it", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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/v2beta3
-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/suite-plugins/csrf.go b/test/e2e/suite-plugins/csrf.go
deleted file mode 100644
index 557e2fcd..00000000
--- a/test/e2e/suite-plugins/csrf.go
+++ /dev/null
@@ -1,141 +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"
- "net/http"
-
- ginkgo "github.com/onsi/ginkgo/v2"
- "github.com/stretchr/testify/assert"
-
- "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
-)
-
-var _ = ginkgo.Describe("suite-plugins: csrf plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("prevent csrf", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- plugins:
- - name: csrf
- enable: true
- config:
- key: "edd1c9f034335f136f87ad84b625c8f1"
-`, 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")
-
- msg401 := s.NewAPISIXClient().
- POST("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusUnauthorized).
- Body().
- Raw()
- assert.Contains(ginkgo.GinkgoT(), msg401, "no csrf token in headers")
-
- resp := s.NewAPISIXClient().
- GET("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
- resp.Header("Set-Cookie").NotEmpty()
-
- cookie := resp.Cookie("apisix-csrf-token")
- token := cookie.Value().Raw()
-
- _ = s.NewAPISIXClient().
- POST("/anything").
- WithHeader("Host", "httpbin.org").
- WithHeader("apisix-csrf-token", token).
- WithCookie("apisix-csrf-token", token).
- Expect().
- Status(http.StatusOK)
- })
-
- ginkgo.It("disable plugin", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-kind: ApisixRoute
-metadata:
- name: httpbin-route
-spec:
- http:
- - name: rule1
- match:
- hosts:
- - httpbin.org
- paths:
- - /anything
- backends:
- - serviceName: %s
- servicePort: %d
- plugins:
- - name: csrf
- enable: false
- config:
- key: "edd1c9f034335f136f87ad84b625c8f1"
-`, 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("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
-
- _ = s.NewAPISIXClient().
- POST("/anything").
- WithHeader("Host", "httpbin.org").
- Expect().
- Status(http.StatusOK)
- })
-})
diff --git a/test/e2e/suite-plugins/echo.go b/test/e2e/suite-plugins/echo.go
deleted file mode 100644
index ad273a93..00000000
--- a/test/e2e/suite-plugins/echo.go
+++ /dev/null
@@ -1,235 +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"
- "net/http"
- "time"
-
- ginkgo "github.com/onsi/ginkgo/v2"
- "github.com/stretchr/testify/assert"
-
- "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
-)
-
-var _ = ginkgo.Describe("suite-plugins: echo plugin", func() {
- opts := &scaffold.Options{
- Name: "default",
- Kubeconfig: scaffold.GetKubeconfig(),
- APISIXConfigPath: "testdata/apisix-gw-config.yaml",
- IngressAPISIXReplicas: 1,
- HTTPBinServicePort: 80,
- APISIXRouteVersion: "apisix.apache.org/v2beta3",
- }
- s := scaffold.NewScaffold(opts)
- ginkgo.It("insert preface and epilogue", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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:
- before_body: "This is the preface"
- after_body: "This is the epilogue"
- headers:
- X-Foo: v1
- X-Foo2: v2
-
-`, 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("X-Foo").Equal("v1")
- resp.Header("X-Foo2").Equal("v2")
- resp.Body().Contains("This is the preface")
- resp.Body().Contains("origin")
- resp.Body().Contains("This is the epilogue")
- })
-
- ginkgo.It("replace body", func() {
- backendSvc, backendPorts := s.DefaultHTTPBackend()
- ar := fmt.Sprintf(`
-apiVersion: apisix.apache.org/v2beta3
-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")
... 2556 lines suppressed ...