Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 7c163e5

Browse files
committed
Update proxy_test for golang 1.20.6
Starting in golang 1.20.6, the creation of requests with invalid host headers returns an error prior to sending the request on the wire to a server. To compensate, we now test with a raw TCP connection instead of our HTTP request/response helpers.
1 parent 05f2266 commit 7c163e5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

proxy/proxy_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,14 +1598,19 @@ var _ = Describe("Proxy", func() {
15981598
})
15991599

16001600
It("responds to host with malicious script with 400", func() {
1601-
conn := dialProxy(proxyServer)
1601+
conn, err := net.Dial("tcp", proxyServer.Addr().String())
1602+
defer conn.Close()
1603+
Expect(err).NotTo(HaveOccurred())
16021604

1603-
req := test_util.NewRequest("GET", "<html><header><script>alert(document.cookie);</script></header><body/></html>", "/", nil)
1604-
conn.WriteRequest(req)
1605+
rawReq := "GET / HTTP/1.1\nHost: <html><header><script>alert(document.cookie);</script></header><body/></html>\n\n\n"
16051606

1606-
resp, body := conn.ReadResponse()
1607-
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
1608-
Expect(body).To(ContainSubstring("malformed Host header"))
1607+
conn.Write([]byte(rawReq))
1608+
1609+
resp, err := ioutil.ReadAll(conn)
1610+
Expect(err).ToNot(HaveOccurred())
1611+
1612+
Expect(string(resp)).To(ContainSubstring("HTTP/1.1 400 Bad Request")) // status header
1613+
Expect(string(resp)).To(ContainSubstring("400 Bad Request: malformed Host header")) // body
16091614
})
16101615

16111616
It("responds with 404 for a not found host name with only valid characters", func() {

0 commit comments

Comments
 (0)