From 12412fd1f8829ed666fbc927ee9654d0aeea7075 Mon Sep 17 00:00:00 2001 From: George Pantelakis Date: Wed, 13 Mar 2024 18:33:33 +0100 Subject: [PATCH] SC-tests/Graphical: add timeout and HTML file changes 1) added timeout to all assert_text calls. 2) Changed order between GUI and Authselect class calling in context manager so the HTML file will include Authselect logs. This happens because HTML file initialization happens in GUI __init__ func. 3) fixed minor issues in test_insert_card_prompt. --- Graphical/local-user-graphical-login.py | 31 +++++++++++++++---------- Graphical/local-user-lock-on-removal.py | 17 ++++++-------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Graphical/local-user-graphical-login.py b/Graphical/local-user-graphical-login.py index 133e94a..f623707 100644 --- a/Graphical/local-user-graphical-login.py +++ b/Graphical/local-user-graphical-login.py @@ -59,7 +59,8 @@ def test_login_with_sc(local_user, required): r'.*user=' + local_user.username + r'@shadowutils.*' ) - with Authselect(required=required), local_user.card(insert=True), GUI() as gui: + with (GUI() as gui, + Authselect(required=required), local_user.card(insert=True)): gui.assert_text('PIN', timeout=60) gui.kb_write(local_user.pin) @@ -93,8 +94,9 @@ def test_login_with_sc_wrong(local_user, required): r'.*user=' + local_user.username + r'@shadowutils.*' ) - with Authselect(required=required), local_user.card(insert=True), GUI() as gui: - gui.assert_text('PIN') + with (GUI() as gui, + Authselect(required=required), local_user.card(insert=True)): + gui.assert_text('PIN', timeout=20) gui.kb_write(local_user.pin[:-1]) with assert_log(SECURE_LOG, expected_log): @@ -102,7 +104,7 @@ def test_login_with_sc_wrong(local_user, required): # Mandatory wait to switch display from GDM to GNOME # Not waiting can actually mess up the output gui.check_home_screen(False) - gui.assert_text('PIN') + gui.assert_text('PIN', timeout=20) def test_login_password(local_user): @@ -123,7 +125,7 @@ def test_login_password(local_user): r'.* pam_unix\(gdm-password:session\): session opened for user .*' ) - with Authselect(required=False), GUI() as gui: + with GUI() as gui, Authselect(required=False): gui.click_on(local_user.username) gui.kb_write(local_user.password) with assert_log(SECURE_LOG, expected_log): @@ -152,14 +154,14 @@ def test_login_password_wrong(local_user): r'.*user=' + local_user.username + r'.*' ) - with Authselect(required=False), GUI() as gui: + with GUI() as gui, Authselect(required=False): gui.click_on(local_user.username) gui.kb_write(local_user.password[:-1]) with assert_log(SECURE_LOG, expected_log): gui.kb_send('enter', wait_time=20) gui.check_home_screen(False) - gui.assert_text('Password') + gui.assert_text('Password', timeout=20) @pytest.mark.parametrize("lock_on_removal", [True, False]) @@ -180,10 +182,15 @@ def test_insert_card_prompt(local_user, lock_on_removal): C. GDM shows "insert PIN" prompt D. User is logged in successfully. """ - with (Authselect(required=True, lock_on_removal=lock_on_removal), - local_user.card(insert=False) as card, - GUI() as gui): - gui.assert_text('insert') + with (GUI() as gui, + Authselect(required=True, lock_on_removal=lock_on_removal), + local_user.card(insert=False) as card): + try: + gui.assert_text('insert') + except Exception: + gui.click_on(local_user.username) + + gui.assert_text('insert', timeout=20) card.insert() sleep(10) gui.assert_text('PIN') @@ -192,7 +199,7 @@ def test_insert_card_prompt(local_user, lock_on_removal): expected_log = ( r'.* gdm-smartcard\]\[[0-9]+\]: ' r'pam_sss\(gdm-smartcard:auth\): authentication success;' - r'.*user=' + local_user.username + r'@shadowutils.*' + r'.*user=' + local_user.username + r'(@shadowutils)?.*' ) with assert_log(SECURE_LOG, expected_log): diff --git a/Graphical/local-user-lock-on-removal.py b/Graphical/local-user-lock-on-removal.py index de194bb..ed2a152 100644 --- a/Graphical/local-user-lock-on-removal.py +++ b/Graphical/local-user-lock-on-removal.py @@ -50,12 +50,11 @@ def test_lock_on_removal(local_user, required): C. The system locks itself after the card is removed D. The system is unlocked """ - - with Authselect(required=required, lock_on_removal=True), GUI() as gui: + with (GUI() as gui, Authselect(required=required, lock_on_removal=True)): # insert the card and sign in a standard way with local_user.card(insert=True) as card: sleep(5) - gui.assert_text('PIN') + gui.assert_text('PIN', timeout=20) gui.kb_write(local_user.pin) gui.kb_send('enter', wait_time=20) # confirm that you are logged in @@ -72,7 +71,7 @@ def test_lock_on_removal(local_user, required): # Confirm that the screen is locked # After the screen has been locked, there should be no Activities gui.check_home_screen(False) - gui.assert_text('insert') + gui.assert_text('insert', timeout=20) card.insert() # click on the password field @@ -100,7 +99,7 @@ def test_lock_on_removal_password(local_user): C. Nothing happens D. Nothing happens - system will not lock on card removal """ - with Authselect(required=False, lock_on_removal=True), GUI() as gui: + with (GUI() as gui, Authselect(required=False, lock_on_removal=True)): with local_user.card(insert=False) as card: gui.click_on(local_user.username) gui.kb_write(local_user.password) @@ -138,11 +137,9 @@ def test_lockscreen_password(local_user, lock_on_removal): D. The screen is locked E. Screen is unlocked successfully """ - with ( - Authselect(required=False, lock_on_removal=lock_on_removal), - GUI() as gui, - local_user.card(insert=False) as card - ): + with (GUI() as gui, + Authselect(required=False, lock_on_removal=lock_on_removal), + local_user.card(insert=False) as card): gui.click_on(local_user.username) gui.kb_write(local_user.password) gui.kb_send('enter', wait_time=20)