From 97551defe96ecbf8aae0163c4133b42a2ca53c6f Mon Sep 17 00:00:00 2001 From: Glen Goulter Date: Tue, 5 Mar 2024 16:49:04 -0800 Subject: [PATCH] Remove the special cases for prod where the tests would use the old iframe --- tests/conftest.py | 83 +++++++++++++++---------------------------- tests/test_2fa_duo.py | 22 +++++------- 2 files changed, 37 insertions(+), 68 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ebeb590..ddc1bc5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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. @@ -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 diff --git a/tests/test_2fa_duo.py b/tests/test_2fa_duo.py index ef3530f..81faae6 100644 --- a/tests/test_2fa_duo.py +++ b/tests/test_2fa_duo.py @@ -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 @@ -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) @@ -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): """