Skip to content

Commit 6161c18

Browse files
hdurand0710mjuraga
authored andcommitted
BUG/MINOR: allow all HTTP methods in httpchk_params and http-check
1 parent 3ab8533 commit 6161c18

16 files changed

+373
-7
lines changed

e2e/tests/backends/data/post.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2+
"adv_check": "httpchk",
23
"balance": {
34
"algorithm": "roundrobin"
45
},
56
"forwardfor": {
67
"enabled": "enabled"
78
},
8-
"httpchk": {
9+
"httpchk_params": {
910
"method": "GET",
1011
"uri": "/check",
1112
"version": "HTTP/1.1"

e2e/tests/backends/data/post_2.2.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"adv_check": "httpchk",
3+
"balance": {
4+
"algorithm": "roundrobin"
5+
},
6+
"forwardfor": {
7+
"enabled": "enabled"
8+
},
9+
"httpchk_params": {
10+
"method": "GET",
11+
"uri": "/check",
12+
"version": "HTTP/1.1"
13+
},
14+
"http-check": {
15+
"index": 0,
16+
"method": "OPTIONS",
17+
"uri": "/",
18+
"version": "HTTP/1.1",
19+
"type": "send"
20+
},
21+
"mode": "http",
22+
"name": "test_backend"
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"adv_check": "httpchk",
3+
"balance": {
4+
"algorithm": "roundrobin"
5+
},
6+
"forwardfor": {
7+
"enabled": "enabled"
8+
},
9+
"httpchk_params": {
10+
"method": "invalid",
11+
"uri": "/check",
12+
"version": "HTTP/1.1"
13+
},
14+
"http-check": {
15+
"index": 0,
16+
"method": "OPTIONS",
17+
"uri": "/",
18+
"version": "HTTP/1.1",
19+
"type": "send"
20+
},
21+
"mode": "http",
22+
"name": "test_backend"
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"adv_check": "httpchk",
3+
"balance": {
4+
"algorithm": "roundrobin"
5+
},
6+
"forwardfor": {
7+
"enabled": "enabled"
8+
},
9+
"httpchk_params": {
10+
"method": "GET",
11+
"uri": "/check",
12+
"version": "HTTP/1.1"
13+
},
14+
"http-check": {
15+
"index": 0,
16+
"method": "invalid",
17+
"uri": "/",
18+
"version": "HTTP/1.1",
19+
"type": "send"
20+
},
21+
"mode": "http",
22+
"name": "test_backend"
23+
}

e2e/tests/backends/data/put.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2+
"adv_check": "httpchk",
23
"balance": {
34
"algorithm": "static-rr"
45
},
5-
"httpchk": {
6+
"httpchk_params": {
67
"method": "GET",
78
"uri": "/healthz",
89
"version": "HTTP/1.1"

e2e/tests/backends/test.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ load 'utils/_helpers'
2525
@test "backends: Add a backend" {
2626
resource_post "$_BACKEND_BASE_PATH" "data/post.json" "force_reload=true"
2727
assert_equal "$SC" "201"
28+
29+
resource_get "$_BACKEND_BASE_PATH/test_backend" assert_equal "$SC" 200
30+
assert_equal "$(get_json_path "$BODY" ".data.adv_check")" "httpchk"
31+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.method")" "GET"
32+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.uri")" "/check"
33+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.version")" "HTTP/1.1"
34+
}
35+
36+
@test "backends: fail adding a backend (invalid send method in httpchk_params)" {
37+
resource_post "$_BACKEND_BASE_PATH" "data/post_invalid_send_method_1.json" "force_reload=true"
38+
assert_equal "$SC" 422
39+
assert_equal "$(get_json_path "$BODY" ".code")" "606"
40+
}
41+
42+
@test "backends: fail adding a backend (invalid send method in http-check)" {
43+
resource_post "$_BACKEND_BASE_PATH" "data/post_invalid_send_method_2.json" "force_reload=true"
44+
assert_equal "$SC" 422
45+
assert_equal "$(get_json_path "$BODY" ".code")" "606"
2846
}
2947

3048
@test "backends: Return a backend" {
@@ -36,6 +54,12 @@ load 'utils/_helpers'
3654
@test "backends: Replace a backend" {
3755
resource_put "$_BACKEND_BASE_PATH/test_backend" "data/put.json" "force_reload=true"
3856
assert_equal "$SC" 200
57+
58+
resource_get "$_BACKEND_BASE_PATH/test_backend" assert_equal "$SC" 200
59+
assert_equal "$(get_json_path "$BODY" ".data.adv_check")" "httpchk"
60+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.method")" "GET"
61+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.uri")" "/healthz"
62+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.version")" "HTTP/1.1"
3963
}
4064

4165
@test "backends: Return an array of backends" {

e2e/tests/backends/test_2.2.bats

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
load '../../libs/haproxy_version'
23+
24+
load 'utils/_helpers'
25+
26+
27+
@test "backends: Add a backend (>=2.2)" {
28+
if haproxy_version_ge "2.2"
29+
then
30+
resource_post "$_BACKEND_BASE_PATH" "data/post_2.2.json" "force_reload=true"
31+
assert_equal "$SC" "201"
32+
33+
resource_get "$_BACKEND_BASE_PATH/test_backend" assert_equal "$SC" 200
34+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".method")" "OPTIONS"
35+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".uri")" "/"
36+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".version")" "HTTP/1.1"
37+
assert_equal "$(get_json_path "$BODY" ".data.adv_check")" "httpchk"
38+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.method")" "GET"
39+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.uri")" "/check"
40+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.version")" "HTTP/1.1"
41+
fi
42+
}
43+
44+
@test "backends: Replace a backend (>=2.2)" {
45+
if haproxy_version_ge "2.2"
46+
then
47+
resource_put "$_BACKEND_BASE_PATH/test_backend" "data/put.json" "force_reload=true"
48+
assert_equal "$SC" 200
49+
50+
resource_get "$_BACKEND_BASE_PATH/test_backend" assert_equal "$SC" 200
51+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".method")" "OPTIONS"
52+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".uri")" "/"
53+
assert_equal "$(get_json_path "$BODY" ".data.\"http-check\".version")" "HTTP/1.1"
54+
assert_equal "$(get_json_path "$BODY" ".data.adv_check")" "httpchk"
55+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.method")" "GET"
56+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.uri")" "/healthz"
57+
assert_equal "$(get_json_path "$BODY" ".data.httpchk_params.version")" "HTTP/1.1"
58+
fi
59+
}
60+
61+
@test "backends: Delete a backend" {
62+
if haproxy_version_ge "2.2"
63+
then
64+
resource_delete "$_BACKEND_BASE_PATH/test_backend" "force_reload=true"
65+
assert_equal "$SC" 204
66+
fi
67+
}

e2e/tests/http_checks/add_2.2.bats

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 2023 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+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
@test "http_checks: Add a new HTTP Check (send) to defaults (>=2.2)" {
28+
if haproxy_version_ge "2.2"
29+
then
30+
resource_post "$_CHECKS_BASE_PATH" "data/post_defaults_send.json" "parent_type=defaults&force_reload=true"
31+
assert_equal "$SC" 201
32+
33+
resource_get "$_CHECKS_BASE_PATH/2" "parent_type=defaults"
34+
assert_equal "$SC" 200
35+
assert_equal "$(get_json_path "$BODY" ".data.method")" "OPTIONS"
36+
assert_equal "$(get_json_path "$BODY" ".data.uri")" "/"
37+
assert_equal "$(get_json_path "$BODY" ".data.version")" "HTTP/1.1"
38+
fi
39+
}
40+
41+
42+
@test "http_checks: Add a new HTTP Check (send) to backend (>=2.2)" {
43+
if haproxy_version_ge "2.2"
44+
then
45+
resource_post "$_CHECKS_BASE_PATH" "data/post_send.json" "parent_type=backend&parent_name=test_backend_2&force_reload=true"
46+
assert_equal "$SC" 201
47+
48+
resource_get "$_CHECKS_BASE_PATH/0" "parent_type=backend&parent_name=test_backend_2"
49+
assert_equal "$SC" 200
50+
assert_equal "$(get_json_path "$BODY" ".data.method")" "OPTIONS"
51+
assert_equal "$(get_json_path "$BODY" ".data.uri")" "/"
52+
assert_equal "$(get_json_path "$BODY" ".data.version")" "HTTP/1.1"
53+
fi
54+
}
55+
56+
57+
@test "http_checks: fail adding an invalid HTTP Check (send method) to backend (>=2.2)" {
58+
if haproxy_version_ge "2.2"
59+
then
60+
resource_post "$_CHECKS_BASE_PATH" "data/post_invalid_send_method.json" "parent_type=backend&parent_name=test_backend_2&force_reload=true"
61+
assert_equal "$SC" 422
62+
assert_equal "$(get_json_path "$BODY" ".code")" "606"
63+
fi
64+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
option httpchk
20+
timeout http-request 10s
21+
timeout check 10s
22+
timeout connect 10s
23+
timeout client 1m
24+
timeout queue 1m
25+
timeout server 1m
26+
timeout http-keep-alive 10s
27+
http-check send-state
28+
http-check disable-on-404
29+
retries 3
30+
31+
frontend test_frontend
32+
mode http
33+
bind :80
34+
maxconn 1000
35+
option httpclose
36+
37+
backend test_backend
38+
mode http
39+
balance roundrobin
40+
option forwardfor
41+
option httpchk
42+
http-check send meth OPTIONS uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
43+
http-check expect status 200-399
44+
45+
backend test_backend_2
46+
http-check expect status 200-399
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"index": 2,
3+
"type": "send",
4+
"method": "OPTIONS",
5+
"uri": "/",
6+
"version": "HTTP/1.1"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"index": 0,
3+
"type": "send",
4+
"method": "invalid",
5+
"uri": "/",
6+
"version": "HTTP/1.1"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"index": 0,
3+
"type": "send",
4+
"method": "OPTIONS",
5+
"uri": "/",
6+
"version": "HTTP/1.1"
7+
}

e2e/tests/http_checks/get_2.2.bats

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2023 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+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
28+
@test "http_checks: Return one HTTP Check from backend (>=2.2)" {
29+
if haproxy_version_ge "2.2"
30+
then
31+
resource_get "$_CHECKS_BASE_PATH/0" "parent_type=backend&parent_name=test_backend"
32+
assert_equal "$(get_json_path "$BODY" ".data.type")" "send"
33+
assert_equal 1 "$(get_json_path "$BODY" ".data.headers | length")"
34+
assert_equal "$(get_json_path "$BODY" ".data.headers[0].name")" "host"
35+
assert_equal "$(get_json_path "$BODY" ".data.headers[0].fmt")" "haproxy.1wt.eu"
36+
assert_equal "$(get_json_path "$BODY" ".data.method")" "OPTIONS"
37+
assert_equal "$(get_json_path "$BODY" ".data.uri")" "/"
38+
assert_equal "$(get_json_path "$BODY" ".data.version")" "HTTP/1.1"
39+
40+
resource_get "$_CHECKS_BASE_PATH/1" "parent_type=backend&parent_name=test_backend"
41+
assert_equal "$(get_json_path "$BODY" ".data.type")" "expect"
42+
assert_equal "$(get_json_path "$BODY" ".data.match")" "status"
43+
assert_equal "$(get_json_path "$BODY" ".data.pattern")" "200-399"
44+
fi
45+
}

0 commit comments

Comments
 (0)