Skip to content

Commit 92e265c

Browse files
Update tests to match support for physical cards of SCAutolib
1 parent b08c75f commit 92e265c

11 files changed

+255
-205
lines changed

Graphical/local-user-graphical-login.py

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from SCAutolib.models.log import assert_log
3232
import pytest
3333
from time import sleep
34+
from conftest import check_multicert
3435

3536
SECURE_LOG = '/var/log/secure'
3637

@@ -56,19 +57,20 @@ def test_login_with_sc(local_user, required):
5657
expected_log = (
5758
r'.* gdm-smartcard\]\[[0-9]+\]: '
5859
r'pam_sss\(gdm-smartcard:auth\): authentication success;'
59-
r'.*user=' + local_user.username + r'@shadowutils.*'
60+
rf'.*user=({local_user.username}@shadowutils)?.*'
6061
)
6162

62-
with (GUI() as gui,
63-
Authselect(required=required), local_user.card(insert=True)):
64-
gui.assert_text('PIN', timeout=60)
65-
gui.kb_write(local_user.pin)
63+
with (GUI(wait_time=10) as gui, Authselect(required=required)):
64+
for i in range(local_user.total_cards):
65+
with getattr(local_user, f"card_{i}")(insert=True) as sc:
66+
check_multicert(gui=gui)
67+
gui.assert_text('PIN', timeout=60)
6668

67-
with assert_log(SECURE_LOG, expected_log):
68-
gui.kb_send('enter', wait_time=20)
69-
# Mandatory wait to switch display from GDM to GNOME
70-
# Not waiting can actually mess up the output
71-
gui.check_home_screen()
69+
with assert_log(SECURE_LOG, expected_log):
70+
gui.kb_write(sc.pin)
71+
# Mandatory wait to switch display from GDM to GNOME
72+
# Not waiting can actually mess up the output
73+
gui.check_home_screen()
7274

7375

7476
@pytest.mark.parametrize("required", [(True), (False)])
@@ -91,20 +93,24 @@ def test_login_with_sc_wrong(local_user, required):
9193
expected_log = (
9294
r'.* gdm-smartcard\]\[[0-9]+\]: '
9395
r'pam_sss\(gdm-smartcard:auth\): authentication failure;'
94-
r'.*user=' + local_user.username + r'@shadowutils.*'
96+
rf'.*user=({local_user.username}@shadowutils)?.*'
9597
)
9698

97-
with (GUI() as gui,
98-
Authselect(required=required), local_user.card(insert=True)):
99-
gui.assert_text('PIN', timeout=20)
100-
gui.kb_write(local_user.pin[:-1])
99+
with (GUI(wait_time=10) as gui, Authselect(required=required)):
100+
for i in range(local_user.total_cards):
101+
with getattr(local_user, f"card_{i}")(insert=True) as sc:
102+
multicert = check_multicert(gui=gui)
103+
gui.assert_text('PIN', timeout=20)
101104

102-
with assert_log(SECURE_LOG, expected_log):
103-
gui.kb_send('enter', wait_time=20)
104-
# Mandatory wait to switch display from GDM to GNOME
105-
# Not waiting can actually mess up the output
106-
gui.check_home_screen(False)
107-
gui.assert_text('PIN', timeout=20)
105+
with assert_log(SECURE_LOG, expected_log):
106+
gui.kb_write(sc.pin[:-1])
107+
# Mandatory wait to switch display from GDM to GNOME
108+
# Not waiting can actually mess up the output
109+
gui.check_home_screen(False)
110+
if multicert:
111+
gui.assert_text('certificate', timeout=20)
112+
else:
113+
gui.assert_text('PIN', timeout=20)
108114

109115

110116
def test_login_password(local_user):
@@ -123,13 +129,12 @@ def test_login_password(local_user):
123129
"""
124130
expected_log = (
125131
r'.* pam_unix\(gdm-password:session\): session opened for user .*'
126-
)
132+
)
127133

128-
with GUI() as gui, Authselect(required=False):
134+
with GUI(wait_time=10) as gui, Authselect(required=False):
129135
gui.click_on(local_user.username)
130-
gui.kb_write(local_user.password)
131136
with assert_log(SECURE_LOG, expected_log):
132-
gui.kb_send('enter', wait_time=20)
137+
gui.kb_write(local_user.password)
133138
gui.check_home_screen()
134139

135140

@@ -151,14 +156,13 @@ def test_login_password_wrong(local_user):
151156
expected_log = (
152157
r'.* gdm-password\]\[[0-9]+\]: '
153158
r'pam_unix\(gdm-password:auth\): authentication failure;'
154-
r'.*user=' + local_user.username + r'.*'
159+
rf'.*user=({local_user.username}@shadowutils)?.*'
155160
)
156161

157-
with GUI() as gui, Authselect(required=False):
162+
with GUI(wait_time=10) as gui, Authselect(required=False):
158163
gui.click_on(local_user.username)
159-
gui.kb_write(local_user.password[:-1])
160164
with assert_log(SECURE_LOG, expected_log):
161-
gui.kb_send('enter', wait_time=20)
165+
gui.kb_write(local_user.password[:-1])
162166

163167
gui.check_home_screen(False)
164168
gui.assert_text('Password', timeout=20)
@@ -182,28 +186,29 @@ def test_insert_card_prompt(local_user, lock_on_removal):
182186
C. GDM shows "insert PIN" prompt
183187
D. User is logged in successfully.
184188
"""
185-
with (GUI() as gui,
186-
Authselect(required=True, lock_on_removal=lock_on_removal),
187-
local_user.card(insert=False) as card):
188-
try:
189-
gui.assert_text('insert', timeout=20)
190-
except Exception:
191-
gui.click_on(local_user.username)
192-
193-
gui.assert_text('insert', timeout=20)
194-
card.insert()
195-
sleep(10)
196-
gui.assert_text('PIN')
197-
gui.kb_write(local_user.pin)
198-
199-
expected_log = (
200-
r'.* gdm-smartcard\]\[[0-9]+\]: '
201-
r'pam_sss\(gdm-smartcard:auth\): authentication success;'
202-
r'.*user=' + local_user.username + r'(@shadowutils)?.*'
203-
)
204-
205-
with assert_log(SECURE_LOG, expected_log):
206-
gui.kb_send('enter', wait_time=20)
207-
# Mandatory wait to switch display from GDM to GNOME
208-
# Not waiting can actually mess up the output
209-
gui.check_home_screen()
189+
with (GUI(wait_time=10) as gui,
190+
Authselect(required=True, lock_on_removal=lock_on_removal)):
191+
for i in range(local_user.total_cards):
192+
with getattr(local_user, f"card_{i}")(insert=True) as sc:
193+
try:
194+
gui.assert_text('insert', timeout=20)
195+
except Exception:
196+
gui.click_on(local_user.username)
197+
198+
gui.assert_text('insert', timeout=20)
199+
sc.insert()
200+
sleep(10)
201+
check_multicert(gui=gui)
202+
gui.assert_text('PIN')
203+
204+
expected_log = (
205+
r'.* gdm-smartcard\]\[[0-9]+\]: '
206+
r'pam_sss\(gdm-smartcard:auth\): authentication success;'
207+
rf'.*user=({local_user.username}@shadowutils)?.*'
208+
)
209+
210+
with assert_log(SECURE_LOG, expected_log):
211+
gui.kb_write(sc.pin)
212+
# Mandatory wait to switch display from GDM to GNOME
213+
# Not waiting can actually mess up the output
214+
gui.check_home_screen()

Graphical/local-user-lock-on-removal.py

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from SCAutolib.models.authselect import Authselect
2929
from SCAutolib.models.gui import GUI, keyboard
3030
from time import sleep
31+
from conftest import check_multicert
3132
import 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

8589
def 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()

Kerberos/test_kerberos_ssh_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from SCAutolib.models.authselect import Authselect
7-
from SCAutolib.isDistro import isDistro
7+
from SCAutolib.utils import isDistro
88

99

1010
def test_krb_user_ssh(ipa_user, user_shell):

Kerberos/test_kerberos_user_change_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import conftest
44
from SCAutolib.models.authselect import Authselect
5-
from SCAutolib.isDistro import isDistro
5+
from SCAutolib.utils import isDistro
66

77

88
@pytest.mark.parametrize("required,insert,expect,secret",

0 commit comments

Comments
 (0)