mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
test: Add test cases for NETWORK_ACCESS=internal
This commit is contained in:
parent
28c74e8dae
commit
2509fc1076
11
test/test_internal/network_internal.conf
Normal file
11
test/test_internal/network_internal.conf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Only allow traffic from internal clients
|
||||||
|
allow 127.0.0.0/8;
|
||||||
|
allow 10.0.0.0/8;
|
||||||
|
allow 192.168.0.0/16;
|
||||||
|
allow 172.16.0.0/12;
|
||||||
|
allow fc00::/7; # IPv6 local address range
|
||||||
|
deny all;
|
||||||
|
|
||||||
|
# Dummy header for testing
|
||||||
|
add_header X-network internal;
|
||||||
|
|
14
test/test_internal/test_per-vhost.py
Normal file
14
test/test_internal/test_per-vhost.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_network_web1(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://web1.nginx-proxy.local/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 81\n"
|
||||||
|
assert "X-network" in r.headers
|
||||||
|
assert "internal" == r.headers["X-network"]
|
||||||
|
|
||||||
|
def test_network_web2(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://web2.nginx-proxy.local/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 82\n"
|
||||||
|
assert "X-network" not in r.headers
|
24
test/test_internal/test_per-vhost.yml
Normal file
24
test/test_internal/test_per-vhost.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
web1:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "81"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: 81
|
||||||
|
VIRTUAL_HOST: web1.nginx-proxy.local
|
||||||
|
NETWORK_ACCESS: internal
|
||||||
|
|
||||||
|
web2:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "82"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: 82
|
||||||
|
VIRTUAL_HOST: web2.nginx-proxy.local
|
||||||
|
|
||||||
|
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
|
||||||
|
- ./network_internal.conf:/etc/nginx/network_internal.conf:ro
|
||||||
|
|
14
test/test_internal/test_per-vpath.py
Normal file
14
test/test_internal/test_per-vpath.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_network_web1(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://nginx-proxy.local/web1/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 81\n"
|
||||||
|
assert "X-network" in r.headers
|
||||||
|
assert "internal" == r.headers["X-network"]
|
||||||
|
|
||||||
|
def test_network_web2(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://nginx-proxy.local/web2/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 82\n"
|
||||||
|
assert "X-network" not in r.headers
|
28
test/test_internal/test_per-vpath.yml
Normal file
28
test/test_internal/test_per-vpath.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
web1:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "81"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: 81
|
||||||
|
VIRTUAL_HOST: nginx-proxy.local
|
||||||
|
VIRTUAL_PATH: /web1/
|
||||||
|
VIRTUAL_DEST: /
|
||||||
|
NETWORK_ACCESS: internal
|
||||||
|
|
||||||
|
web2:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "82"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: 82
|
||||||
|
VIRTUAL_HOST: nginx-proxy.local
|
||||||
|
VIRTUAL_PATH: /web2/
|
||||||
|
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
|
||||||
|
- ./network_internal.conf:/etc/nginx/network_internal.conf:ro
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user