Skip to content

Commit

Permalink
[FIX] Adapt test to traefik3
Browse files Browse the repository at this point in the history
- Add traefik versions to test's matrix
- Get traefik version from env
- Avoid no HTTPS on traefik v3
  • Loading branch information
josep-tecnativa committed Jun 26, 2024
1 parent 2593d6c commit 5fd1793
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
odoo-version: 17.0
- python-version: 3.11
odoo-version: 17.0
traefik_version:
- 1
- 2
- 3

steps:
# Shared steps
Expand Down Expand Up @@ -92,7 +96,9 @@ jobs:
- run: poetry run invoke test
env:
SELECTED_ODOO_VERSIONS: ${{ matrix.odoo-version }}
TRAEFIK_VERSION: ${{ matrix.traefik_version }}
# Concurrent tests (isolated)
- run: poetry run invoke test --sequential
env:
SELECTED_ODOO_VERSIONS: ${{ matrix.odoo-version }}
TRAEFIK_VERSION: ${{ matrix.traefik_version }}
33 changes: 25 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import pytest
import yaml
from packaging import version
from plumbum import ProcessExecutionError, local
from plumbum.cmd import git, invoke
from python_on_whales import DockerClient
Expand All @@ -24,6 +23,9 @@
# Different tests test different Odoo versions
OLDEST_SUPPORTED_ODOO_VERSION = 11.0
ALL_ODOO_VERSIONS = tuple(COPIER_SETTINGS["odoo_version"]["choices"])
# ALL_TRAEFIK_VERSIONS = tuple(COPIER_SETTINGS["traefik_version"]["choices"])
TRAEFIK_VERSION = os.getenv("TRAEFIK_VERSION", "3")

SUPPORTED_ODOO_VERSIONS = tuple(
v for v in ALL_ODOO_VERSIONS if v >= OLDEST_SUPPORTED_ODOO_VERSION
)
Expand Down Expand Up @@ -68,9 +70,6 @@
},
}

# Traefik versions matrix
ALL_TRAEFIK_VERSIONS = ("latest", "1.7")


@pytest.fixture(autouse=True)
def skip_odoo_prereleases(supported_odoo_version: float, request):
Expand Down Expand Up @@ -147,13 +146,31 @@ def versionless_odoo_autoskip(request):
pytest.skip("version-independent test in old versioned odoo test session")


@pytest.fixture(params=ALL_TRAEFIK_VERSIONS)
@pytest.fixture(params=TRAEFIK_VERSION)
def traefik_host(request):
"""Fixture to indicate where to find a running traefik instance."""
docker = DockerClient()
if request.param == "latest" or version.parse(request.param) >= version.parse("2"):
if request.param == "3":
traefik_container = docker.run(
"traefik:v3.0",
detach=True,
privileged=True,
networks=["inverseproxy_shared"],
volumes=[("/var/run/docker.sock", "/var/run/docker.sock", "ro")],
command=[
"--accessLog=true",
"--entryPoints.web-alt.address=:8080",
"--entryPoints.web-insecure.address=:80",
"--entryPoints.web-main.address=:443",
"--log.level=debug",
"--providers.docker.exposedByDefault=false",
"--providers.docker.network=inverseproxy_shared",
"--providers.docker=true",
],
)
elif request.param == "2":
traefik_container = docker.run(
f"traefik:{request.param}",
"traefik:v2.4",
detach=True,
privileged=True,
networks=["inverseproxy_shared"],
Expand All @@ -171,7 +188,7 @@ def traefik_host(request):
)
else:
traefik_container = docker.run(
f"traefik:{request.param}",
"traefik:v1.7",
detach=True,
privileged=True,
networks=["inverseproxy_shared"],
Expand Down
52 changes: 30 additions & 22 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_multiple_domains(
base_path = f"{base_domain}/web/login"
# XXX Remove traefik1 specific stuff some day
is_traefik1 = version.parse(traefik_host["traefik_version"]) < version.parse("2")
is_traefik3 = version.parse(traefik_host["traefik_version"]) >= version.parse("3")
data = {
"odoo_listdb": True,
"odoo_version": supported_odoo_version,
Expand Down Expand Up @@ -66,6 +67,8 @@ def test_multiple_domains(
if supported_odoo_version < 16:
data["postgres_version"] = 13
dc = DockerClient(compose_files=[f"{environment}.yaml"])
# Guarda la configuración en una variable como una cadena JSON
# docker_compose_config_json = json.dumps(docker_compose_config, indent=2)
with local.cwd(tmp_path):
run_copy(
src_path=str(cloned_template),
Expand Down Expand Up @@ -117,16 +120,19 @@ def test_multiple_domains(
)
else:
# main0, no TLS
response = requests.get(f"http://main0.{base_path}")
assert response.ok
assert response.url == f"http://main0.{base_path}"
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# alt0 and alt1, no TLS
for alt_num in range(2):
response = requests.get(f"http://alt{alt_num}.main0.{base_path}")
if not is_traefik3:
response = requests.get(f"http://main0.{base_path}")
assert response.ok
assert response.url == f"http://main0.{base_path}"
assert response.history[0].status_code == 302
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# alt0 and alt1, no TLS
for alt_num in range(2):
response = requests.get(
f"http://alt{alt_num}.main0.{base_path}"
)
assert response.ok
assert response.url == f"http://main0.{base_path}"
assert response.history[0].status_code == 302
# main2 serves https on port 80; returns a 404 from Odoo (not from
# Traefik) without HTTPS redirection
bad_response = requests.get(
Expand Down Expand Up @@ -161,21 +167,23 @@ def test_multiple_domains(
if is_traefik1
else f"https://main1.{base_path}"
)
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# alt0 and alt1, with self-signed TLS
for alt_num in range(2):
response = requests.get(
f"http://alt{alt_num}.main1.{base_domain}/web/database/selector",
verify=False,
)
assert response.ok
assert (
response.url == f"https://main1.{base_domain}/web/database/selector"
)
if not is_traefik3:
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# Search for a response in the chain with the 301 return code
# as several will be made during the redirection
assert filter(lambda r: r.status_code == 301, response.history)
# alt0 and alt1, with self-signed TLS
for alt_num in range(2):
response = requests.get(
f"http://alt{alt_num}.main1.{base_domain}/web/database/selector",
verify=False,
)
assert response.ok
assert (
response.url
== f"https://main1.{base_domain}/web/database/selector"
)
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# Search for a response in the chain with the 301 return code
# as several will be made during the redirection
assert filter(lambda r: r.status_code == 301, response.history)
# missing, which fails with Traefik 404, both with and without TLS
bad_response = requests.get(
f"http://missing.{base_path}", verify=not is_traefik1
Expand Down

0 comments on commit 5fd1793

Please sign in to comment.