e2e: add test cases for url redirect annotations (#216)

This commit is contained in:
Lisheng Zheng
2023-02-24 11:03:32 +08:00
committed by GitHub
parent b41f4ce886
commit e839052a9e
9 changed files with 322 additions and 33 deletions

View File

@@ -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)
}
})
},
}

View File

@@ -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

View File

@@ -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)
}
})
},
}

View File

@@ -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

View File

@@ -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{

View File

@@ -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

View File

@@ -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)
}
})
},
}

View File

@@ -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

View File

@@ -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)