From bfa0c46588ef8db1d07c12b83a8ae680671057c6 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 30 Mar 2021 11:05:31 +0200 Subject: [PATCH] tests/e2e: fix source tests Signed-off-by: Jens Langhammer --- tests/e2e/test_source_oauth.py | 38 +++++----------------------------- tests/e2e/test_source_saml.py | 23 ++++++++++++-------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/tests/e2e/test_source_oauth.py b/tests/e2e/test_source_oauth.py index 9f1ca18af..c3646a7f7 100644 --- a/tests/e2e/test_source_oauth.py +++ b/tests/e2e/test_source_oauth.py @@ -15,6 +15,7 @@ from selenium.webdriver.support.wait import WebDriverWait from structlog.stdlib import get_logger from yaml import safe_dump +from authentik.core.models import User from authentik.flows.models import Flow from authentik.providers.oauth2.generators import ( generate_client_id, @@ -162,17 +163,7 @@ class TestSourceOAuth2(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - self.assertEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), "foo" - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_name").get_attribute("value"), - "admin", - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_email").get_attribute("value"), - "admin@example.com", - ) + self.assert_user(User(username="foo", name="admin", email="admin@example.com")) @retry() @apply_migration("authentik_core", "0003_default_user") @@ -257,17 +248,7 @@ class TestSourceOAuth2(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - self.assertEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), "foo" - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_name").get_attribute("value"), - "admin", - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_email").get_attribute("value"), - "admin@example.com", - ) + self.assert_user(User(username="foo", name="admin", email="admin@example.com")) @skipUnless(platform.startswith("linux"), "requires local docker") @@ -361,15 +342,6 @@ class TestSourceOAuth1(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - self.assertEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), - "example-user", - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_name").get_attribute("value"), - "test name", - ) - self.assertEqual( - self.driver.find_element(By.ID, "id_email").get_attribute("value"), - "foo@example.com", + self.assert_user( + User(username="example-user", name="test name", email="foo@example.com") ) diff --git a/tests/e2e/test_source_saml.py b/tests/e2e/test_source_saml.py index cdd1964d1..8fbfbfccd 100644 --- a/tests/e2e/test_source_saml.py +++ b/tests/e2e/test_source_saml.py @@ -5,12 +5,14 @@ from typing import Any, Optional from unittest.case import skipUnless from docker.types import Healthcheck +from guardian.utils import get_anonymous_user from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support.wait import WebDriverWait from structlog.stdlib import get_logger +from authentik.core.models import User from authentik.crypto.models import CertificateKeyPair from authentik.flows.models import Flow from authentik.sources.saml.models import SAMLBindingTypes, SAMLSource @@ -155,9 +157,10 @@ class TestSourceSAML(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - # Wait until we've loaded the user info page - self.assertNotEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), "" + self.assert_user( + User.objects.exclude(username="akadmin") + .exclude(pk=get_anonymous_user().pk) + .first() ) @retry() @@ -235,9 +238,10 @@ class TestSourceSAML(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - # Wait until we've loaded the user info page - self.assertNotEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), "" + self.assert_user( + User.objects.exclude(username="akadmin") + .exclude(pk=get_anonymous_user().pk) + .first() ) @retry() @@ -302,7 +306,8 @@ class TestSourceSAML(SeleniumTestCase): self.wait_for_url(self.if_admin_url("/library")) self.driver.get(self.if_admin_url("/user")) - # Wait until we've loaded the user info page - self.assertNotEqual( - self.driver.find_element(By.ID, "id_username").get_attribute("value"), "" + self.assert_user( + User.objects.exclude(username="akadmin") + .exclude(pk=get_anonymous_user().pk) + .first() )