...

Source file src/sigs.k8s.io/gateway-api/conformance/tests/httproute-redirect-scheme.go

Documentation: sigs.k8s.io/gateway-api/conformance/tests

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package tests
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/apimachinery/pkg/types"
    23  
    24  	"sigs.k8s.io/gateway-api/conformance/utils/http"
    25  	"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
    26  	"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
    27  	"sigs.k8s.io/gateway-api/conformance/utils/suite"
    28  )
    29  
    30  func init() {
    31  	ConformanceTests = append(ConformanceTests, HTTPRouteRedirectScheme)
    32  }
    33  
    34  var HTTPRouteRedirectScheme = suite.ConformanceTest{
    35  	ShortName:   "HTTPRouteRedirectScheme",
    36  	Description: "An HTTPRoute with a scheme redirect filter",
    37  	Manifests:   []string{"tests/httproute-redirect-scheme.yaml"},
    38  	Features: []suite.SupportedFeature{
    39  		suite.SupportGateway,
    40  		suite.SupportHTTPRoute,
    41  		suite.SupportHTTPRouteSchemeRedirect,
    42  	},
    43  	Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
    44  		ns := "gateway-conformance-infra"
    45  		routeNN := types.NamespacedName{Name: "redirect-scheme", Namespace: ns}
    46  		gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
    47  		gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
    48  		kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
    49  
    50  		testCases := []http.ExpectedResponse{
    51  			{
    52  				Request: http.Request{
    53  					Path:             "/scheme",
    54  					UnfollowRedirect: true,
    55  				},
    56  				Response: http.Response{
    57  					StatusCode: 302,
    58  				},
    59  				RedirectRequest: &roundtripper.RedirectRequest{
    60  					Scheme: "https",
    61  				},
    62  				Namespace: ns,
    63  			}, {
    64  				Request: http.Request{
    65  					Path:             "/scheme-and-host",
    66  					UnfollowRedirect: true,
    67  				},
    68  				Response: http.Response{
    69  					StatusCode: 302,
    70  				},
    71  				RedirectRequest: &roundtripper.RedirectRequest{
    72  					Host:   "example.org",
    73  					Scheme: "https",
    74  				},
    75  				Namespace: ns,
    76  			}, {
    77  				Request: http.Request{
    78  					Path:             "/scheme-and-status",
    79  					UnfollowRedirect: true,
    80  				},
    81  				Response: http.Response{
    82  					StatusCode: 301,
    83  				},
    84  				RedirectRequest: &roundtripper.RedirectRequest{
    85  					Scheme: "https",
    86  				},
    87  				Namespace: ns,
    88  			}, {
    89  				Request: http.Request{
    90  					Path:             "/scheme-and-host-and-status",
    91  					UnfollowRedirect: true,
    92  				},
    93  				Response: http.Response{
    94  					StatusCode: 302,
    95  				},
    96  				RedirectRequest: &roundtripper.RedirectRequest{
    97  					Scheme: "https",
    98  					Host:   "example.org",
    99  				},
   100  				Namespace: ns,
   101  			},
   102  		}
   103  		for i := range testCases {
   104  			// Declare tc here to avoid loop variable
   105  			// reuse issues across parallel tests.
   106  			tc := testCases[i]
   107  			t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
   108  				t.Parallel()
   109  				http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
   110  			})
   111  		}
   112  	},
   113  }
   114  

View as plain text