From 088e0e736a12e2af0dec9e8f2168e752a096e1ed Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 27 Feb 2021 22:57:15 +0100 Subject: [PATCH] tests/e2e: fix more tests, cleanup --- tests/e2e/test_flows_stage_setup.py | 1 - tests/e2e/test_provider_oauth2_github.py | 25 +++++++++++++++++------ tests/e2e/test_provider_oauth2_grafana.py | 17 ++++++++++++++- tests/e2e/test_provider_oauth2_oidc.py | 17 ++++++++++++++- tests/e2e/test_provider_proxy.py | 1 - tests/e2e/utils.py | 7 +------ 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/tests/e2e/test_flows_stage_setup.py b/tests/e2e/test_flows_stage_setup.py index 2de1054b6..b53aead6a 100644 --- a/tests/e2e/test_flows_stage_setup.py +++ b/tests/e2e/test_flows_stage_setup.py @@ -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 diff --git a/tests/e2e/test_provider_oauth2_github.py b/tests/e2e/test_provider_oauth2_github.py index f762252aa..783744bd9 100644 --- a/tests/e2e/test_provider_oauth2_github.py +++ b/tests/e2e/test_provider_oauth2_github.py @@ -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 diff --git a/tests/e2e/test_provider_oauth2_grafana.py b/tests/e2e/test_provider_oauth2_grafana.py index 24cdbd57b..85c036c36 100644 --- a/tests/e2e/test_provider_oauth2_grafana.py +++ b/tests/e2e/test_provider_oauth2_grafana.py @@ -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) diff --git a/tests/e2e/test_provider_oauth2_oidc.py b/tests/e2e/test_provider_oauth2_oidc.py index 52b590730..f580316f6 100644 --- a/tests/e2e/test_provider_oauth2_oidc.py +++ b/tests/e2e/test_provider_oauth2_oidc.py @@ -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) diff --git a/tests/e2e/test_provider_proxy.py b/tests/e2e/test_provider_proxy.py index 56d1e8b5d..daec31500 100644 --- a/tests/e2e/test_provider_proxy.py +++ b/tests/e2e/test_provider_proxy.py @@ -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( diff --git a/tests/e2e/utils.py b/tests/e2e/utils.py index 32b36fafe..3e9287453 100644 --- a/tests/e2e/utils.py +++ b/tests/e2e/utils.py @@ -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