Skip to content

Commit

Permalink
Merge pull request #44 from UWIT-IAM/GH-43
Browse files Browse the repository at this point in the history
[GH-43] Remove the special test flows for prod where the tests would use the old iframe
  • Loading branch information
goulter authored Mar 6, 2024
2 parents 913e16e + 97551de commit f8768aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 68 deletions.
83 changes: 29 additions & 54 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def inner(
select_this_is_my_device: Optional[bool] = False,
):
"""
eval and prod flows have 2 different expectations, since duo is updated on eval only, prod to come soon.
:param current_browser: The browser you want to invoke these actions on.
:param passcode: The passcode you want to enter; if not provided, will use the
correct test instance passcode.
Expand Down Expand Up @@ -241,69 +240,45 @@ def inner(
if assert_failure is None:
assert_failure = not passcode_matches_default

if select_duo_push and test_env == 'prod':
current_browser.wait_for_tag('p', 'Use your 2FA device.')
iframe = current_browser.wait_for(Locators.iframe)
current_browser.switch_to.frame(iframe)
current_browser.wait_for(Locators.passcode_button)
current_browser.execute_script("document.getElementById('passcode').click();")

if test_env == 'prod':
current_browser.execute_script(
"document.getElementsByClassName('passcode-input')[0].value = arguments[0];",
passcode
)
current_browser.snap()
current_browser.execute_script("document.getElementById('passcode').click();")
sleep(5) # this sleep will go away after we copy the universal prompt 2fa to prod.

if select_duo_push and test_env == 'eval':
if select_duo_push:
duo_push(current_browser)

if test_env == 'eval':
# focus on the correct element based on if we are retrying the passcode,
# or its the first time we enter the passcode
wait = WebDriverWait(current_browser, 10)
if retry:
element = wait.until(EC.element_to_be_clickable((By.XPATH,
"//input[contains(@id, 'passcode-input')]")))
wait = WebDriverWait(current_browser, 10)
if retry:
element = wait.until(EC.element_to_be_clickable((By.XPATH,
"//input[contains(@id, 'passcode-input')]")))
else:
element = wait.until(EC.visibility_of_element_located((By.XPATH,
"//div[contains(text(), 'Bypass code') and "
"contains(@class, 'row') and contains(@class, "
"'display-flex')]")))

current_browser.snap()
element.click()
current_browser.snap()
if retry:
clear_passcode(current_browser, element)
current_browser.send_inputs(passcode)
current_browser.snap()
current_browser.wait_for_tag('button', 'Verify').click()

if is_this_your_device_screen:
if select_this_is_my_device:
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='trust-browser-button']")))
else:
element = wait.until(EC.visibility_of_element_located((By.XPATH,
"//div[contains(text(), 'Bypass code') and "
"contains(@class, 'row') and contains(@class, "
"'display-flex')]")))
element = wait.until(
EC.element_to_be_clickable((By.XPATH, "//button[@id='dont-trust-browser-button' "
"and text()='No, other people use this "
"device']")))

current_browser.snap()
element.click()
current_browser.snap()
if retry:
clear_passcode(current_browser, element)
current_browser.send_inputs(passcode)
current_browser.snap()
current_browser.wait_for_tag('button', 'Verify').click()

if test_env == 'eval' and is_this_your_device_screen:
if select_this_is_my_device:
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='trust-browser-button']")))
else:
element = wait.until(
EC.element_to_be_clickable((By.XPATH, "//button[@id='dont-trust-browser-button' "
"and text()='No, other people use this "
"device']")))

element.click()
current_browser.snap()
current_browser.snap()

if assert_success:
if test_env == 'prod':
current_browser.switch_to.default_content()
sp = sp_domain(match_service_provider) if match_service_provider else ''
current_browser.wait_for_tag('h2', f'{sp} sign-in success!')
elif assert_failure:
if test_env == 'eval':
current_browser.wait_for_tag('span', 'Invalid passcode')
else:
current_browser.wait_for_tag('span', 'Incorrect passcode. Enter a passcode from Duo Mobile.')
current_browser.wait_for_tag('span', 'Invalid passcode')

return inner

Expand Down
22 changes: 8 additions & 14 deletions tests/test_2fa_duo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
2FA-1 thru 2FA-11. 2FA-8b and 2FA-10 are not yet automatable.
"""
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
Expand Down Expand Up @@ -191,18 +190,13 @@ def test_remember_me_cookie(
fresh_browser.get(sp_shib_url(sp, append='mfa'))
fresh_browser.send_inputs(netid3, password)
fresh_browser.click(Locators.submit_button)
if test_env == 'prod':
fresh_browser.wait_for_tag('p', 'Use your 2FA device.')
fresh_browser.find_element_by_name('rememberme').click()
enter_duo_passcode(fresh_browser, match_service_provider=sp)

if test_env == 'eval':
"""
Select the other duo option, to get to the bypass code option
"""
wait = WebDriverWait(fresh_browser, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Other options')]")))
enter_duo_passcode(fresh_browser, match_service_provider=sp, select_this_is_my_device=True)

"""
Select the other duo option, to get to the bypass code option
"""
wait = WebDriverWait(fresh_browser, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Other options')]")))
enter_duo_passcode(fresh_browser, match_service_provider=sp, select_this_is_my_device=True)

# go to an idp site to retrieve the shib idp cookies
fresh_browser.get(idp_url)
Expand All @@ -229,7 +223,7 @@ def test_remember_me_cookie(
log_in_netid(fresh_browser, netid3, match_service_provider=sp)


@pytest.mark.usefixtures('skip_if_eval')
@pytest.mark.skip(reason="We dont yet have a way to 'forget' a remember me style cookie. Archiving this for when we do")
def test_forget_me_self_service(utils, sp_url, sp_domain, secrets, netid3, test_env, enter_duo_passcode,
fresh_browser, sp_shib_url):
"""
Expand Down

0 comments on commit f8768aa

Please sign in to comment.