Skip to content

Commit

Permalink
fix: Finish proxy_protocol acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
a18e committed May 3, 2024
1 parent 769f78e commit 519e378
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions acceptance-tests/acceptance_tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func expectConnectionRefusedErr(err error) {
checkNetOpErr(err, "connect: connection refused")
}

func expectConnectionResetErr(err error) {
checkNetOpErr(err, "read: connection reset by peer")
}

func checkNetOpErr(err error, expectString string) {
Expect(err).To(HaveOccurred())
urlErr, ok := err.(*url.Error)
Expand Down
21 changes: 16 additions & 5 deletions acceptance-tests/proxy_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
proxyproto "github.com/pires/go-proxyproto"
"net"
"net/http"
"time"
)

var _ = Describe("Proxy Protocol", func() {
Expand All @@ -29,27 +30,37 @@ var _ = Describe("Proxy Protocol", func() {
haproxyBackendPort: haproxyBackendPort,
haproxyBackendServers: []string{"127.0.0.1"},
deploymentName: deploymentNameForTestNode(),
}, []string{opsfileProxyProtocol}, map[string]interface{}{}, true)
}, []string{opsfileProxyProtocol}, map[string]interface{}{}, false)

closeLocalServer, localPort := startDefaultTestServer()
defer closeLocalServer()

closeTunnel := setupTunnelFromHaproxyToTestServer(haproxyInfo, haproxyBackendPort, localPort)
defer closeTunnel()

By("Waiting for monit to report that HAProxy is healthy")
// Since the backend is now listening, HAProxy healthcheck should start returning healthy
// and monit should in turn start reporting a healthy process
// We will up to wait one minute for the status to stabilise
Eventually(func() string {
return boshInstances(deploymentNameForTestNode())[0].ProcessState
}, time.Minute, time.Second).Should(Equal("running"))

By("Sending a request with Proxy Protocol Header to HAProxy traffic port")
err := performProxyProtocolRequest(haproxyInfo.PublicIP, 80, "/")
Expect(err).NotTo(HaveOccurred())

By("Sending a request without Proxy Protocol Header to HAProxy")
expect400(http.Get(fmt.Sprintf("http://%s", haproxyInfo.PublicIP)))
_, err = http.Get(fmt.Sprintf("http://%s", haproxyInfo.PublicIP))
expectConnectionResetErr(err)

By("Sending a request with Proxy Protocol Header to HAProxy healthcheck port")
By("Sending a request with Proxy Protocol Header to HAProxy health check port")
err = performProxyProtocolRequest(haproxyInfo.PublicIP, 8080, "/health")
Expect(err).NotTo(HaveOccurred())

By("Sending a request without Proxy Protocol Header to HAProxy healthcheck port")
expect400(http.Get(fmt.Sprintf("http://%s:8080/health", haproxyInfo.PublicIP)))
By("Sending a request without Proxy Protocol Header to HAProxy health check port")
_, err = http.Get(fmt.Sprintf("http://%s:8080/health", haproxyInfo.PublicIP))
expectConnectionResetErr(err)
})
})

Expand Down

0 comments on commit 519e378

Please sign in to comment.