Compare commits
4 Commits
imports-fo
...
tests/e2e/
Author | SHA1 | Date | |
---|---|---|---|
25181d079e | |||
5b91cb5ff3 | |||
8ba5fde5ba | |||
2802deb497 |
@ -47,10 +47,12 @@ class TestProviderOAuth2Github(SeleniumTestCase):
|
|||||||
"GF_AUTH_GITHUB_AUTH_URL": self.url(
|
"GF_AUTH_GITHUB_AUTH_URL": self.url(
|
||||||
"authentik_providers_oauth2_root:github-authorize"
|
"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"
|
"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",
|
"GF_LOG_LEVEL": "debug",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -53,8 +53,12 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
|
|||||||
"GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET": self.client_secret,
|
"GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET": self.client_secret,
|
||||||
"GF_AUTH_GENERIC_OAUTH_SCOPES": "openid email profile",
|
"GF_AUTH_GENERIC_OAUTH_SCOPES": "openid email profile",
|
||||||
"GF_AUTH_GENERIC_OAUTH_AUTH_URL": self.url("authentik_providers_oauth2:authorize"),
|
"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_TOKEN_URL": self.host_url(
|
||||||
"GF_AUTH_GENERIC_OAUTH_API_URL": self.url("authentik_providers_oauth2:userinfo"),
|
"authentik_providers_oauth2:token"
|
||||||
|
),
|
||||||
|
"GF_AUTH_GENERIC_OAUTH_API_URL": self.host_url(
|
||||||
|
"authentik_providers_oauth2:userinfo"
|
||||||
|
),
|
||||||
"GF_AUTH_SIGNOUT_REDIRECT_URL": self.url(
|
"GF_AUTH_SIGNOUT_REDIRECT_URL": self.url(
|
||||||
"authentik_providers_oauth2:end-session",
|
"authentik_providers_oauth2:end-session",
|
||||||
application_slug=self.app_slug,
|
application_slug=self.app_slug,
|
||||||
|
@ -42,7 +42,9 @@ class TestSourceSCIM(SeleniumTestCase):
|
|||||||
test_launch = session.post(
|
test_launch = session.post(
|
||||||
"http://localhost:8080/test/run",
|
"http://localhost:8080/test/run",
|
||||||
data={
|
data={
|
||||||
"endPoint": self.live_server_url + f"/source/scim/{source.slug}/v2",
|
"endPoint": self.host_url(
|
||||||
|
"authentik_sources_scim:v2-root", source_slug=source.slug
|
||||||
|
),
|
||||||
"username": "foo",
|
"username": "foo",
|
||||||
"password": source.token.key,
|
"password": source.token.key,
|
||||||
"jwtToken": None,
|
"jwtToken": None,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from functools import lru_cache, wraps
|
from functools import lru_cache, wraps
|
||||||
from os import environ
|
from os import environ
|
||||||
@ -36,8 +35,8 @@ from authentik.core.models import User
|
|||||||
from authentik.core.tests.utils import create_test_admin_user
|
from authentik.core.tests.utils import create_test_admin_user
|
||||||
from authentik.lib.generators import generate_id
|
from authentik.lib.generators import generate_id
|
||||||
|
|
||||||
RETRIES = int(environ.get("RETRIES", "3"))
|
|
||||||
IS_CI = "CI" in environ
|
IS_CI = "CI" in environ
|
||||||
|
RETRIES = int(environ.get("RETRIES", "3")) if IS_CI else 1
|
||||||
|
|
||||||
|
|
||||||
def get_docker_tag() -> str:
|
def get_docker_tag() -> str:
|
||||||
@ -51,13 +50,6 @@ def get_docker_tag() -> str:
|
|||||||
return f"gh-{branch_name}"
|
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):
|
class DockerTestCase(TestCase):
|
||||||
"""Mixin for dealing with containers"""
|
"""Mixin for dealing with containers"""
|
||||||
|
|
||||||
@ -113,6 +105,9 @@ class DockerTestCase(TestCase):
|
|||||||
specs["network"] = self.__network.name
|
specs["network"] = self.__network.name
|
||||||
specs["labels"] = self.docker_labels
|
specs["labels"] = self.docker_labels
|
||||||
specs["detach"] = True
|
specs["detach"] = True
|
||||||
|
specs["extra_hosts"] = {
|
||||||
|
"host.docker.internal": "host-gateway",
|
||||||
|
}
|
||||||
if hasattr(self, "live_server_url"):
|
if hasattr(self, "live_server_url"):
|
||||||
specs.setdefault("environment", {})
|
specs.setdefault("environment", {})
|
||||||
specs["environment"]["AUTHENTIK_HOST"] = self.live_server_url
|
specs["environment"]["AUTHENTIK_HOST"] = self.live_server_url
|
||||||
@ -155,7 +150,7 @@ class DockerTestCase(TestCase):
|
|||||||
class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
||||||
"""StaticLiveServerTestCase which automatically creates a Webdriver instance"""
|
"""StaticLiveServerTestCase which automatically creates a Webdriver instance"""
|
||||||
|
|
||||||
host = get_local_ip()
|
host = "0.0.0.0" # nosec Required for containers to reach us directly on the host
|
||||||
wait_timeout: int
|
wait_timeout: int
|
||||||
user: User
|
user: User
|
||||||
|
|
||||||
@ -210,6 +205,15 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
|||||||
f"URL {self.driver.current_url} doesn't match expected URL {desired_url}",
|
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:
|
def url(self, view, query: dict | None = None, **kwargs) -> str:
|
||||||
"""reverse `view` with `**kwargs` into full URL using live_server_url"""
|
"""reverse `view` with `**kwargs` into full URL using live_server_url"""
|
||||||
url = self.live_server_url + reverse(view, kwargs=kwargs)
|
url = self.live_server_url + reverse(view, kwargs=kwargs)
|
||||||
|
Reference in New Issue
Block a user