properly parse x-forwarded-host

This commit is contained in:
Elvin Efendi 2019-03-31 13:33:59 -04:00
parent 79431812b6
commit 87e962682f
2 changed files with 28 additions and 4 deletions

View file

@ -54,6 +54,7 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
return strings.Contains(server, "server_name forwarded-headers")
})
By("ensuring single values are parsed correctly")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
@ -70,6 +71,22 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=myproto")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=1234")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-for=1.2.3.4")))
By("ensuring that first entry in X-Forwarded-Host is used as the best host")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("X-Forwarded-Port", "1234").
Set("X-Forwarded-Proto", "myproto").
Set("X-Forwarded-For", "1.2.3.4").
Set("X-Forwarded-Host", "myhost.com, another.host,example.net").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=myhost.com")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-host=myhost.com")))
})
It("should not trust X-Forwarded headers when setting is false", func() {
host := "forwarded-headers"