Skip to content

Commit

Permalink
test(customheaders): add test for annotation added
Browse files Browse the repository at this point in the history
reproduces kubernetes#11680
  • Loading branch information
qvalentin committed Dec 12, 2024
1 parent c6a2d9a commit a398fe5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/e2e/annotations/customheaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})

0 comments on commit a398fe5

Please sign in to comment.