tests/e2e: don't rely DNS to get host's IP for container access
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -47,10 +47,12 @@ class TestProviderOAuth2Github(SeleniumTestCase):
|
||||
"GF_AUTH_GITHUB_AUTH_URL": self.url(
|
||||
"authentik_providers_oauth2_root:github-authorize"
|
||||
),
|
||||
"GF_AUTH_GITHUB_TOKEN_URL": self.url(
|
||||
"GF_AUTH_GITHUB_TOKEN_URL": self.host_url(
|
||||
"authentik_providers_oauth2_root:github-access-token"
|
||||
),
|
||||
"GF_AUTH_GITHUB_API_URL": self.url("authentik_providers_oauth2_root:github-user"),
|
||||
"GF_AUTH_GITHUB_API_URL": self.host_url(
|
||||
"authentik_providers_oauth2_root:github-user"
|
||||
),
|
||||
"GF_LOG_LEVEL": "debug",
|
||||
},
|
||||
)
|
||||
|
@ -53,8 +53,12 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
|
||||
"GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET": self.client_secret,
|
||||
"GF_AUTH_GENERIC_OAUTH_SCOPES": "openid email profile",
|
||||
"GF_AUTH_GENERIC_OAUTH_AUTH_URL": self.url("authentik_providers_oauth2:authorize"),
|
||||
"GF_AUTH_GENERIC_OAUTH_TOKEN_URL": self.url("authentik_providers_oauth2:token"),
|
||||
"GF_AUTH_GENERIC_OAUTH_API_URL": self.url("authentik_providers_oauth2:userinfo"),
|
||||
"GF_AUTH_GENERIC_OAUTH_TOKEN_URL": self.host_url(
|
||||
"authentik_providers_oauth2:token"
|
||||
),
|
||||
"GF_AUTH_GENERIC_OAUTH_API_URL": self.host_url(
|
||||
"authentik_providers_oauth2:userinfo"
|
||||
),
|
||||
"GF_AUTH_SIGNOUT_REDIRECT_URL": self.url(
|
||||
"authentik_providers_oauth2:end-session",
|
||||
application_slug=self.app_slug,
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from collections.abc import Callable
|
||||
from functools import lru_cache, wraps
|
||||
from os import environ
|
||||
@ -51,13 +50,6 @@ def get_docker_tag() -> str:
|
||||
return f"gh-{branch_name}"
|
||||
|
||||
|
||||
def get_local_ip() -> str:
|
||||
"""Get the local machine's IP"""
|
||||
hostname = socket.gethostname()
|
||||
ip_addr = socket.gethostbyname(hostname)
|
||||
return ip_addr
|
||||
|
||||
|
||||
class DockerTestCase(TestCase):
|
||||
"""Mixin for dealing with containers"""
|
||||
|
||||
@ -113,6 +105,9 @@ class DockerTestCase(TestCase):
|
||||
specs["network"] = self.__network.name
|
||||
specs["labels"] = self.docker_labels
|
||||
specs["detach"] = True
|
||||
specs["extra_hosts"] = {
|
||||
"host.docker.internal": "host-gateway",
|
||||
}
|
||||
if hasattr(self, "live_server_url"):
|
||||
specs.setdefault("environment", {})
|
||||
specs["environment"]["AUTHENTIK_HOST"] = self.live_server_url
|
||||
@ -155,7 +150,6 @@ class DockerTestCase(TestCase):
|
||||
class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
||||
"""StaticLiveServerTestCase which automatically creates a Webdriver instance"""
|
||||
|
||||
host = get_local_ip()
|
||||
wait_timeout: int
|
||||
user: User
|
||||
|
||||
@ -210,6 +204,15 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
||||
f"URL {self.driver.current_url} doesn't match expected URL {desired_url}",
|
||||
)
|
||||
|
||||
def host_url(self, view, query: dict | None = None, **kwargs) -> str:
|
||||
"""reverse `view` with `**kwargs` into full URL using live_server_url"""
|
||||
url = f"http://host.docker.internal:{self.server_thread.port}" + reverse(
|
||||
view, kwargs=kwargs
|
||||
)
|
||||
if query:
|
||||
return url + "?" + urlencode(query)
|
||||
return url
|
||||
|
||||
def url(self, view, query: dict | None = None, **kwargs) -> str:
|
||||
"""reverse `view` with `**kwargs` into full URL using live_server_url"""
|
||||
url = self.live_server_url + reverse(view, kwargs=kwargs)
|
||||
|
Reference in New Issue
Block a user