2020-06-29 19:39:04 +00:00
|
|
|
"""test stage setup flows (password change)"""
|
2020-09-11 21:21:11 +00:00
|
|
|
from sys import platform
|
|
|
|
from unittest.case import skipUnless
|
2020-06-29 19:39:04 +00:00
|
|
|
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
from authentik.core.models import User
|
|
|
|
from authentik.flows.models import Flow, FlowDesignation
|
|
|
|
from authentik.providers.oauth2.generators import generate_client_secret
|
|
|
|
from authentik.stages.password.models import PasswordStage
|
2021-02-27 21:32:48 +00:00
|
|
|
from tests.e2e.utils import USER, SeleniumTestCase, apply_migration, retry
|
2020-06-29 19:39:04 +00:00
|
|
|
|
|
|
|
|
2020-09-11 21:21:11 +00:00
|
|
|
@skipUnless(platform.startswith("linux"), "requires local docker")
|
2020-06-29 19:39:04 +00:00
|
|
|
class TestFlowsStageSetup(SeleniumTestCase):
|
|
|
|
"""test stage setup flows"""
|
|
|
|
|
2020-10-20 16:42:26 +00:00
|
|
|
@retry()
|
2021-02-27 21:32:48 +00:00
|
|
|
@apply_migration("authentik_core", "0003_default_user")
|
|
|
|
@apply_migration("authentik_flows", "0008_default_flows")
|
2021-05-25 07:48:45 +00:00
|
|
|
@apply_migration("authentik_flows", "0011_flow_title")
|
2021-02-27 21:32:48 +00:00
|
|
|
@apply_migration("authentik_stages_password", "0002_passwordstage_change_flow")
|
2020-06-29 19:39:04 +00:00
|
|
|
def test_password_change(self):
|
|
|
|
"""test password change flow"""
|
2020-07-25 19:37:15 +00:00
|
|
|
# Ensure that password stage has change_flow set
|
|
|
|
flow = Flow.objects.get(
|
2020-09-25 19:12:42 +00:00
|
|
|
slug="default-password-change",
|
|
|
|
designation=FlowDesignation.STAGE_CONFIGURATION,
|
2020-07-25 19:37:15 +00:00
|
|
|
)
|
|
|
|
|
2020-09-25 18:33:06 +00:00
|
|
|
stage = PasswordStage.objects.get(name="default-authentication-password")
|
|
|
|
stage.configure_flow = flow
|
2020-07-25 19:37:15 +00:00
|
|
|
stage.save()
|
|
|
|
|
2020-09-11 21:21:11 +00:00
|
|
|
new_password = generate_client_secret()
|
2020-06-29 19:39:04 +00:00
|
|
|
|
|
|
|
self.driver.get(
|
2021-03-22 12:44:17 +00:00
|
|
|
self.url(
|
|
|
|
"authentik_core:if-flow",
|
|
|
|
flow_slug="default-authentication-flow",
|
|
|
|
)
|
2020-06-29 19:39:04 +00:00
|
|
|
)
|
2021-02-27 21:32:48 +00:00
|
|
|
self.login()
|
2021-03-22 12:44:17 +00:00
|
|
|
self.wait_for_url(self.if_admin_url("/library"))
|
2020-11-23 13:24:42 +00:00
|
|
|
|
|
|
|
self.driver.get(
|
|
|
|
self.url(
|
2020-12-05 21:08:42 +00:00
|
|
|
"authentik_flows:configure",
|
2020-11-23 13:24:42 +00:00
|
|
|
stage_uuid=PasswordStage.objects.first().stage_uuid,
|
|
|
|
)
|
|
|
|
)
|
2021-02-27 21:32:48 +00:00
|
|
|
|
|
|
|
flow_executor = self.get_shadow_root("ak-flow-executor")
|
|
|
|
prompt_stage = self.get_shadow_root("ak-stage-prompt", flow_executor)
|
|
|
|
|
|
|
|
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=password]").send_keys(
|
|
|
|
new_password
|
|
|
|
)
|
|
|
|
prompt_stage.find_element(
|
|
|
|
By.CSS_SELECTOR, "input[name=password_repeat]"
|
|
|
|
).send_keys(new_password)
|
|
|
|
prompt_stage.find_element(
|
|
|
|
By.CSS_SELECTOR, "input[name=password_repeat]"
|
|
|
|
).send_keys(Keys.ENTER)
|
2020-06-29 19:39:04 +00:00
|
|
|
|
2021-03-22 12:44:17 +00:00
|
|
|
self.wait_for_url(self.if_admin_url("/library"))
|
2020-06-29 19:39:04 +00:00
|
|
|
# Because USER() is cached, we need to get the user manually here
|
|
|
|
user = User.objects.get(username=USER().username)
|
|
|
|
self.assertTrue(user.check_password(new_password))
|