tests/e2e: fix URLs, use self.login()

This commit is contained in:
Jens Langhammer 2021-02-27 18:48:41 +01:00
parent 402afa1e85
commit 380786bfde
7 changed files with 16 additions and 52 deletions

View File

@ -1,10 +1,5 @@
all: lint-fix lint coverage gen all: lint-fix lint coverage gen
test-full:
coverage run manage.py test --failfast -v 3 .
coverage html
coverage report
test-integration: test-integration:
k3d cluster create || exit 0 k3d cluster create || exit 0
k3d kubeconfig write -o ~/.kube/config --overwrite k3d kubeconfig write -o ~/.kube/config --overwrite

View File

@ -2,9 +2,6 @@
from sys import platform from sys import platform
from unittest.case import skipUnless from unittest.case import skipUnless
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from tests.e2e.utils import USER, SeleniumTestCase, retry from tests.e2e.utils import USER, SeleniumTestCase, retry
@ -16,10 +13,6 @@ class TestFlowsLogin(SeleniumTestCase):
def test_login(self): def test_login(self):
"""test default login flow""" """test default login flow"""
self.driver.get(f"{self.live_server_url}/flows/default-authentication-flow/") self.driver.get(f"{self.live_server_url}/flows/default-authentication-flow/")
self.driver.find_element(By.ID, "id_uid_field").click() self.login()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username) self.wait_for_url(self.shell_url("/library"))
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
self.wait_for_url(self.shell_url("authentik_core:overview"))
self.assert_user(USER()) self.assert_user(USER())

View File

@ -38,7 +38,7 @@ class TestFlowsStageSetup(SeleniumTestCase):
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER) self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username) self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER) self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get( self.driver.get(
self.url( self.url(
@ -51,7 +51,7 @@ class TestFlowsStageSetup(SeleniumTestCase):
self.driver.find_element(By.ID, "id_password_repeat").send_keys(new_password) self.driver.find_element(By.ID, "id_password_repeat").send_keys(new_password)
self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click() self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
# Because USER() is cached, we need to get the user manually here # Because USER() is cached, we need to get the user manually here
user = User.objects.get(username=USER().username) user = User.objects.get(username=USER().username)
self.assertTrue(user.check_password(new_password)) self.assertTrue(user.check_password(new_password))

View File

@ -9,7 +9,6 @@ from channels.testing import ChannelsLiveServerTestCase
from docker.client import DockerClient, from_env from docker.client import DockerClient, from_env
from docker.models.containers import Container from docker.models.containers import Container
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from authentik import __version__ from authentik import __version__
from authentik.core.models import Application from authentik.core.models import Application
@ -22,7 +21,7 @@ from authentik.outposts.models import (
OutpostType, OutpostType,
) )
from authentik.providers.proxy.models import ProxyProvider from authentik.providers.proxy.models import ProxyProvider
from tests.e2e.utils import USER, SeleniumTestCase, retry from tests.e2e.utils import SeleniumTestCase, retry
@skipUnless(platform.startswith("linux"), "requires local docker") @skipUnless(platform.startswith("linux"), "requires local docker")
@ -94,13 +93,7 @@ class TestProviderProxy(SeleniumTestCase):
sleep(0.5) sleep(0.5)
self.driver.get("http://localhost:4180") self.driver.get("http://localhost:4180")
self.login()
self.driver.find_element(By.ID, "id_uid_field").click()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username)
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
sleep(1) sleep(1)
full_body_text = self.driver.find_element(By.CSS_SELECTOR, "pre").text full_body_text = self.driver.find_element(By.CSS_SELECTOR, "pre").text

View File

@ -8,7 +8,6 @@ from docker import DockerClient, from_env
from docker.models.containers import Container from docker.models.containers import Container
from docker.types import Healthcheck from docker.types import Healthcheck
from selenium.webdriver.common.by import By 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 import expected_conditions as ec
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
@ -90,11 +89,7 @@ class TestProviderSAML(SeleniumTestCase):
) )
self.container = self.setup_client(provider) self.container = self.setup_client(provider)
self.driver.get("http://localhost:9009") self.driver.get("http://localhost:9009")
self.driver.find_element(By.ID, "id_uid_field").click() self.login()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username)
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
self.wait_for_url("http://localhost:9009/") self.wait_for_url("http://localhost:9009/")
body = loads(self.driver.find_element(By.CSS_SELECTOR, "pre").text) body = loads(self.driver.find_element(By.CSS_SELECTOR, "pre").text)
@ -153,11 +148,7 @@ class TestProviderSAML(SeleniumTestCase):
) )
self.container = self.setup_client(provider) self.container = self.setup_client(provider)
self.driver.get("http://localhost:9009") self.driver.get("http://localhost:9009")
self.driver.find_element(By.ID, "id_uid_field").click() self.login()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username)
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
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,
@ -227,11 +218,7 @@ class TestProviderSAML(SeleniumTestCase):
application_slug=provider.application.slug, application_slug=provider.application.slug,
) )
) )
self.driver.find_element(By.ID, "id_uid_field").click() self.login()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username)
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
sleep(1) sleep(1)
self.wait_for_url("http://localhost:9009/") self.wait_for_url("http://localhost:9009/")
@ -295,11 +282,7 @@ class TestProviderSAML(SeleniumTestCase):
PolicyBinding.objects.create(target=app, policy=negative_policy, order=0) PolicyBinding.objects.create(target=app, policy=negative_policy, order=0)
self.container = self.setup_client(provider) self.container = self.setup_client(provider)
self.driver.get("http://localhost:9009/") self.driver.get("http://localhost:9009/")
self.driver.find_element(By.ID, "id_uid_field").click() self.login()
self.driver.find_element(By.ID, "id_uid_field").send_keys(USER().username)
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
self.wait.until( self.wait.until(
ec.presence_of_element_located((By.CSS_SELECTOR, "header > h1")) ec.presence_of_element_located((By.CSS_SELECTOR, "header > h1"))

View File

@ -141,7 +141,7 @@ class TestSourceOAuth2(SeleniumTestCase):
self.driver.find_element(By.NAME, "username").send_keys(Keys.ENTER) self.driver.find_element(By.NAME, "username").send_keys(Keys.ENTER)
# Wait until we've logged in # Wait until we've logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
self.assertEqual( self.assertEqual(
@ -223,7 +223,7 @@ class TestSourceOAuth2(SeleniumTestCase):
self.driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click() self.driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click()
# Wait until we've logged in # Wait until we've logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
self.assertEqual( self.assertEqual(
@ -316,7 +316,7 @@ class TestSourceOAuth1(SeleniumTestCase):
# Wait until we've loaded the user info page # Wait until we've loaded the user info page
sleep(2) sleep(2)
# Wait until we've logged in # Wait until we've logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
self.assertEqual( self.assertEqual(

View File

@ -133,7 +133,7 @@ class TestSourceSAML(SeleniumTestCase):
self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER) self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER)
# Wait until we're logged in # Wait until we're logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
# Wait until we've loaded the user info page # Wait until we've loaded the user info page
@ -184,7 +184,7 @@ class TestSourceSAML(SeleniumTestCase):
self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER) self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER)
# Wait until we're logged in # Wait until we're logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
# Wait until we've loaded the user info page # Wait until we've loaded the user info page
@ -233,7 +233,7 @@ class TestSourceSAML(SeleniumTestCase):
self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER) self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER)
# Wait until we're logged in # Wait until we're logged in
self.wait_for_url(self.shell_url("authentik_core:overview")) self.wait_for_url(self.shell_url("/library"))
self.driver.get(self.url("authentik_core:user-details")) self.driver.get(self.url("authentik_core:user-details"))
# Wait until we've loaded the user info page # Wait until we've loaded the user info page