2828from SCAutolib .models .authselect import Authselect
2929from SCAutolib .models .gui import GUI , keyboard
3030from time import sleep
31+ from conftest import check_multicert
3132import pytest
3233
3334
@@ -50,36 +51,39 @@ def test_lock_on_removal(local_user, required):
5051 C. The system locks itself after the card is removed
5152 D. The system is unlocked
5253 """
53- with (GUI () as gui , Authselect (required = required , lock_on_removal = True )):
54+ with (GUI (wait_time = 10 ) as gui ,
55+ Authselect (required = required , lock_on_removal = True )):
5456 # insert the card and sign in a standard way
55- with local_user .card (insert = True ) as card :
56- sleep (5 )
57- gui .assert_text ('PIN' , timeout = 20 )
58- gui .kb_write (local_user .pin )
59- gui .kb_send ('enter' , wait_time = 20 )
60- # confirm that you are logged in
61- gui .check_home_screen ()
62-
63- # remove the card and wait for the screen to lock
64- card .remove ()
65- sleep (5 )
66- # Locking the screen in GNOME apparently does not generate any log.
67- # This could be checked by monitoring D-Bus signals
68-
69- # Wake up the black screen by pressing enter
70- gui .kb_send ('enter' , screenshot = False )
71- # Confirm that the screen is locked
72- # After the screen has been locked, there should be no Activities
73- gui .check_home_screen (False )
74- gui .assert_text ('insert' , timeout = 20 )
75-
76- card .insert ()
77- # click on the password field
78- gui .click_on ('PIN' )
79- gui .kb_write (local_user .pin )
80- gui .kb_send ('enter' , wait_time = 20 )
81- # confirm that you are logged back in
82- gui .check_home_screen ()
57+
58+ for i in range (local_user .total_cards ):
59+ with getattr (local_user , f"card_{ i } " )(insert = True ) as sc :
60+ sleep (5 )
61+ check_multicert (gui = gui )
62+ gui .assert_text ('PIN' , timeout = 20 )
63+ gui .kb_write (sc .pin )
64+ # confirm that you are logged in
65+ gui .check_home_screen ()
66+
67+ # remove the card and wait for the screen to lock
68+ sc .remove ()
69+ sleep (5 )
70+ # Locking the screen in GNOME apparently does not generate any log.
71+ # This could be checked by monitoring D-Bus signals
72+
73+ # Wake up the black screen by pressing enter
74+ gui .kb_send ('enter' , screenshot = False )
75+ # Confirm that the screen is locked
76+ # After the screen has been locked, there should be no Activities
77+ gui .check_home_screen (False )
78+ gui .assert_text ('insert' , timeout = 20 )
79+
80+ sc .insert ()
81+ check_multicert (gui = gui )
82+ # click on the password field
83+ gui .click_on ('PIN' )
84+ gui .kb_write (sc .pin )
85+ # confirm that you are logged back in
86+ gui .check_home_screen ()
8387
8488
8589def test_lock_on_removal_password (local_user ):
@@ -99,24 +103,25 @@ def test_lock_on_removal_password(local_user):
99103 C. Nothing happens
100104 D. Nothing happens - system will not lock on card removal
101105 """
102- with (GUI () as gui , Authselect (required = False , lock_on_removal = True )):
103- with local_user .card (insert = False ) as card :
104- gui .click_on (local_user .username )
105- gui .kb_write (local_user .password )
106- gui .kb_send ('enter' , wait_time = 20 )
107- gui .check_home_screen ()
106+ with (GUI (wait_time = 10 ) as gui ,
107+ Authselect (required = False , lock_on_removal = True )):
108+ for i in range (local_user .total_cards ):
109+ with getattr (local_user , f"card_{ i } " )() as sc :
110+ gui .click_on (local_user .username )
111+ gui .kb_write (local_user .password )
112+ gui .check_home_screen ()
108113
109- card .insert ()
110- sleep (10 )
111- card .remove ()
112- sleep (10 )
114+ sc .insert ()
115+ sleep (10 )
116+ sc .remove ()
117+ sleep (10 )
113118
114- # Screen should be unlocked
115- gui .check_home_screen ()
119+ # Screen should be unlocked
120+ gui .check_home_screen ()
116121
117122
118123@pytest .mark .parametrize ("lock_on_removal" , [(True ), (False )])
119- def test_lockscreen_password (local_user , lock_on_removal ):
124+ def test_lockscreen_password (local_user , check_multicert , lock_on_removal ):
120125 """Local user unlocks screen using password, even if the smart card is
121126 inserted (after the password login). Screen unlocking requires the same
122127 method (PIN vs password) as was used for login.
@@ -137,31 +142,30 @@ def test_lockscreen_password(local_user, lock_on_removal):
137142 D. The screen is locked
138143 E. Screen is unlocked successfully
139144 """
140- with (GUI () as gui ,
141- Authselect (required = False , lock_on_removal = lock_on_removal ),
142- local_user .card (insert = False ) as card ):
143- gui .click_on (local_user .username )
144- gui .kb_write (local_user .password )
145- gui .kb_send ('enter' , wait_time = 20 )
146- gui .check_home_screen ()
147-
148- card .insert ()
149- sleep (10 )
150- # press shortcut to lock the screen
151- # keyboard.send('windows+l') cannot be parsed properly
152- # this is a workaround for keyboard library
153- keyboard .press ((125 , 126 ),)
154- keyboard .send ('l' )
155- keyboard .release ((125 , 126 ),)
156- sleep (10 )
157-
158- # Wake up the black screen by pressing enter
159- gui .kb_send ('enter' , screenshot = False )
160- # Confirm that the screen is locked
161- # After the screen has been locked, there should be no Activities
162- gui .check_home_screen (False )
163- gui .click_on ('Password' , check_difference = False )
164- gui .kb_write (local_user .password )
165- gui .kb_send ('enter' , wait_time = 10 )
166- # confirm that you are logged back in
167- gui .check_home_screen ()
145+ with (GUI (wait_time = 10 ) as gui ,
146+ Authselect (required = False , lock_on_removal = lock_on_removal )):
147+ for i in range (local_user .total_cards ):
148+ with getattr (local_user , f"card_{ i } " )() as sc :
149+ gui .click_on (local_user .username )
150+ gui .kb_write (local_user .password )
151+ gui .check_home_screen ()
152+
153+ sc .insert ()
154+ sleep (10 )
155+ # press shortcut to lock the screen
156+ # keyboard.send('windows+l') cannot be parsed properly
157+ # this is a workaround for keyboard library
158+ keyboard .press ((125 , 126 ),)
159+ keyboard .send ('l' )
160+ keyboard .release ((125 , 126 ),)
161+ sleep (10 )
162+
163+ # Wake up the black screen by pressing enter
164+ gui .kb_send ('enter' , screenshot = False )
165+ # Confirm that the screen is locked
166+ # After the screen has been locked, there should be no Activities
167+ gui .check_home_screen (False )
168+ gui .click_on ('Password' , check_difference = False )
169+ gui .kb_write (local_user .password )
170+ # confirm that you are logged back in
171+ gui .check_home_screen ()
0 commit comments