@@ -168,4 +168,92 @@ spec:
168168 Expect (upstreams [0 ].Timeout .Connect ).To (Equal (4 ), "checking Upstream connect timeout" )
169169 })
170170 })
171+
172+ Context ("Plugins" , func () {
173+ var (
174+ tohttps = `
175+ apiVersion: networking.k8s.io/v1
176+ kind: Ingress
177+ metadata:
178+ name: tohttps
179+ annotations:
180+ k8s.apisix.apache.org/http-to-https: "true"
181+ spec:
182+ ingressClassName: %s
183+ rules:
184+ - host: httpbin.example
185+ http:
186+ paths:
187+ - path: /get
188+ pathType: Exact
189+ backend:
190+ service:
191+ name: httpbin-service-e2e-test
192+ port:
193+ number: 80
194+ `
195+ redirect = `
196+ apiVersion: networking.k8s.io/v1
197+ kind: Ingress
198+ metadata:
199+ name: redirect
200+ annotations:
201+ k8s.apisix.apache.org/http-redirect: "/anything$uri"
202+ k8s.apisix.apache.org/http-redirect-code: "308"
203+ spec:
204+ ingressClassName: %s
205+ rules:
206+ - host: httpbin.example
207+ http:
208+ paths:
209+ - path: /ip
210+ pathType: Exact
211+ backend:
212+ service:
213+ name: httpbin-service-e2e-test
214+ port:
215+ number: 80
216+ `
217+ )
218+ BeforeEach (func () {
219+ By ("create GatewayProxy" )
220+ Expect (s .CreateResourceFromString (s .GetGatewayProxySpec ())).NotTo (HaveOccurred (), "creating GatewayProxy" )
221+
222+ By ("create IngressClass" )
223+ err := s .CreateResourceFromStringWithNamespace (s .GetIngressClassYaml (), "" )
224+ Expect (err ).NotTo (HaveOccurred (), "creating IngressClass" )
225+ time .Sleep (5 * time .Second )
226+ })
227+ It ("redirect" , func () {
228+ Expect (s .CreateResourceFromString (fmt .Sprintf (tohttps , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
229+ Expect (s .CreateResourceFromString (fmt .Sprintf (redirect , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
230+
231+ s .RequestAssert (& scaffold.RequestAssert {
232+ Method : "GET" ,
233+ Path : "/get" ,
234+ Host : "httpbin.example" ,
235+ Check : scaffold .WithExpectedStatus (http .StatusMovedPermanently ),
236+ })
237+ s .RequestAssert (& scaffold.RequestAssert {
238+ Method : "GET" ,
239+ Path : "/ip" ,
240+ Host : "httpbin.example" ,
241+ Check : scaffold .WithExpectedStatus (http .StatusPermanentRedirect ),
242+ })
243+
244+ _ = s .NewAPISIXClient ().
245+ GET ("/get" ).
246+ WithHost ("httpbin.example" ).
247+ Expect ().
248+ Status (http .StatusMovedPermanently ).
249+ Header ("Location" ).IsEqual ("https://httpbin.example:9443/get" )
250+
251+ _ = s .NewAPISIXClient ().
252+ GET ("/ip" ).
253+ WithHost ("httpbin.example" ).
254+ Expect ().
255+ Status (http .StatusPermanentRedirect ).
256+ Header ("Location" ).IsEqual ("/anything/ip" )
257+ })
258+ })
171259})
0 commit comments