diff --git a/test/ingress/conformance/tests/httproute-app-root.go b/test/ingress/conformance/tests/httproute-app-root.go new file mode 100644 index 000000000..84b6a0a52 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-app-root.go @@ -0,0 +1,65 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed 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 tests + +import ( + "testing" + + "github.com/alibaba/higress/test/ingress/conformance/utils/http" + "github.com/alibaba/higress/test/ingress/conformance/utils/roundtripper" + "github.com/alibaba/higress/test/ingress/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, HTTPRouteAppRoot) +} + +var HTTPRouteAppRoot = suite.ConformanceTest{ + ShortName: "HTTPRouteAppRoot", + Description: "The Ingress in the higress-conformance-infra namespace uses the app root.", + Manifests: []string{"tests/httproute-app-root.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/", + UnfollowRedirect: true, + }, + RedirectRequest: &roundtripper.RedirectRequest{ + Scheme: "http", + Host: "foo.com", + Path: "/foo", + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 302, + }, + }, + }, + } + t.Run("HTTPRoute app root", func(t *testing.T) { + for _, testcase := range testcases { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase) + } + }) + }, +} diff --git a/test/ingress/conformance/tests/httproute-app-root.yaml b/test/ingress/conformance/tests/httproute-app-root.yaml new file mode 100644 index 000000000..cdf650b94 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-app-root.yaml @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed 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. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/app-root: "/foo" + name: httproute-app-root + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: "foo.com" + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 diff --git a/test/ingress/conformance/tests/httproute-permanent-redirect-code.go b/test/ingress/conformance/tests/httproute-permanent-redirect-code.go new file mode 100644 index 000000000..42cf6da3b --- /dev/null +++ b/test/ingress/conformance/tests/httproute-permanent-redirect-code.go @@ -0,0 +1,65 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed 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 tests + +import ( + "testing" + + "github.com/alibaba/higress/test/ingress/conformance/utils/http" + "github.com/alibaba/higress/test/ingress/conformance/utils/roundtripper" + "github.com/alibaba/higress/test/ingress/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, HTTPRoutePermanentRedirectCode) +} + +var HTTPRoutePermanentRedirectCode = suite.ConformanceTest{ + ShortName: "HTTPRoutePermanentRedirectCode", + Description: "The Ingress in the higress-conformance-infra namespace uses the permanent redirect code header.", + Manifests: []string{"tests/httproute-permanent-redirect-code.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/foo", + UnfollowRedirect: true, + }, + RedirectRequest: &roundtripper.RedirectRequest{ + Scheme: "http", + Host: "bar.com", + Path: "/foo", + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 308, + }, + }, + }, + } + t.Run("HTTPRoute permanent redirect code", func(t *testing.T) { + for _, testcase := range testcases { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase) + } + }) + }, +} diff --git a/test/ingress/conformance/tests/httproute-permanent-redirect-code.yaml b/test/ingress/conformance/tests/httproute-permanent-redirect-code.yaml new file mode 100644 index 000000000..a351f5664 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-permanent-redirect-code.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed 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. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/permanent-redirect: "http://bar.com" + nginx.ingress.kubernetes.io/permanent-redirect-code: "308" + name: httproute-permanent-redirect-code + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: "foo.com" + http: + paths: + - pathType: Prefix + path: "/foo" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 diff --git a/test/ingress/conformance/tests/httproute-permanent-redirect.go b/test/ingress/conformance/tests/httproute-permanent-redirect.go index 1bb094ce5..a170156b8 100644 --- a/test/ingress/conformance/tests/httproute-permanent-redirect.go +++ b/test/ingress/conformance/tests/httproute-permanent-redirect.go @@ -18,30 +18,35 @@ import ( "testing" "github.com/alibaba/higress/test/ingress/conformance/utils/http" + "github.com/alibaba/higress/test/ingress/conformance/utils/roundtripper" "github.com/alibaba/higress/test/ingress/conformance/utils/suite" ) -var HTTPRoutePermanentDirect = suite.ConformanceTest{ - ShortName: "HTTPRoutePermanentDirect", - Description: "The Ingress in the higress-conformance-infra namespace uses the permanent direct header.", - Manifests: []string{"tests/httproute-permanent-direct.yaml"}, +func init() { + HigressConformanceTests = append(HigressConformanceTests, HTTPRoutePermanentRedirect) +} + +var HTTPRoutePermanentRedirect = suite.ConformanceTest{ + ShortName: "HTTPRoutePermanentRedirect", + Description: "The Ingress in the higress-conformance-infra namespace uses the permanent redirect header.", + Manifests: []string{"tests/httproute-permanent-redirect.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { testcases := []http.Assertion{ { Meta: http.AssertionMeta{ - TargetBackend: "infra-backend-v2", + TargetBackend: "infra-backend-v1", TargetNamespace: "higress-conformance-infra", }, Request: http.AssertionRequest{ ActualRequest: http.Request{ - Host: "foo.com", - Path: "/foo", + Host: "foo.com", + Path: "/foo", + UnfollowRedirect: true, }, - ExpectedRequest: &http.ExpectedRequest{ - Request: http.Request{ - Host: "bar.com", - Path: "/foo", - }, + RedirectRequest: &roundtripper.RedirectRequest{ + Scheme: "http", + Host: "bar.com", + Path: "/foo", }, }, Response: http.AssertionResponse{ diff --git a/test/ingress/conformance/tests/httproute-permanent-redirect.yaml b/test/ingress/conformance/tests/httproute-permanent-redirect.yaml index b438f006c..30ae82fad 100644 --- a/test/ingress/conformance/tests/httproute-permanent-redirect.yaml +++ b/test/ingress/conformance/tests/httproute-permanent-redirect.yaml @@ -16,8 +16,8 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: - nginx.ingress.kubernetes.io/permanent-redirect: "bar.com" - name: httproute-permanent-direct + nginx.ingress.kubernetes.io/permanent-redirect: "http://bar.com" + name: httproute-permanent-redirect namespace: higress-conformance-infra spec: ingressClassName: higress @@ -32,22 +32,3 @@ spec: name: infra-backend-v1 port: number: 8080 ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: httproute-permanent-direct-bar - namespace: higress-conformance-infra -spec: - ingressClassName: higress - rules: - - host: "bar.com" - http: - paths: - - pathType: Prefix - path: "/foo" - backend: - service: - name: infra-backend-v2 - port: - number: 8080 diff --git a/test/ingress/conformance/tests/httproute-temporal-redirect.go b/test/ingress/conformance/tests/httproute-temporal-redirect.go new file mode 100644 index 000000000..f06428ac2 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-temporal-redirect.go @@ -0,0 +1,65 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed 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 tests + +import ( + "testing" + + "github.com/alibaba/higress/test/ingress/conformance/utils/http" + "github.com/alibaba/higress/test/ingress/conformance/utils/roundtripper" + "github.com/alibaba/higress/test/ingress/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, HTTPRouteTemporalRedirect) +} + +var HTTPRouteTemporalRedirect = suite.ConformanceTest{ + ShortName: "HTTPRouteTemporalRedirect", + Description: "The Ingress in the higress-conformance-infra namespace uses the temporal redirect header.", + Manifests: []string{"tests/httproute-temporal-redirect.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/foo", + UnfollowRedirect: true, + }, + RedirectRequest: &roundtripper.RedirectRequest{ + Scheme: "http", + Host: "bar.com", + Path: "/foo", + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 302, + }, + }, + }, + } + t.Run("HTTPRoute temporal redirect", func(t *testing.T) { + for _, testcase := range testcases { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase) + } + }) + }, +} diff --git a/test/ingress/conformance/tests/httproute-temporal-redirect.yaml b/test/ingress/conformance/tests/httproute-temporal-redirect.yaml new file mode 100644 index 000000000..9adcfccb6 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-temporal-redirect.yaml @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed 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. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/temporal-redirect: "http://bar.com" + name: httproute-temporal-redirect + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: "foo.com" + http: + paths: + - pathType: Prefix + path: "/foo" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 diff --git a/test/ingress/e2e_test.go b/test/ingress/e2e_test.go index 0157dcd2b..3c61b03e3 100644 --- a/test/ingress/e2e_test.go +++ b/test/ingress/e2e_test.go @@ -49,6 +49,7 @@ func TestHigressConformanceTests(t *testing.T) { }) cSuite.Setup(t) + higressTests := []suite.ConformanceTest{ tests.HTTPRouteSimpleSameNamespace, tests.HTTPRouteHostNameSameNamespace, @@ -60,6 +61,10 @@ func TestHigressConformanceTests(t *testing.T) { tests.HTTPRouteMatchMethods, tests.HTTPRouteMatchQueryParams, tests.HTTPRouteMatchHeaders, + tests.HTTPRouteAppRoot, + tests.HTTPRoutePermanentRedirect, + tests.HTTPRoutePermanentRedirectCode, + tests.HTTPRouteTemporalRedirect, } cSuite.Run(t, higressTests)