Skip to content

Commit

Permalink
Fix regex from Traefik 1 path prefix rules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jairo Llopis committed Nov 26, 2020
1 parent 3ca4c8a commit 80e956e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions _traefik1_labels.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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}")
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion vendor/maintainer-quality-tools

0 comments on commit 80e956e

Please sign in to comment.