tests/e2e: fix more tests, cleanup
This commit is contained in:
		@ -1,6 +1,5 @@
 | 
			
		||||
"""test stage setup flows (password change)"""
 | 
			
		||||
from sys import platform
 | 
			
		||||
from time import sleep
 | 
			
		||||
from unittest.case import skipUnless
 | 
			
		||||
 | 
			
		||||
from selenium.webdriver.common.by import By
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ from authentik.providers.oauth2.generators import (
 | 
			
		||||
    generate_client_secret,
 | 
			
		||||
)
 | 
			
		||||
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, retry
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, retry
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@skipUnless(platform.startswith("linux"), "requires local docker")
 | 
			
		||||
@ -61,6 +61,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_implied(self):
 | 
			
		||||
        """test OAuth Provider flow (default authorization flow with implied consent)"""
 | 
			
		||||
        # Bootstrap all needed objects
 | 
			
		||||
@ -111,6 +114,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_explicit(self):
 | 
			
		||||
        """test OAuth Provider flow (default authorization flow with explicit consent)"""
 | 
			
		||||
        # Bootstrap all needed objects
 | 
			
		||||
@ -135,17 +141,21 @@ class TestProviderOAuth2Github(SeleniumTestCase):
 | 
			
		||||
        self.driver.find_element(By.CLASS_NAME, "btn-service--github").click()
 | 
			
		||||
        self.login()
 | 
			
		||||
 | 
			
		||||
        sleep(1)
 | 
			
		||||
        sleep(3)
 | 
			
		||||
        self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "ak-flow-executor")))
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
        flow_executor = self.get_shadow_root("ak-flow-executor")
 | 
			
		||||
        consent_stage = self.get_shadow_root("ak-stage-consent", flow_executor)
 | 
			
		||||
 | 
			
		||||
        self.assertIn(
 | 
			
		||||
            app.name,
 | 
			
		||||
            self.driver.find_element(By.ID, "application-name").text,
 | 
			
		||||
            consent_stage.find_element(By.CSS_SELECTOR, "#header-text").text,
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            "GitHub Compatibility: Access you Email addresses",
 | 
			
		||||
            self.driver.find_element(By.ID, "permission-user:email").text,
 | 
			
		||||
            consent_stage.find_element(By.CSS_SELECTOR, "[data-permission-code='user:email']").text,
 | 
			
		||||
        )
 | 
			
		||||
        self.driver.find_element(
 | 
			
		||||
        consent_stage.find_element(
 | 
			
		||||
            By.CSS_SELECTOR,
 | 
			
		||||
            ("[type=submit]"),
 | 
			
		||||
        ).click()
 | 
			
		||||
@ -176,6 +186,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_denied(self):
 | 
			
		||||
        """test OAuth Provider flow (default authorization flow, denied)"""
 | 
			
		||||
        # Bootstrap all needed objects
 | 
			
		||||
 | 
			
		||||
@ -24,7 +24,7 @@ from authentik.providers.oauth2.generators import (
 | 
			
		||||
    generate_client_secret,
 | 
			
		||||
)
 | 
			
		||||
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider, ScopeMapping
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, retry
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, retry
 | 
			
		||||
 | 
			
		||||
LOGGER = get_logger()
 | 
			
		||||
APPLICATION_SLUG = "grafana"
 | 
			
		||||
@ -75,6 +75,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_redirect_uri_error(self):
 | 
			
		||||
        """test OpenID Provider flow (invalid redirect URI, check error message)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -112,6 +115,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_implied(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization flow with implied consent)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -169,6 +175,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_logout(self):
 | 
			
		||||
        """test OpenID Provider flow with logout"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -234,6 +243,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
 | 
			
		||||
        self.driver.find_element(By.ID, "logout").click()
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_explicit(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization flow with explicit consent)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -303,6 +315,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_denied(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization with access deny)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ from authentik.providers.oauth2.generators import (
 | 
			
		||||
    generate_client_secret,
 | 
			
		||||
)
 | 
			
		||||
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider, ScopeMapping
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, retry
 | 
			
		||||
from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, retry
 | 
			
		||||
 | 
			
		||||
LOGGER = get_logger()
 | 
			
		||||
 | 
			
		||||
@ -70,6 +70,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
 | 
			
		||||
            sleep(1)
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_redirect_uri_error(self):
 | 
			
		||||
        """test OpenID Provider flow (invalid redirect URI, check error message)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -107,6 +110,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_implied(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization flow with implied consent)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -151,6 +157,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
 | 
			
		||||
        self.assertEqual(body["UserInfo"]["email"], USER().email)
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_consent_explicit(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization flow with explicit consent)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
@ -182,6 +191,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
 | 
			
		||||
 | 
			
		||||
        self.driver.get("http://localhost:9009")
 | 
			
		||||
        self.login()
 | 
			
		||||
 | 
			
		||||
        sleep(9999999)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            app.name,
 | 
			
		||||
            self.driver.find_element(By.ID, "application-name").text,
 | 
			
		||||
@ -205,6 +217,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
 | 
			
		||||
        self.assertEqual(body["UserInfo"]["email"], USER().email)
 | 
			
		||||
 | 
			
		||||
    @retry()
 | 
			
		||||
    @apply_migration("authentik_core", "0003_default_user")
 | 
			
		||||
    @apply_migration("authentik_flows", "0008_default_flows")
 | 
			
		||||
    @apply_migration("authentik_flows", "0010_provider_flows")
 | 
			
		||||
    def test_authorization_denied(self):
 | 
			
		||||
        """test OpenID Provider flow (default authorization with access deny)"""
 | 
			
		||||
        sleep(1)
 | 
			
		||||
 | 
			
		||||
@ -108,7 +108,6 @@ class TestProviderProxyConnect(ChannelsLiveServerTestCase):
 | 
			
		||||
    def test_proxy_connectivity(self):
 | 
			
		||||
        """Test proxy connectivity over websocket"""
 | 
			
		||||
        AuthentikOutpostConfig.init_local_connection()
 | 
			
		||||
        SeleniumTestCase().apply_default_data()
 | 
			
		||||
        proxy: ProxyProvider = ProxyProvider.objects.create(
 | 
			
		||||
            name="proxy_provider",
 | 
			
		||||
            authorization_flow=Flow.objects.get(
 | 
			
		||||
 | 
			
		||||
@ -1,19 +1,15 @@
 | 
			
		||||
"""authentik e2e testing utilities"""
 | 
			
		||||
import json
 | 
			
		||||
from functools import lru_cache, wraps
 | 
			
		||||
from glob import glob
 | 
			
		||||
from importlib.util import module_from_spec, spec_from_file_location
 | 
			
		||||
from inspect import getmembers, isfunction
 | 
			
		||||
from os import environ, makedirs
 | 
			
		||||
from time import sleep, time
 | 
			
		||||
from typing import Any, Callable, Optional
 | 
			
		||||
 | 
			
		||||
from django.apps import apps
 | 
			
		||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
 | 
			
		||||
from django.db import connection, transaction
 | 
			
		||||
from django.db import connection
 | 
			
		||||
from django.db.migrations.loader import MigrationLoader
 | 
			
		||||
from django.db.migrations.operations.special import RunPython
 | 
			
		||||
from django.db.utils import IntegrityError
 | 
			
		||||
from django.test.testcases import TransactionTestCase
 | 
			
		||||
from django.urls import reverse
 | 
			
		||||
from docker import DockerClient, from_env
 | 
			
		||||
@ -34,7 +30,6 @@ from structlog.stdlib import get_logger
 | 
			
		||||
 | 
			
		||||
from authentik.core.api.users import UserSerializer
 | 
			
		||||
from authentik.core.models import User
 | 
			
		||||
from authentik.managed.manager import ObjectManager
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# pylint: disable=invalid-name
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user