1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-05-06 07:36:10 +02:00

test: Add test case for location config priority

This commit is contained in:
Alexander Lieret 2021-08-18 15:34:30 +02:00 committed by Nicolas Duchon
parent 4099fcd618
commit 6a580ad664
No known key found for this signature in database
GPG Key ID: 91EF7BB1EECB961A
5 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1 @@
add_header X-test-default true;

View File

@ -0,0 +1 @@
add_header X-test-host true;

View File

@ -0,0 +1 @@
add_header X-test-path true;

View File

@ -0,0 +1,32 @@
import pytest
def test_location_precedence_case1(docker_compose, nginxproxy):
r = nginxproxy.get(f"http://foo.nginx-proxy.test/web1/port")
assert r.status_code == 200
assert "X-test-default" in r.headers
assert "X-test-host" not in r.headers
assert "X-test-path" not in r.headers
assert r.headers["X-test-default"] == "true"
def test_location_precedence_case2(docker_compose, nginxproxy):
r = nginxproxy.get(f"http://bar.nginx-proxy.test/web2/port")
assert r.status_code == 200
assert "X-test-default" not in r.headers
assert "X-test-host" in r.headers
assert "X-test-path" not in r.headers
assert r.headers["X-test-host"] == "true"
def test_location_precedence_case3(docker_compose, nginxproxy):
r = nginxproxy.get(f"http://bar.nginx-proxy.test/web3/port")
assert r.status_code == 200
assert "X-test-default" not in r.headers
assert "X-test-host" not in r.headers
assert "X-test-path" in r.headers
assert r.headers["X-test-path"] == "true"

View File

@ -0,0 +1,38 @@
web1:
image: web
expose:
- "81"
environment:
WEB_PORTS: "81"
VIRTUAL_HOST: "foo.nginx-proxy.test"
VIRTUAL_PATH: "/web1/"
VIRTUAL_DEST: "/"
web2:
image: web
expose:
- "82"
environment:
WEB_PORTS: "82"
VIRTUAL_HOST: "bar.nginx-proxy.test"
VIRTUAL_PATH: "/web2/"
VIRTUAL_DEST: "/"
web3:
image: web
expose:
- "83"
environment:
WEB_PORTS: "83"
VIRTUAL_HOST: "bar.nginx-proxy.test"
VIRTUAL_PATH: "/web3/"
VIRTUAL_DEST: "/"
sut:
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
- ./default.conf:/etc/nginx/vhost.d/default_location:ro
- ./host.conf:/etc/nginx/vhost.d/bar.nginx-proxy.test_location:ro
- ./path.conf:/etc/nginx/vhost.d/bar.nginx-proxy.test_99f2db0ed8aa95dbb5b87fca79c7eff2ff6bb8bd_location:ro