Skip to content

Commit

Permalink
Fix regex from Traefik 1 path prefix rules (#189)
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.

BTW I update MQT repo.
  • Loading branch information
yajo authored Nov 30, 2020
1 parent eaa07d6 commit 0365f65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 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
8 changes: 6 additions & 2 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_multiple_domains(
# XXX Remove traefik1 specific stuff some day
is_traefik1 = version.parse(traefik_host["traefik_version"]) < version.parse("2")
data = {
"odoo_listdb": True,
"odoo_version": supported_odoo_version,
"paths_without_crawlers": ["/web/login", "/web/database"],
"project_name": uuid.uuid4().hex,
f"domains_{environment}": [
# main0 has no TLS
Expand Down Expand Up @@ -153,11 +155,13 @@ def test_multiple_domains(
# alt0 and alt1, with self-signed TLS
for alt_num in range(2):
response = requests.get(
f"http://alt{alt_num}.main1.{base_path}",
f"http://alt{alt_num}.main1.{base_domain}/web/database/selector",
verify=False,
)
assert response.ok
assert response.url == f"https://main1.{base_path}"
assert (
response.url == f"https://main1.{base_domain}/web/database/selector"
)
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# missing, which fails with Traefik 404, both with and without TLS
bad_response = requests.get(
Expand Down
2 changes: 1 addition & 1 deletion vendor/maintainer-quality-tools

0 comments on commit 0365f65

Please sign in to comment.