Integration tests for all new header manip features
This commit is contained in:
parent
1dd1683ed9
commit
bc1c86df96
|
@ -465,7 +465,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
retry_on_status_codes = [401, 209]
|
||||
request_headers {
|
||||
add {
|
||||
foo = "bar"
|
||||
x-foo = "bar"
|
||||
}
|
||||
set {
|
||||
bar = "baz"
|
||||
|
@ -474,7 +474,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
}
|
||||
response_headers {
|
||||
add {
|
||||
foo = "bar"
|
||||
x-foo = "bar"
|
||||
}
|
||||
set {
|
||||
bar = "baz"
|
||||
|
@ -566,7 +566,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
RetryOnStatusCodes = [401, 209]
|
||||
RequestHeaders {
|
||||
Add {
|
||||
foo = "bar"
|
||||
x-foo = "bar"
|
||||
}
|
||||
Set {
|
||||
bar = "baz"
|
||||
|
@ -575,7 +575,7 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
}
|
||||
ResponseHeaders {
|
||||
Add {
|
||||
foo = "bar"
|
||||
x-foo = "bar"
|
||||
}
|
||||
Set {
|
||||
bar = "baz"
|
||||
|
@ -666,12 +666,12 @@ func TestDecodeConfigEntry(t *testing.T) {
|
|||
RetryOnConnectFailure: true,
|
||||
RetryOnStatusCodes: []uint32{401, 209},
|
||||
RequestHeaders: &HTTPHeaderModifiers{
|
||||
Add: map[string]string{"foo": "bar"},
|
||||
Add: map[string]string{"x-foo": "bar"},
|
||||
Set: map[string]string{"bar": "baz"},
|
||||
Remove: []string{"qux"},
|
||||
},
|
||||
ResponseHeaders: &HTTPHeaderModifiers{
|
||||
Add: map[string]string{"foo": "bar"},
|
||||
Add: map[string]string{"x-foo": "bar"},
|
||||
Set: map[string]string{"bar": "baz"},
|
||||
Remove: []string{"qux"},
|
||||
},
|
||||
|
|
|
@ -291,6 +291,36 @@ config_entries {
|
|||
prefix_rewrite = "/debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
match { http {
|
||||
path_exact = "/header-manip/debug"
|
||||
} },
|
||||
destination {
|
||||
service_subset = "v2"
|
||||
prefix_rewrite = "/debug"
|
||||
request_headers {
|
||||
set {
|
||||
x-foo = "request-bar"
|
||||
}
|
||||
remove = ["x-bad-req"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
match { http {
|
||||
path_exact = "/header-manip/echo"
|
||||
} },
|
||||
destination {
|
||||
service_subset = "v2"
|
||||
prefix_rewrite = "/"
|
||||
response_headers {
|
||||
add {
|
||||
x-foo = "response-bar"
|
||||
}
|
||||
remove = ["x-bad-resp"]
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,3 +104,44 @@ load helpers
|
|||
@test "test method match" {
|
||||
assert_expected_fortio_name s2-v2 localhost 5000 /method-match
|
||||
}
|
||||
|
||||
@test "test request header manipulation" {
|
||||
run retry_default curl -s -f \
|
||||
-H "X-Bad-Req: true" \
|
||||
"localhost:5000/header-manip/debug?env=dump"
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Should have been routed to the right server
|
||||
echo "$output" | grep -E "^FORTIO_NAME=s2-v2"
|
||||
|
||||
# Route should have added the right request header
|
||||
echo "$output" | grep -E "^X-Foo: request-bar"
|
||||
|
||||
# Route should have removed the bad request header
|
||||
if echo "$output" | grep -E "^X-Bad-Req: true"; then
|
||||
echo "X-Bad-Req request header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "test response header manipulation" {
|
||||
# Add a response header that should be stripped by the route.
|
||||
run retry_default curl -v -f -X PUT \
|
||||
"localhost:5000/header-manip/echo?header=x-bad-resp:true"
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Route should have added the right response header (this is output by curl -v)
|
||||
echo "$output" | grep -E "^< x-foo: response-bar"
|
||||
|
||||
# Route should have removed the bad response header
|
||||
if echo "$output" | grep -E "^< x-bad-resp: true"; then
|
||||
echo "X-Bad-Resp response header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -31,10 +31,34 @@ config_entries {
|
|||
{
|
||||
weight = 50,
|
||||
service_subset = "v2"
|
||||
request_headers {
|
||||
set {
|
||||
x-split-leg = "v2"
|
||||
}
|
||||
remove = ["x-bad-req"]
|
||||
}
|
||||
response_headers {
|
||||
add {
|
||||
x-svc-version = "v2"
|
||||
}
|
||||
remove = ["x-bad-resp"]
|
||||
}
|
||||
},
|
||||
{
|
||||
weight = 50,
|
||||
service_subset = "v1"
|
||||
request_headers {
|
||||
set {
|
||||
x-split-leg = "v1"
|
||||
}
|
||||
remove = ["x-bad-req"]
|
||||
}
|
||||
response_headers {
|
||||
add {
|
||||
x-svc-version = "v1"
|
||||
}
|
||||
remove = ["x-bad-resp"]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
|
@ -50,3 +50,48 @@ load helpers
|
|||
@test "s1 upstream should be able to connect to s2-v1 or s2-v2 via upstream s2" {
|
||||
assert_expected_fortio_name_pattern ^FORTIO_NAME=s2-v[12]$
|
||||
}
|
||||
|
||||
@test "test request header manipulation" {
|
||||
run retry_default curl -s -f \
|
||||
-H "X-Bad-Req: true" \
|
||||
"localhost:5000/debug?env=dump"
|
||||
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Figure out which version we hit. This will fail the test if the grep can't
|
||||
# find a match while capturing the v1 or v2 from the server name in VERSION
|
||||
VERSION=$(echo "$output" | grep -o -E "^FORTIO_NAME=s2-v[12]" | grep -o 'v[12]$')
|
||||
|
||||
# Route should have added the right request header
|
||||
GOT_HEADER=$(echo "$output" | grep -E "^X-Split-Leg: v[12]" | grep -o 'v[12]$')
|
||||
|
||||
[ "$GOT_HEADER" == "$VERSION" ]
|
||||
|
||||
# Route should have removed the bad request header
|
||||
if echo "$output" | grep -E "^X-Bad-Req: true"; then
|
||||
echo "X-Bad-Req request header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "test response header manipulation" {
|
||||
# Add a response header that should be stripped by the route.
|
||||
run retry_default curl -v -f -X PUT \
|
||||
"localhost:5000/header-manip/echo?header=x-bad-resp:true"
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Splitter should have added the right response header (this is output by curl -v)
|
||||
echo "$output" | grep -E "^< x-svc-version: v[12]"
|
||||
|
||||
# Splitter should have removed the bad response header
|
||||
if echo "$output" | grep -E "^< x-bad-resp: true"; then
|
||||
echo "X-Bad-Resp response header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -18,6 +18,26 @@ config_entries {
|
|||
services = [
|
||||
{
|
||||
name = "router"
|
||||
request_headers {
|
||||
add {
|
||||
x-foo = "bar-req"
|
||||
x-existing-1 = "appended-req"
|
||||
}
|
||||
set {
|
||||
x-existing-2 = "replaced-req"
|
||||
}
|
||||
remove = ["x-bad-req"]
|
||||
}
|
||||
response_headers {
|
||||
add {
|
||||
x-foo = "bar-resp"
|
||||
x-existing-1 = "appended-resp"
|
||||
}
|
||||
set {
|
||||
x-existing-2 = "replaced-resp"
|
||||
}
|
||||
remove = ["x-bad-resp"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -38,3 +38,66 @@ load helpers
|
|||
assert_expected_fortio_name s2 router.ingress.consul 9999 /s2
|
||||
}
|
||||
|
||||
@test "test request header manipulation" {
|
||||
run retry_default curl -s -f \
|
||||
-H "Host: router.ingress.consul" \
|
||||
-H "X-Existing-1: original" \
|
||||
-H "X-Existing-2: original" \
|
||||
-H "X-Bad-Req: true" \
|
||||
"localhost:9999/s2/debug?env=dump"
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Should have been routed to the right server
|
||||
echo "$output" | grep -E "^FORTIO_NAME=s2"
|
||||
|
||||
# Ingress should have added the new request header
|
||||
echo "$output" | grep -E "^X-Foo: bar-req"
|
||||
|
||||
# Ingress should have appended the first existing header - both should be
|
||||
# present
|
||||
echo "$output" | grep -E "^X-Existing-1: original,appended-req"
|
||||
|
||||
# Ingress should have replaced the second existing header
|
||||
echo "$output" | grep -E "^X-Existing-2: replaced-req"
|
||||
|
||||
# Ingress should have removed the bad request header
|
||||
if echo "$output" | grep -E "^X-Bad-Req: true"; then
|
||||
echo "X-Bad-Req request header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "test response header manipulation" {
|
||||
# Add a response header that should be stripped by the route.
|
||||
run retry_default curl -v -s -f -X PUT \
|
||||
-H "Host: router.ingress.consul" \
|
||||
"localhost:9999/s2/echo?header=x-bad-resp:true&header=x-existing-1:original&header=x-existing-2:original"
|
||||
|
||||
echo "GOT: $output"
|
||||
|
||||
[ "$status" == "0" ]
|
||||
|
||||
# Ingress should have added the new response header
|
||||
echo "$output" | grep -E "^< x-foo: bar-resp"
|
||||
|
||||
# Ingress should have appended the first existing header - both should be
|
||||
# present
|
||||
echo "$output" | grep -E "^< x-existing-1: original"
|
||||
echo "$output" | grep -E "^< x-existing-1: appended-resp"
|
||||
|
||||
# Ingress should have replaced the second existing header
|
||||
echo "$output" | grep -E "^< x-existing-2: replaced-resp"
|
||||
if echo "$output" | grep -E "^< x-existing-2: original"; then
|
||||
echo "x-existing-2 response header should have been overridden, original still present"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ingress should have removed the bad response header
|
||||
if echo "$output" | grep -E "^< x-bad-resp: true"; then
|
||||
echo "X-Bad-Resp response header should have been stripped but was still present"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue