Switch forwarded-headers e2e to use gorequest.

This commit is contained in:
Dario Nieuwenhuis 2018-06-13 21:10:33 +02:00
parent 94266ff167
commit 04d24e1ff7

View file

@ -18,12 +18,12 @@ package settings
import ( import (
"fmt" "fmt"
"io/ioutil" "net/http"
"net"
"strings" "strings"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"k8s.io/ingress-nginx/test/e2e/framework" "k8s.io/ingress-nginx/test/e2e/framework"
) )
@ -60,20 +60,17 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
ip, err := f.GetNginxIP() resp, body, errs := gorequest.New().
Expect(err).NotTo(HaveOccurred()) Get(f.IngressController.HTTPURL).
port, err := f.GetNginxPort("http") Set("Host", host).
Expect(err).NotTo(HaveOccurred()) Set("X-Forwarded-Port", "1234").
Set("X-Forwarded-Proto", "myproto").
Set("X-Forwarded-For", "1.2.3.4").
Set("X-Forwarded-Host", "myhost").
End()
conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", ip, port)) Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode).Should(Equal(http.StatusOK))
defer conn.Close()
conn.Write([]byte("GET / HTTP/1.1\r\nHost: forwarded-headers\r\nX-Forwarded-Port: 1234\r\nX-Forwarded-Proto: myproto\r\nX-Forwarded-For: 1.2.3.4\r\nX-Forwarded-Host: myhost\r\n\r\n"))
data, err := ioutil.ReadAll(conn)
Expect(err).NotTo(HaveOccurred())
body := string(data)
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=myhost"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("host=myhost")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-host=myhost"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-host=myhost")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=myproto"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=myproto")))
@ -96,20 +93,17 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
ip, err := f.GetNginxIP() resp, body, errs := gorequest.New().
Expect(err).NotTo(HaveOccurred()) Get(f.IngressController.HTTPURL).
port, err := f.GetNginxPort("http") Set("Host", host).
Expect(err).NotTo(HaveOccurred()) Set("X-Forwarded-Port", "1234").
Set("X-Forwarded-Proto", "myproto").
Set("X-Forwarded-For", "1.2.3.4").
Set("X-Forwarded-Host", "myhost").
End()
conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", ip, port)) Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode).Should(Equal(http.StatusOK))
defer conn.Close()
conn.Write([]byte("GET / HTTP/1.1\r\nHost: forwarded-headers\r\nX-Forwarded-Port: 1234\r\nX-Forwarded-Proto: myproto\r\nX-Forwarded-For: 1.2.3.4\r\nX-Forwarded-Host: myhost\r\n\r\n"))
data, err := ioutil.ReadAll(conn)
Expect(err).NotTo(HaveOccurred())
body := string(data)
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=forwarded-headers"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("host=forwarded-headers")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=80"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=80")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=http"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=http")))