tests/e2e: fix more tests, cleanup

This commit is contained in:
Jens Langhammer 2021-02-27 22:57:15 +01:00
parent cbb0681f95
commit 088e0e736a
6 changed files with 52 additions and 16 deletions

View File

@ -1,6 +1,5 @@
"""test stage setup flows (password change)""" """test stage setup flows (password change)"""
from sys import platform from sys import platform
from time import sleep
from unittest.case import skipUnless from unittest.case import skipUnless
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By

View File

@ -17,7 +17,7 @@ from authentik.providers.oauth2.generators import (
generate_client_secret, generate_client_secret,
) )
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider 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") @skipUnless(platform.startswith("linux"), "requires local docker")
@ -61,6 +61,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
} }
@retry() @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): def test_authorization_consent_implied(self):
"""test OAuth Provider flow (default authorization flow with implied consent)""" """test OAuth Provider flow (default authorization flow with implied consent)"""
# Bootstrap all needed objects # Bootstrap all needed objects
@ -111,6 +114,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
) )
@retry() @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): def test_authorization_consent_explicit(self):
"""test OAuth Provider flow (default authorization flow with explicit consent)""" """test OAuth Provider flow (default authorization flow with explicit consent)"""
# Bootstrap all needed objects # Bootstrap all needed objects
@ -135,17 +141,21 @@ class TestProviderOAuth2Github(SeleniumTestCase):
self.driver.find_element(By.CLASS_NAME, "btn-service--github").click() self.driver.find_element(By.CLASS_NAME, "btn-service--github").click()
self.login() 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, app.name,
self.driver.find_element(By.ID, "application-name").text, consent_stage.find_element(By.CSS_SELECTOR, "#header-text").text,
) )
self.assertEqual( self.assertEqual(
"GitHub Compatibility: Access you Email addresses", "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, By.CSS_SELECTOR,
("[type=submit]"), ("[type=submit]"),
).click() ).click()
@ -176,6 +186,9 @@ class TestProviderOAuth2Github(SeleniumTestCase):
) )
@retry() @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): def test_denied(self):
"""test OAuth Provider flow (default authorization flow, denied)""" """test OAuth Provider flow (default authorization flow, denied)"""
# Bootstrap all needed objects # Bootstrap all needed objects

View File

@ -24,7 +24,7 @@ from authentik.providers.oauth2.generators import (
generate_client_secret, generate_client_secret,
) )
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider, ScopeMapping 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() LOGGER = get_logger()
APPLICATION_SLUG = "grafana" APPLICATION_SLUG = "grafana"
@ -75,6 +75,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
} }
@retry() @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): def test_redirect_uri_error(self):
"""test OpenID Provider flow (invalid redirect URI, check error message)""" """test OpenID Provider flow (invalid redirect URI, check error message)"""
sleep(1) sleep(1)
@ -112,6 +115,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
) )
@retry() @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): def test_authorization_consent_implied(self):
"""test OpenID Provider flow (default authorization flow with implied consent)""" """test OpenID Provider flow (default authorization flow with implied consent)"""
sleep(1) sleep(1)
@ -169,6 +175,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
) )
@retry() @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): def test_authorization_logout(self):
"""test OpenID Provider flow with logout""" """test OpenID Provider flow with logout"""
sleep(1) sleep(1)
@ -234,6 +243,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
self.driver.find_element(By.ID, "logout").click() self.driver.find_element(By.ID, "logout").click()
@retry() @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): def test_authorization_consent_explicit(self):
"""test OpenID Provider flow (default authorization flow with explicit consent)""" """test OpenID Provider flow (default authorization flow with explicit consent)"""
sleep(1) sleep(1)
@ -303,6 +315,9 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
) )
@retry() @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): def test_authorization_denied(self):
"""test OpenID Provider flow (default authorization with access deny)""" """test OpenID Provider flow (default authorization with access deny)"""
sleep(1) sleep(1)

View File

@ -26,7 +26,7 @@ from authentik.providers.oauth2.generators import (
generate_client_secret, generate_client_secret,
) )
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider, ScopeMapping 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() LOGGER = get_logger()
@ -70,6 +70,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
sleep(1) sleep(1)
@retry() @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): def test_redirect_uri_error(self):
"""test OpenID Provider flow (invalid redirect URI, check error message)""" """test OpenID Provider flow (invalid redirect URI, check error message)"""
sleep(1) sleep(1)
@ -107,6 +110,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
) )
@retry() @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): def test_authorization_consent_implied(self):
"""test OpenID Provider flow (default authorization flow with implied consent)""" """test OpenID Provider flow (default authorization flow with implied consent)"""
sleep(1) sleep(1)
@ -151,6 +157,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
self.assertEqual(body["UserInfo"]["email"], USER().email) self.assertEqual(body["UserInfo"]["email"], USER().email)
@retry() @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): def test_authorization_consent_explicit(self):
"""test OpenID Provider flow (default authorization flow with explicit consent)""" """test OpenID Provider flow (default authorization flow with explicit consent)"""
sleep(1) sleep(1)
@ -182,6 +191,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
self.driver.get("http://localhost:9009") self.driver.get("http://localhost:9009")
self.login() self.login()
sleep(9999999)
self.assertEqual( self.assertEqual(
app.name, app.name,
self.driver.find_element(By.ID, "application-name").text, self.driver.find_element(By.ID, "application-name").text,
@ -205,6 +217,9 @@ class TestProviderOAuth2OIDC(SeleniumTestCase):
self.assertEqual(body["UserInfo"]["email"], USER().email) self.assertEqual(body["UserInfo"]["email"], USER().email)
@retry() @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): def test_authorization_denied(self):
"""test OpenID Provider flow (default authorization with access deny)""" """test OpenID Provider flow (default authorization with access deny)"""
sleep(1) sleep(1)

View File

@ -108,7 +108,6 @@ class TestProviderProxyConnect(ChannelsLiveServerTestCase):
def test_proxy_connectivity(self): def test_proxy_connectivity(self):
"""Test proxy connectivity over websocket""" """Test proxy connectivity over websocket"""
AuthentikOutpostConfig.init_local_connection() AuthentikOutpostConfig.init_local_connection()
SeleniumTestCase().apply_default_data()
proxy: ProxyProvider = ProxyProvider.objects.create( proxy: ProxyProvider = ProxyProvider.objects.create(
name="proxy_provider", name="proxy_provider",
authorization_flow=Flow.objects.get( authorization_flow=Flow.objects.get(

View File

@ -1,19 +1,15 @@
"""authentik e2e testing utilities""" """authentik e2e testing utilities"""
import json import json
from functools import lru_cache, wraps 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 os import environ, makedirs
from time import sleep, time from time import sleep, time
from typing import Any, Callable, Optional from typing import Any, Callable, Optional
from django.apps import apps from django.apps import apps
from django.contrib.staticfiles.testing import StaticLiveServerTestCase 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.loader import MigrationLoader
from django.db.migrations.operations.special import RunPython from django.db.migrations.operations.special import RunPython
from django.db.utils import IntegrityError
from django.test.testcases import TransactionTestCase from django.test.testcases import TransactionTestCase
from django.urls import reverse from django.urls import reverse
from docker import DockerClient, from_env 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.api.users import UserSerializer
from authentik.core.models import User from authentik.core.models import User
from authentik.managed.manager import ObjectManager
# pylint: disable=invalid-name # pylint: disable=invalid-name