Skip to content

Commit

Permalink
SC-tests/Graphical: add timeout and HTML file changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GeorgePantelakis committed Mar 14, 2024
1 parent b442282 commit e772f72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
31 changes: 19 additions & 12 deletions Graphical/local-user-graphical-login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -93,16 +94,17 @@ 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):
gui.kb_send('enter', wait_time=20)
# 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):
Expand All @@ -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):
Expand Down Expand Up @@ -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])
Expand All @@ -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')
Expand All @@ -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):
Expand Down
17 changes: 7 additions & 10 deletions Graphical/local-user-lock-on-removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e772f72

Please # to comment.