From 80e956eb283530a7b320867c3a41a95907e379d5 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 26 Nov 2020 13:01:54 +0000 Subject: [PATCH] Fix regex from Traefik 1 path prefix rules The path matching is hard because for example a rule such as `/example` must match also `/example/*`, but it must not match `/example*`; and Traefik 1 has no *OR* rules. Well, there was some problem on the way these matches worked. This should fix #116. BTW I update MQT repo. --- _traefik1_labels.yml.jinja | 7 +++++-- tests/test_routing.py | 3 +++ vendor/maintainer-quality-tools | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/_traefik1_labels.yml.jinja b/_traefik1_labels.yml.jinja index e7fc8160..50336b32 100644 --- a/_traefik1_labels.yml.jinja +++ b/_traefik1_labels.yml.jinja @@ -10,8 +10,11 @@ {%- macro path_prefix_rule(path_prefixes) -%} Path: {%- for path in path_prefixes %} - {%- set sep = "" if path.endswith("/") else "/" %} - {{- path }}{anything:{{ sep }}.*} + {%- if path.endswith("/") %} + {{- path }}{anything:.*} + {%- else %} + {{- path }},{{- path }}/{anything:.*} + {%- endif %} {%- if not loop.last %},{% endif %} {%- endfor %} {%- endmacro %} diff --git a/tests/test_routing.py b/tests/test_routing.py index 29b81087..ce3bafb9 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -56,6 +56,7 @@ def test_multiple_domains( "cert_resolver": False, }, ], + "paths_without_crawlers": ["/web", "/insecure/path"], } dc = docker_compose["-f", f"{environment}.yaml"] with local.cwd(tmp_path): @@ -104,6 +105,7 @@ def test_multiple_domains( assert ( bad_response.url == f"https://main2.{base_domain}:443/insecure/path" ) + assert bad_response.headers["X-Robots-Tag"] == "noindex, nofollow" else: # main0, no TLS response = requests.get(f"http://main0.{base_path}") @@ -125,6 +127,7 @@ def test_multiple_domains( assert bad_response.status_code == 404 assert "Werkzeug" in bad_response.headers.get("Server") assert bad_response.url == f"http://main2.{base_domain}/insecure/path" + assert bad_response.headers["X-Robots-Tag"] == "noindex, nofollow" # main3 cannot find /web on port 8080; no HTTPS redirection bad_response = requests.get( f"http://main3.{base_domain}:8080/web", diff --git a/vendor/maintainer-quality-tools b/vendor/maintainer-quality-tools index aab40189..c9864146 160000 --- a/vendor/maintainer-quality-tools +++ b/vendor/maintainer-quality-tools @@ -1 +1 @@ -Subproject commit aab40189e04e6a6bf8ab4fcbf184571721ac7717 +Subproject commit c9864146f4ee19dd5a7c7bf5a0ea7001ff4700cd