From a398fe5dc345c3bf67e24e839fe7e1e5263ae539 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Thu, 12 Dec 2024 13:13:19 +0100 Subject: [PATCH] test(customheaders): add test for annotation added reproduces https://github.com/kubernetes/ingress-nginx/issues/11680 --- test/e2e/annotations/customheaders.go | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/e2e/annotations/customheaders.go b/test/e2e/annotations/customheaders.go index 274ce8278c..b0a1c30b84 100644 --- a/test/e2e/annotations/customheaders.go +++ b/test/e2e/annotations/customheaders.go @@ -107,4 +107,49 @@ var _ = framework.DescribeAnnotation("custom-headers-*", func() { Status(http.StatusOK). Header("My-Custom-Header-Dollar").Contains("$remote_addr") }) + + ginkgo.It(`should set "more_set_headers 'My-Custom-Header' '42';" when custom-headers annotation is added`, func() { + f.CreateConfigMap("custom-headers", map[string]string{ + "My-Custom-Header": "42", + "My-Custom-Header-Dollar": "$remote_addr", + }) + f.UpdateNginxConfigMapData("global-allowed-response-headers", "My-Custom-Header,My-Custom-Header-Dollar") + + annotations := map[string]string{} + ing := framework.NewSingleIngress(customHeaderHost, "/", customHeaderHost, f.Namespace, framework.EchoService, 80, annotations) + f.EnsureIngress(ing) + + f.WaitForNginxServer(customHeaderHost, + func(server string) bool { + return strings.Contains(server, `more_set_headers "My-Custom-Header: 42";`) + }) + + f.HTTPTestClient(). + GET("/"). + WithHeader("Host", customHeaderHost). + Expect(). + Status(http.StatusOK). + Header("My-Custom-Header").Equal("") + + annotations = map[string]string{ + "nginx.ingress.kubernetes.io/custom-headers": f.Namespace + "/custom-headers", + } + + ing.Annotations = annotations + + f.UpdateIngress(ing) + + f.HTTPTestClient(). + GET("/"). + WithHeader("Host", customHeaderHost). + Expect(). + Status(http.StatusOK). + Header("My-Custom-Header").Contains("42") + f.HTTPTestClient(). + GET("/"). + WithHeader("Host", customHeaderHost). + Expect(). + Status(http.StatusOK). + Header("My-Custom-Header-Dollar").Contains("$remote_addr") + }) })