瀏覽代碼

test: per vhost custom config for wildcard hosts

Nicolas Duchon 1 月之前
父節點
當前提交
8d3b5c957a

+ 1 - 0
test/test_custom/my_custom_proxy_settings_baz.conf

@@ -0,0 +1 @@
+add_header X-test-2 baz;

+ 16 - 4
test/test_custom/test_location-per-vhost.py

@@ -2,26 +2,38 @@ def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy)
     r = nginxproxy.get("http://nginx-proxy/")
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503
     assert r.status_code == 503
     assert "X-test" not in r.headers
     assert "X-test" not in r.headers
+    assert "X-test-2" not in r.headers
 
 
 def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
 def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    assert r.status_code == 200
     assert r.text == "answer from port 81\n"
     assert r.text == "answer from port 81\n"
     assert "X-test" in r.headers
     assert "X-test" in r.headers
+    assert "X-test-2" not in r.headers
     assert "f00" == r.headers["X-test"]
     assert "f00" == r.headers["X-test"]
 
 
 def test_custom_conf_applies_to_regex(docker_compose, nginxproxy):
 def test_custom_conf_applies_to_regex(docker_compose, nginxproxy):
-    r = nginxproxy.get("http://regex.foo.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    r = nginxproxy.get("http://foo.nginx-proxy.regex/port")
+    assert r.status_code == 200
     assert r.text == "answer from port 83\n"
     assert r.text == "answer from port 83\n"
     assert "X-test" in r.headers
     assert "X-test" in r.headers
+    assert "X-test-2" not in r.headers
     assert "bar" == r.headers["X-test"]
     assert "bar" == r.headers["X-test"]
 
 
+def test_custom_conf_applies_to_wildcard(docker_compose, nginxproxy):
+    r = nginxproxy.get("http://foo.nginx-proxy.example/port")
+    assert r.status_code == 200
+    assert r.text == "answer from port 84\n"
+    assert "X-test" not in r.headers
+    assert "X-test-2" in r.headers
+    assert "baz" == r.headers["X-test-2"]
+
 def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
 def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web2.nginx-proxy.example/port")
     r = nginxproxy.get("http://web2.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    assert r.status_code == 200
     assert r.text == "answer from port 82\n"
     assert r.text == "answer from port 82\n"
     assert "X-test" not in r.headers
     assert "X-test" not in r.headers
+    assert "X-test-2" not in r.headers
 
 
 def test_custom_block_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
 def test_custom_block_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
     assert b"include /etc/nginx/vhost.d/web1.nginx-proxy.example_location;" in nginxproxy.get_conf()
     assert b"include /etc/nginx/vhost.d/web1.nginx-proxy.example_location;" in nginxproxy.get_conf()

+ 11 - 2
test/test_custom/test_location-per-vhost.yml

@@ -3,7 +3,8 @@ services:
     volumes:
     volumes:
       - /var/run/docker.sock:/tmp/docker.sock:ro
       - /var/run/docker.sock:/tmp/docker.sock:ro
       - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_f00.conf:/etc/nginx/vhost.d/web1.nginx-proxy.example_location:ro
       - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_f00.conf:/etc/nginx/vhost.d/web1.nginx-proxy.example_location:ro
-      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/561032515ede3ab3a015edfb244608b72409c430_location:ro
+      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/97db860fb631ba3c047db9fec60638fd72a180b1_location:ro
+      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_baz.conf:/etc/nginx/vhost.d/*.nginx-proxy.example_location:ro
 
 
   web1:
   web1:
     image: web
     image: web
@@ -27,4 +28,12 @@ services:
       - "83"
       - "83"
     environment:
     environment:
       WEB_PORTS: "83"
       WEB_PORTS: "83"
-      VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$$ # we need to double the `$` because of docker compose variable interpolation
+      VIRTUAL_HOST: ~^.*\.nginx-proxy\.regex$$ # we need to double the `$` because of docker compose variable interpolation
+  
+  wildcard:
+    image: web
+    expose:
+      - "84"
+    environment:
+      WEB_PORTS: "84"
+      VIRTUAL_HOST: "*.nginx-proxy.example" # wildcard for all subdomains

+ 16 - 4
test/test_custom/test_per-vhost.py

@@ -2,23 +2,35 @@ def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy)
     r = nginxproxy.get("http://nginx-proxy/")
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503
     assert r.status_code == 503
     assert "X-test" not in r.headers
     assert "X-test" not in r.headers
+    assert "X-test-2" not in r.headers
 
 
 def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
 def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    assert r.status_code == 200
     assert r.text == "answer from port 81\n"
     assert r.text == "answer from port 81\n"
     assert "X-test" in r.headers
     assert "X-test" in r.headers
+    assert "X-test-2" not in r.headers
     assert "f00" == r.headers["X-test"]
     assert "f00" == r.headers["X-test"]
 
 
 def test_custom_conf_applies_to_regex(docker_compose, nginxproxy):
 def test_custom_conf_applies_to_regex(docker_compose, nginxproxy):
-    r = nginxproxy.get("http://regex.foo.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    r = nginxproxy.get("http://foo.nginx-proxy.regex/port")
+    assert r.status_code == 200
     assert r.text == "answer from port 83\n"
     assert r.text == "answer from port 83\n"
     assert "X-test" in r.headers
     assert "X-test" in r.headers
+    assert "X-test-2" not in r.headers
     assert "bar" == r.headers["X-test"]
     assert "bar" == r.headers["X-test"]
 
 
+def test_custom_conf_applies_to_wildcard(docker_compose, nginxproxy):
+    r = nginxproxy.get("http://foo.nginx-proxy.example/port")
+    assert r.status_code == 200
+    assert r.text == "answer from port 84\n"
+    assert "X-test" not in r.headers
+    assert "X-test-2" in r.headers
+    assert "baz" == r.headers["X-test-2"]
+
 def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
 def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web2.nginx-proxy.example/port")
     r = nginxproxy.get("http://web2.nginx-proxy.example/port")
-    assert r.status_code == 200   
+    assert r.status_code == 200
     assert r.text == "answer from port 82\n"
     assert r.text == "answer from port 82\n"
     assert "X-test" not in r.headers
     assert "X-test" not in r.headers
+    assert "X-test-2" not in r.headers

+ 11 - 2
test/test_custom/test_per-vhost.yml

@@ -3,7 +3,8 @@ services:
     volumes:
     volumes:
       - /var/run/docker.sock:/tmp/docker.sock:ro
       - /var/run/docker.sock:/tmp/docker.sock:ro
       - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_f00.conf:/etc/nginx/vhost.d/web1.nginx-proxy.example:ro
       - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_f00.conf:/etc/nginx/vhost.d/web1.nginx-proxy.example:ro
-      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/561032515ede3ab3a015edfb244608b72409c430:ro
+      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/97db860fb631ba3c047db9fec60638fd72a180b1:ro
+      - ${PYTEST_MODULE_PATH}/my_custom_proxy_settings_baz.conf:/etc/nginx/vhost.d/*.nginx-proxy.example:ro
 
 
   web1:
   web1:
     image: web
     image: web
@@ -27,4 +28,12 @@ services:
       - "83"
       - "83"
     environment:
     environment:
       WEB_PORTS: "83"
       WEB_PORTS: "83"
-      VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$$ # we need to double the `$` because of docker compose variable interpolation
+      VIRTUAL_HOST: ~^.*\.nginx-proxy\.regex$$ # we need to double the `$` because of docker compose variable interpolation
+
+  wildcard:
+    image: web
+    expose:
+      - "84"
+    environment:
+      WEB_PORTS: "84"
+      VIRTUAL_HOST: "*.nginx-proxy.example" # wildcard for all subdomains