summaryrefslogtreecommitdiff
path: root/service/http/handler_test.go
diff options
context:
space:
mode:
authorAnton Titov <[email protected]>2019-09-06 12:49:45 +0300
committerGitHub <[email protected]>2019-09-06 12:49:45 +0300
commit832295948b275898ec398341bba76ed96cbde5d9 (patch)
tree62f809be5c4fba1f3b5511832ec17d8de54937a8 /service/http/handler_test.go
parent756a5a21cb4324c51ef44bd668c1c2f222aaa9b5 (diff)
parentdef26e1c757815bee024c1181ea1bb66c399156b (diff)
Merge pull request #184 from spudro228/bug-fix/183-wrong-proxy-resolving
Bug fix/183 wrong proxy resolving
Diffstat (limited to 'service/http/handler_test.go')
-rw-r--r--service/http/handler_test.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 95077da6..e29b76ac 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -1345,7 +1345,58 @@ func TestHandler_XForwardedFor(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 200, r.StatusCode)
- assert.Equal(t, "200.0.0.1", body)
+ assert.Equal(t, "101.0.0.1", body)
+
+ body, r, err = getHeader("http://127.0.0.1:8177/", map[string]string{
+ "X-Forwarded-For": "100.0.0.1, 200.0.0.1, 101.0.0.1, invalid",
+ })
+
+ assert.NoError(t, err)
+ assert.Equal(t, 200, r.StatusCode)
+ assert.Equal(t, "101.0.0.1", body)
+}
+
+func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
+ h := &Handler{
+ cfg: &Config{
+ MaxRequestSize: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{},
+ },
+ TrustedSubnets: []string{
+ "10.0.0.0/8",
+ },
+ },
+ rr: roadrunner.NewServer(&roadrunner.ServerConfig{
+ Command: "php ../../tests/http/client.php ip pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ h.cfg.parseCIDRs()
+
+ assert.NoError(t, h.rr.Start())
+ defer h.rr.Stop()
+
+ hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
+ defer hs.Shutdown(context.Background())
+
+ go func() { hs.ListenAndServe() }()
+ time.Sleep(time.Millisecond * 10)
+
+ body, r, err := getHeader("http://127.0.0.1:8177/", map[string]string{
+ "X-Forwarded-For": "100.0.0.1, 200.0.0.1, invalid, 101.0.0.1",
+ })
+
+ assert.NoError(t, err)
+ assert.Equal(t, 200, r.StatusCode)
+ assert.Equal(t, "127.0.0.1", body)
}
func BenchmarkHandler_Listen_Echo(b *testing.B) {