2020-05-28 22:45:56 +00:00
|
|
|
"""Test 2-step enroll flow"""
|
|
|
|
from selenium.webdriver.common.by import By
|
2020-06-19 20:37:48 +00:00
|
|
|
from selenium.webdriver.support import expected_conditions as ec
|
2020-05-28 22:45:56 +00:00
|
|
|
|
2020-06-20 21:52:06 +00:00
|
|
|
from e2e.utils import USER, SeleniumTestCase
|
2020-05-28 22:45:56 +00:00
|
|
|
from passbook.flows.models import Flow, FlowDesignation, FlowStageBinding
|
|
|
|
from passbook.policies.expression.models import ExpressionPolicy
|
|
|
|
from passbook.policies.models import PolicyBinding
|
2020-06-19 17:34:27 +00:00
|
|
|
from passbook.stages.identification.models import IdentificationStage
|
2020-05-28 22:45:56 +00:00
|
|
|
from passbook.stages.prompt.models import FieldTypes, Prompt, PromptStage
|
|
|
|
from passbook.stages.user_login.models import UserLoginStage
|
|
|
|
from passbook.stages.user_write.models import UserWriteStage
|
|
|
|
|
2020-06-07 17:50:01 +00:00
|
|
|
|
2020-06-20 15:06:00 +00:00
|
|
|
class TestEnroll2Step(SeleniumTestCase):
|
2020-05-28 22:45:56 +00:00
|
|
|
"""Test 2-step enroll flow"""
|
|
|
|
|
|
|
|
def test_enroll_2_step(self):
|
|
|
|
"""Test 2-step enroll flow"""
|
|
|
|
# First stage fields
|
|
|
|
username_prompt = Prompt.objects.create(
|
|
|
|
field_key="username", label="Username", order=0, type=FieldTypes.TEXT
|
|
|
|
)
|
|
|
|
password = Prompt.objects.create(
|
|
|
|
field_key="password", label="Password", order=1, type=FieldTypes.PASSWORD
|
|
|
|
)
|
|
|
|
password_repeat = Prompt.objects.create(
|
|
|
|
field_key="password_repeat",
|
|
|
|
label="Password (repeat)",
|
|
|
|
order=2,
|
|
|
|
type=FieldTypes.PASSWORD,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Second stage fields
|
|
|
|
name_field = Prompt.objects.create(
|
|
|
|
field_key="name", label="Name", order=0, type=FieldTypes.TEXT
|
|
|
|
)
|
|
|
|
email = Prompt.objects.create(
|
|
|
|
field_key="email", label="E-Mail", order=1, type=FieldTypes.EMAIL
|
|
|
|
)
|
|
|
|
|
|
|
|
# Stages
|
|
|
|
first_stage = PromptStage.objects.create(name="prompt-stage-first")
|
|
|
|
first_stage.fields.set([username_prompt, password, password_repeat])
|
|
|
|
first_stage.save()
|
|
|
|
second_stage = PromptStage.objects.create(name="prompt-stage-second")
|
|
|
|
second_stage.fields.set([name_field, email])
|
|
|
|
second_stage.save()
|
|
|
|
user_write = UserWriteStage.objects.create(name="enroll-user-write")
|
|
|
|
user_login = UserLoginStage.objects.create(name="enroll-user-login")
|
|
|
|
|
|
|
|
# Password checking policy
|
|
|
|
password_policy = ExpressionPolicy.objects.create(
|
|
|
|
name="policy-enrollment-password-equals",
|
2020-06-07 17:30:56 +00:00
|
|
|
expression="return request.context['password'] == request.context['password_repeat']",
|
2020-05-28 22:45:56 +00:00
|
|
|
)
|
|
|
|
PolicyBinding.objects.create(
|
|
|
|
target=first_stage, policy=password_policy, order=0
|
|
|
|
)
|
|
|
|
|
|
|
|
flow = Flow.objects.create(
|
|
|
|
name="default-enrollment-flow",
|
|
|
|
slug="default-enrollment-flow",
|
|
|
|
designation=FlowDesignation.ENROLLMENT,
|
|
|
|
)
|
|
|
|
|
2020-06-07 17:30:56 +00:00
|
|
|
# Attach enrollment flow to identification stage
|
|
|
|
ident_stage: IdentificationStage = IdentificationStage.objects.first()
|
|
|
|
ident_stage.enrollment_flow = flow
|
|
|
|
ident_stage.save()
|
|
|
|
|
2020-05-28 22:45:56 +00:00
|
|
|
FlowStageBinding.objects.create(flow=flow, stage=first_stage, order=0)
|
|
|
|
FlowStageBinding.objects.create(flow=flow, stage=second_stage, order=1)
|
|
|
|
FlowStageBinding.objects.create(flow=flow, stage=user_write, order=2)
|
|
|
|
FlowStageBinding.objects.create(flow=flow, stage=user_login, order=3)
|
2020-06-07 17:30:56 +00:00
|
|
|
self.driver.get(self.live_server_url)
|
2020-05-28 22:45:56 +00:00
|
|
|
self.driver.find_element(By.CSS_SELECTOR, "[role=enroll]").click()
|
|
|
|
self.driver.find_element(By.ID, "id_username").send_keys("foo")
|
2020-06-20 21:52:06 +00:00
|
|
|
self.driver.find_element(By.ID, "id_password").send_keys(USER().username)
|
|
|
|
self.driver.find_element(By.ID, "id_password_repeat").send_keys(USER().username)
|
2020-05-28 22:45:56 +00:00
|
|
|
self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
|
|
|
|
self.driver.find_element(By.ID, "id_name").send_keys("some name")
|
|
|
|
self.driver.find_element(By.ID, "id_email").send_keys("foo@bar.baz")
|
|
|
|
self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
|
|
|
|
self.driver.find_element(By.LINK_TEXT, "foo").click()
|
2020-06-19 20:27:44 +00:00
|
|
|
|
2020-06-19 20:37:48 +00:00
|
|
|
self.wait.until(ec.presence_of_element_located((By.ID, "id_username")))
|
2020-05-28 22:45:56 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.driver.find_element(By.XPATH, "//a[contains(@href, '/-/user/')]").text,
|
|
|
|
"foo",
|
|
|
|
)
|
|
|
|
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"),
|
|
|
|
"some name",
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.driver.find_element(By.ID, "id_email").get_attribute("value"),
|
|
|
|
"foo@bar.baz",
|
|
|
|
)
|