Minor adjustment in Static unittest.
This commit is contained in:
parent
75deebc783
commit
ddfa2e34ae
3 changed files with 98 additions and 27 deletions
95
tests/expected/static.txt
Normal file
95
tests/expected/static.txt
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
global
|
||||||
|
log stdout format raw local0 info
|
||||||
|
maxconn 2000
|
||||||
|
tune.ssl.default-dh-param 2048
|
||||||
|
|
||||||
|
defaults
|
||||||
|
log global
|
||||||
|
|
||||||
|
timeout connect 3s
|
||||||
|
timeout client 10s
|
||||||
|
timeout server 10m
|
||||||
|
errorfile 400 /etc/haproxy/errors-custom/400.http
|
||||||
|
errorfile 403 /etc/haproxy/errors-custom/403.http
|
||||||
|
errorfile 408 /etc/haproxy/errors-custom/408.http
|
||||||
|
errorfile 500 /etc/haproxy/errors-custom/500.http
|
||||||
|
errorfile 502 /etc/haproxy/errors-custom/502.http
|
||||||
|
errorfile 503 /etc/haproxy/errors-custom/503.http
|
||||||
|
errorfile 504 /etc/haproxy/errors-custom/504.http
|
||||||
|
|
||||||
|
frontend stats
|
||||||
|
bind *:1936
|
||||||
|
mode http
|
||||||
|
stats enable
|
||||||
|
stats hide-version
|
||||||
|
stats realm Haproxy\ Statistics
|
||||||
|
stats uri /
|
||||||
|
stats auth admin:test123
|
||||||
|
# acl is_proxystats hdr(host) -i some.host.com
|
||||||
|
# default_backend srv_stats
|
||||||
|
# use_backend srv_stats if is_proxystats
|
||||||
|
default_backend srv_stats
|
||||||
|
|
||||||
|
backend srv_stats
|
||||||
|
mode http
|
||||||
|
server Local 127.0.0.1:1936
|
||||||
|
|
||||||
|
frontend http_in_80_1
|
||||||
|
bind *:80
|
||||||
|
mode http
|
||||||
|
redirect prefix http://host1.com.br code 301 if { hdr(host) -i www.host1.com.br }
|
||||||
|
|
||||||
|
acl is_rule_host1_com_br_80_1_1 hdr(host) -i host1.com.br
|
||||||
|
acl is_rule_host1_com_br_80_1_2 hdr(host) -i host1.com.br:80
|
||||||
|
use_backend srv_host1_com_br_80_1 if is_rule_host1_com_br_80_1_1 OR is_rule_host1_com_br_80_1_2
|
||||||
|
|
||||||
|
acl is_rule_host2_com_br_80_1_1 hdr(host) -i host2.com.br
|
||||||
|
acl is_rule_host2_com_br_80_1_2 hdr(host) -i host2.com.br:80
|
||||||
|
use_backend srv_host2_com_br_80_1 if is_rule_host2_com_br_80_1_1 OR is_rule_host2_com_br_80_1_2
|
||||||
|
|
||||||
|
backend srv_host1_com_br_80_1
|
||||||
|
balance roundrobin
|
||||||
|
mode http
|
||||||
|
option forwardfor
|
||||||
|
http-request set-header X-Forwarded-Port %[dst_port]
|
||||||
|
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||||
|
server srv container:5000 check weight 1
|
||||||
|
backend srv_host2_com_br_80_1
|
||||||
|
balance roundrobin
|
||||||
|
mode http
|
||||||
|
option forwardfor
|
||||||
|
http-request set-header X-Forwarded-Port %[dst_port]
|
||||||
|
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||||
|
server srv other:3000 check weight 1
|
||||||
|
|
||||||
|
frontend http_in_443_2
|
||||||
|
bind *:443 ssl crt /etc/haproxy/certs/mycert.pem
|
||||||
|
mode http
|
||||||
|
|
||||||
|
acl is_rule_host1_com_br_443_2_1 hdr(host) -i host1.com.br
|
||||||
|
acl is_rule_host1_com_br_443_2_2 hdr(host) -i host1.com.br:443
|
||||||
|
use_backend srv_host1_com_br_443_2 if is_rule_host1_com_br_443_2_1 OR is_rule_host1_com_br_443_2_2
|
||||||
|
|
||||||
|
backend srv_host1_com_br_443_2
|
||||||
|
balance roundrobin
|
||||||
|
mode http
|
||||||
|
option forwardfor
|
||||||
|
http-request set-header X-Forwarded-Port %[dst_port]
|
||||||
|
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||||
|
server srv container:80 check weight 1
|
||||||
|
|
||||||
|
frontend http_in_8080_3
|
||||||
|
bind *:8080
|
||||||
|
mode http
|
||||||
|
|
||||||
|
acl is_rule_host3_com_br_8080_3_1 hdr(host) -i host3.com.br
|
||||||
|
acl is_rule_host3_com_br_8080_3_2 hdr(host) -i host3.com.br:8080
|
||||||
|
use_backend srv_host3_com_br_8080_3 if is_rule_host3_com_br_8080_3_1 OR is_rule_host3_com_br_8080_3_2
|
||||||
|
|
||||||
|
backend srv_host3_com_br_8080_3
|
||||||
|
balance roundrobin
|
||||||
|
mode http
|
||||||
|
option forwardfor
|
||||||
|
http-request set-header X-Forwarded-Port %[dst_port]
|
||||||
|
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||||
|
server srv domain:8181 check weight 1
|
||||||
2
tests/fixtures/static.yml
vendored
2
tests/fixtures/static.yml
vendored
|
|
@ -14,7 +14,7 @@ easymapping:
|
||||||
www.host1.com.br: http://host1.com.br
|
www.host1.com.br: http://host1.com.br
|
||||||
|
|
||||||
- port: 443
|
- port: 443
|
||||||
ssl_cert: BASE64_PEM_CERTIFICATE
|
ssl_cert: /etc/haproxy/certs/mycert.pem
|
||||||
hosts:
|
hosts:
|
||||||
host1.com.br: container:80
|
host1.com.br: container:80
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,8 @@ def test_parser_static():
|
||||||
haproxy_config = cfg.generate()
|
haproxy_config = cfg.generate()
|
||||||
assert len(haproxy_config) > 0
|
assert len(haproxy_config) > 0
|
||||||
|
|
||||||
# assert on auth on stats
|
with open(path + "/expected/static.txt", 'r') as expected_file:
|
||||||
assert "stats auth admin:test123" in haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
|
|
||||||
# assert that we found redirect
|
|
||||||
assert "redirect prefix http://host1.com.br code 301 if { hdr(host) -i www.host1.com.br }" in haproxy_config
|
|
||||||
|
|
||||||
# assert that we found the services
|
|
||||||
frontend_http_cfg = "frontend http_in_80_1\n"
|
|
||||||
frontend_http_cfg += " bind *:80"
|
|
||||||
assert frontend_http_cfg in haproxy_config
|
|
||||||
|
|
||||||
frontend_https_cfg = "frontend http_in_443_2\n"
|
|
||||||
frontend_https_cfg += " bind *:443"
|
|
||||||
assert frontend_https_cfg in haproxy_config
|
|
||||||
|
|
||||||
# print(haproxy_config)
|
|
||||||
frontend_http8080_cfg = "frontend http_in_8080_3\n"
|
|
||||||
frontend_http8080_cfg += " bind *:8080"
|
|
||||||
assert frontend_http8080_cfg in haproxy_config
|
|
||||||
|
|
||||||
|
|
||||||
# verify ssl config with certificate
|
|
||||||
frontend_ssl_cfg = "frontend http_in_443_2\n"
|
|
||||||
frontend_ssl_cfg += " bind *:443 ssl crt BASE64_PEM_CERTIFICATE"
|
|
||||||
assert frontend_ssl_cfg in haproxy_config
|
|
||||||
|
|
||||||
|
|
||||||
def test_parser_tcp():
|
def test_parser_tcp():
|
||||||
lineList = load_fixture("services-tcp")
|
lineList = load_fixture("services-tcp")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue