Skip to content

Commit b71f406

Browse files
committed
TEST/MINOR: testing http-after-response keyword
1 parent 87586b4 commit b71f406

10 files changed

Lines changed: 408 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "http_after_response_rules: Add a new HTTP After Response Rule to frontend" {
27+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
28+
skip "http-after-response is not supported in HAProxy 2.1"
29+
fi
30+
31+
resource_post "$_RES_RULES_BASE_PATH" "data/post.json" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
32+
assert_equal "$SC" 201
33+
}
34+
35+
@test "http_after_response_rules: Add a new HTTP After Response Rule to backend" {
36+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
37+
skip "http-after-response is not supported in HAProxy 2.1"
38+
fi
39+
40+
resource_post "$_RES_RULES_BASE_PATH" "data/post.json" "parent_type=backend&parent_name=test_backend&force_reload=true"
41+
assert_equal "$SC" 201
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
defaults
11+
mode http
12+
maxconn 3000
13+
log global
14+
option httplog
15+
option redispatch
16+
option dontlognull
17+
option http-server-close
18+
option forwardfor except 127.0.0.0/8
19+
timeout http-request 10s
20+
timeout check 10s
21+
timeout connect 10s
22+
timeout client 1m
23+
timeout queue 1m
24+
timeout server 1m
25+
timeout http-keep-alive 10s
26+
retries 3
27+
28+
frontend test_frontend
29+
mode http
30+
bind :80
31+
maxconn 1000
32+
option httpclose
33+
http-after-response add-header X-Add-Frontend CustomValue unless { src 192.168.0.0/16 }
34+
http-after-response del-header X-Del-Frontend if { src 10.1.0.0/16 }
35+
36+
backend test_backend
37+
mode http
38+
balance roundrobin
39+
option forwardfor
40+
http-after-response add-header X-Add-Backend CustomValue unless { src 192.168.0.0/16 }
41+
http-after-response del-header X-Del-Backend if { src 10.1.0.0/16 }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "unless",
3+
"cond_test": "{ src 192.168.0.0/16 }",
4+
"hdr_format": "%T",
5+
"hdr_name": "X-Haproxy-Current-Date",
6+
"index": 0,
7+
"type": "add-header"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cond": "if",
3+
"cond_test": "{ src 192.168.0.0/16 }",
4+
"hdr_format": "%T",
5+
"hdr_name": "X-Haproxy-Current-Date",
6+
"index": 0,
7+
"type": "add-header"
8+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "http_after_response_rules: Delete a HTTP After Response Rule from frontend" {
27+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
28+
skip "http-after-response is not supported in HAProxy 2.1"
29+
fi
30+
31+
#
32+
# Deleting the first one
33+
#
34+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
35+
assert_equal "$SC" 204
36+
#
37+
# Deleting the second one
38+
#
39+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
40+
assert_equal "$SC" 204
41+
#
42+
# No more HTTP after response rules, not found!
43+
#
44+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
45+
assert_equal "$SC" 404
46+
}
47+
48+
@test "http_after_response_rules: Delete a HTTP After Response Rule from backend" {
49+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
50+
skip "http-after-response is not supported in HAProxy 2.1"
51+
fi
52+
53+
#
54+
# Deleting the first one
55+
#
56+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_backend&force_reload=true"
57+
assert_equal "$SC" 204
58+
#
59+
# Deleting the second one
60+
#
61+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_backend&force_reload=true"
62+
assert_equal "$SC" 204
63+
#
64+
# No more HTTP after response rules, not found!
65+
#
66+
resource_delete "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_backend&force_reload=true"
67+
assert_equal "$SC" 404
68+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "http_after_response_rules: Return one HTTP After Response Rule from frontend" {
27+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
28+
skip "http-after-response is not supported in HAProxy 2.1"
29+
fi
30+
31+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_frontend"
32+
assert_equal "$SC" 200
33+
assert_equal "$(get_json_path "$BODY" ".data.type")" "add-header"
34+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Add-Frontend"
35+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "unless"
36+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 192.168.0.0/16 }"
37+
38+
resource_get "$_RES_RULES_BASE_PATH/1" "parent_type=frontend&parent_name=test_frontend"
39+
assert_equal "$SC" 200
40+
assert_equal "$(get_json_path "$BODY" ".data.type")" "del-header"
41+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Del-Frontend"
42+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
43+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 10.1.0.0/16 }"
44+
}
45+
46+
@test "http_after_response_rules: Return one HTTP After Response Rule from backend" {
47+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
48+
skip "http-after-response is not supported in HAProxy 2.1"
49+
fi
50+
51+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_backend"
52+
assert_equal "$SC" 200
53+
assert_equal "$(get_json_path "$BODY" ".data.type")" "add-header"
54+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Add-Backend"
55+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "unless"
56+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 192.168.0.0/16 }"
57+
58+
resource_get "$_RES_RULES_BASE_PATH/1" "parent_type=backend&parent_name=test_backend"
59+
assert_equal "$SC" 200
60+
assert_equal "$(get_json_path "$BODY" ".data.type")" "del-header"
61+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Del-Backend"
62+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
63+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 10.1.0.0/16 }"
64+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "http_after_response_rules: Return an array of all HTTP After Response Rules from frontend" {
27+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
28+
skip "http-after-response is not supported in HAProxy 2.1"
29+
fi
30+
31+
resource_get "$_RES_RULES_BASE_PATH" "parent_type=frontend&parent_name=test_frontend"
32+
assert_equal "$SC" 200
33+
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
34+
assert_equal "$(get_json_path "$BODY" ".data[0].type")" "add-header"
35+
assert_equal "$(get_json_path "$BODY" ".data[0].hdr_name")" "X-Add-Frontend"
36+
assert_equal "$(get_json_path "$BODY" ".data[0].cond")" "unless"
37+
assert_equal "$(get_json_path "$BODY" ".data[0].cond_test")" "{ src 192.168.0.0/16 }"
38+
assert_equal "$(get_json_path "$BODY" ".data[1].type")" "del-header"
39+
assert_equal "$(get_json_path "$BODY" ".data[1].hdr_name")" "X-Del-Frontend"
40+
assert_equal "$(get_json_path "$BODY" ".data[1].cond")" "if"
41+
assert_equal "$(get_json_path "$BODY" ".data[1].cond_test")" "{ src 10.1.0.0/16 }"
42+
}
43+
44+
@test "http_after_response_rules: Return one HTTP After Response Rule from backend" {
45+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
46+
skip "http-after-response is not supported in HAProxy 2.1"
47+
fi
48+
49+
resource_get "$_RES_RULES_BASE_PATH" "parent_type=backend&parent_name=test_backend"
50+
assert_equal "$SC" 200
51+
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
52+
assert_equal "$(get_json_path "$BODY" ".data[0].type")" "add-header"
53+
assert_equal "$(get_json_path "$BODY" ".data[0].hdr_name")" "X-Add-Backend"
54+
assert_equal "$(get_json_path "$BODY" ".data[0].cond")" "unless"
55+
assert_equal "$(get_json_path "$BODY" ".data[0].cond_test")" "{ src 192.168.0.0/16 }"
56+
assert_equal "$(get_json_path "$BODY" ".data[1].type")" "del-header"
57+
assert_equal "$(get_json_path "$BODY" ".data[1].hdr_name")" "X-Del-Backend"
58+
assert_equal "$(get_json_path "$BODY" ".data[1].cond")" "if"
59+
assert_equal "$(get_json_path "$BODY" ".data[1].cond_test")" "{ src 10.1.0.0/16 }"
60+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/resource_client'
21+
load '../../libs/version'
22+
23+
load 'utils/_helpers'
24+
25+
@test "http_after_response_rules: Fail creating a HTTP After Response rule when frontend doesn't exist" {
26+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
27+
skip "http-after-response is not supported in HAProxy 2.1"
28+
fi
29+
30+
resource_post "$_RES_RULES_BASE_PATH" "data/post.json" "parent_type=frontend&parent_name=ghost&force_reload=true"
31+
assert_equal "$SC" 400
32+
}
33+
34+
@test "http_after_response_rules: Fail creating a HTTP After Response rule when backend doesn't exist" {
35+
if $HAPROXY_VERSION == "2.1"; then
36+
skip "http-after-response is not supported in HAProxy 2.1"
37+
fi
38+
39+
resource_post "$_RES_RULES_BASE_PATH" "data/post.json" "parent_type=backend&parent_name=ghost&force_reload=true"
40+
assert_equal "$SC" 400
41+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "http_after_response_rules: Replace a HTTP After Response Rule of frontend" {
27+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
28+
skip "http-after-response is not supported in HAProxy 2.1"
29+
fi
30+
31+
resource_put "$_RES_RULES_BASE_PATH/0" "data/put.json" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
32+
assert_equal "$SC" 200
33+
34+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=frontend&parent_name=test_frontend&force_reload=true"
35+
assert_equal "$SC" 200
36+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
37+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 192.168.0.0/16 }"
38+
assert_equal "$(get_json_path "$BODY" ".data.type")" "add-header"
39+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Haproxy-Current-Date"
40+
assert_equal "$(get_json_path "$BODY" ".data.hdr_format")" "%T"
41+
}
42+
43+
@test "http_after_response_rules: Replace a HTTP After Response Rule of backend" {
44+
if [[ "$HAPROXY_VERSION" == "2.1" ]]; then
45+
skip "http-after-response is not supported in HAProxy 2.1"
46+
fi
47+
48+
resource_put "$_RES_RULES_BASE_PATH/0" "data/put.json" "parent_type=backend&parent_name=test_backend&force_reload=true"
49+
assert_equal "$SC" 200
50+
51+
resource_get "$_RES_RULES_BASE_PATH/0" "parent_type=backend&parent_name=test_backend&force_reload=true"
52+
assert_equal "$SC" 200
53+
assert_equal "$(get_json_path "$BODY" ".data.cond")" "if"
54+
assert_equal "$(get_json_path "$BODY" ".data.cond_test")" "{ src 192.168.0.0/16 }"
55+
assert_equal "$(get_json_path "$BODY" ".data.type")" "add-header"
56+
assert_equal "$(get_json_path "$BODY" ".data.hdr_name")" "X-Haproxy-Current-Date"
57+
assert_equal "$(get_json_path "$BODY" ".data.hdr_format")" "%T"
58+
}

0 commit comments

Comments
 (0)