Skip to content

Commit

Permalink
test: add integration test for XFF parsing (#3623)
Browse files Browse the repository at this point in the history
This should catch some regressions related to XFF parsing, like what's
described in #3607.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
  • Loading branch information
rgs1 authored and alyssawilk committed Jun 13, 2018
1 parent 1e33007 commit 29db40c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/integration/header_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const std::string http_connection_mgr_config = R"EOF(
http_filters:
- name: envoy.router
codec_type: HTTP1
use_remote_address: false
xff_num_trusted_hops: 1
stat_prefix: header_test
route_config:
virtual_hosts:
Expand Down Expand Up @@ -108,6 +110,16 @@ stat_prefix: header_test
key: "x-route-response"
value: "route"
response_headers_to_remove: ["x-route-response-remove"]
- name: xff-headers
domains: ["xff-headers.com"]
routes:
- match: { prefix: "/test" }
route:
cluster: cluster_0
request_headers_to_add:
- header:
key: "x-real-ip"
value: "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
)EOF";

} // namespace
Expand Down Expand Up @@ -861,4 +873,35 @@ TEST_P(HeaderIntegrationTest, TestDynamicHeaders) {
});
}

// Validates that XFF gets properly parsed.
TEST_P(HeaderIntegrationTest, TestXFFParsing) {
initializeFilter(HeaderMode::Replace, false);
performRequest(
Http::TestHeaderMapImpl{
{":method", "GET"},
{":path", "/test"},
{":scheme", "http"},
{":authority", "xff-headers.com"},
{"x-forwarded-for", "1.2.3.4, 5.6.7.8 ,9.10.11.12"},
},
Http::TestHeaderMapImpl{
{":authority", "xff-headers.com"},
{"x-forwarded-for", "1.2.3.4, 5.6.7.8 ,9.10.11.12"},
{"x-real-ip", "5.6.7.8"},
{":path", "/test"},
{":method", "GET"},
},
Http::TestHeaderMapImpl{
{"server", "envoy"},
{"content-length", "0"},
{":status", "200"},
{"x-unmodified", "response"},
},
Http::TestHeaderMapImpl{
{"server", "envoy"},
{"x-unmodified", "response"},
{":status", "200"},
});
}

} // namespace Envoy

0 comments on commit 29db40c

Please sign in to comment.