diff --git a/tests/e2e/test_provider_ldap.py b/tests/e2e/test_provider_ldap.py index 7e088d53b..a33223390 100644 --- a/tests/e2e/test_provider_ldap.py +++ b/tests/e2e/test_provider_ldap.py @@ -15,14 +15,7 @@ from authentik.flows.models import Flow from authentik.outposts.managed import MANAGED_OUTPOST from authentik.outposts.models import Outpost, OutpostType from authentik.providers.ldap.models import LDAPProvider -from tests.e2e.utils import ( - USER, - SeleniumTestCase, - apply_migration, - get_docker_tag, - object_manager, - retry, -) +from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, object_manager, retry @skipUnless(platform.startswith("linux"), "requires local docker") @@ -40,7 +33,7 @@ class TestProviderLDAP(SeleniumTestCase): """Start ldap container based on outpost created""" client: DockerClient = from_env() container = client.containers.run( - image=f"beryju.org/authentik/outpost-ldap:{get_docker_tag()}", + image=self.get_container_image("beryju.org/authentik/outpost-ldap"), detach=True, network_mode="host", auto_remove=True, diff --git a/tests/e2e/test_provider_proxy.py b/tests/e2e/test_provider_proxy.py index 5a9b25fde..4bc18a14a 100644 --- a/tests/e2e/test_provider_proxy.py +++ b/tests/e2e/test_provider_proxy.py @@ -16,14 +16,7 @@ from authentik.flows.models import Flow from authentik.outposts.models import DockerServiceConnection, Outpost, OutpostConfig, OutpostType from authentik.outposts.tasks import outpost_local_connection from authentik.providers.proxy.models import ProxyProvider -from tests.e2e.utils import ( - USER, - SeleniumTestCase, - apply_migration, - get_docker_tag, - object_manager, - retry, -) +from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, object_manager, retry @skipUnless(platform.startswith("linux"), "requires local docker") @@ -49,7 +42,7 @@ class TestProviderProxy(SeleniumTestCase): """Start proxy container based on outpost created""" client: DockerClient = from_env() container = client.containers.run( - image=f"beryju.org/authentik/outpost-proxy:{get_docker_tag()}", + image=self.get_container_image("beryju.org/authentik/outpost-proxy"), detach=True, network_mode="host", auto_remove=True, diff --git a/tests/e2e/utils.py b/tests/e2e/utils.py index 45418ba73..e548d4398 100644 --- a/tests/e2e/utils.py +++ b/tests/e2e/utils.py @@ -14,6 +14,7 @@ from django.db.migrations.operations.special import RunPython from django.test.testcases import TransactionTestCase from django.urls import reverse from docker import DockerClient, from_env +from docker.errors import DockerException from docker.models.containers import Container from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException @@ -66,9 +67,20 @@ class SeleniumTestCase(StaticLiveServerTestCase): if specs := self.get_container_specs(): self.container = self._start_container(specs) + def get_container_image(self, base: str) -> str: + """Try to pull docker image based on git branch, fallback to master if not found.""" + client: DockerClient = from_env() + image = f"{base}:gh-master" + try: + branch_image = f"{base}:{get_docker_tag()}" + client.images.pull(branch_image) + return branch_image + except DockerException: + client.images.pull(image) + return image + def _start_container(self, specs: dict[str, Any]) -> Container: client: DockerClient = from_env() - client.images.pull(specs["image"]) container = client.containers.run(**specs) if "healthcheck" not in specs: return container