Skip to content

Commit 4670d13

Browse files
authored
test: check keyring before starting client (#12028)
1 parent 8d5cbe6 commit 4670d13

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

test/gui/shared/scripts/bdd_hooks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from helpers.SyncHelper import close_socket_connection, clear_waited_after_sync
2424
from helpers.SpaceHelper import delete_project_spaces
2525
from helpers.api.provisioning import delete_created_groups, delete_created_users
26-
from helpers.SetupClientHelper import wait_until_app_killed, unlock_keyring
26+
from helpers.SetupClientHelper import wait_until_app_killed
2727
from helpers.ConfigHelper import (
2828
init_config,
2929
get_config,
@@ -62,7 +62,6 @@ def hook(context):
6262
# Order: 1
6363
@OnScenarioStart
6464
def hook(context):
65-
unlock_keyring()
6665
clear_scenario_config()
6766

6867

test/gui/shared/scripts/helpers/SetupClientHelper.py

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def get_current_user_sync_path():
109109

110110

111111
def start_client():
112+
check_keyring()
113+
112114
squish.startApplication(
113115
'owncloud -s'
114116
+ f' --logfile {get_config("clientLogFile")}'
@@ -230,10 +232,55 @@ def generate_uuidv4():
230232

231233

232234
# sometimes the keyring is locked during the test execution, and we need to unlock it
233-
def unlock_keyring():
235+
def check_keyring():
234236
if is_windows():
235237
return
236238

239+
if is_keyring_locked():
240+
test.log('[INFO] Keyring is locked or service is down. Unlocking...')
241+
wait_until_keyring_unlocked()
242+
243+
244+
def unlock_keyring() -> bool | None:
245+
if is_windows():
246+
return None
247+
248+
password = os.getenv('VNC_PW')
249+
command = f'echo -n "{password}" | gnome-keyring-daemon -r --unlock'
250+
stdout, stderr, returncode = run_sys_command(command, True)
251+
252+
output = ''
253+
if stdout:
254+
output = stdout.decode('utf-8')
255+
if stderr:
256+
output = stderr.decode('utf-8')
257+
test.log(f'[INFO] Keyring unlock output: {output}')
258+
# wait for keyring to unlock
259+
squish.snooze(1)
260+
261+
if returncode:
262+
return False
263+
264+
return not is_keyring_locked()
265+
266+
267+
def wait_until_keyring_unlocked():
268+
if is_windows():
269+
return
270+
271+
timeout = 10
272+
unlocked = squish.waitFor(
273+
lambda: unlock_keyring(), # pylint: disable=unnecessary-lambda
274+
timeout * 1000,
275+
)
276+
if not unlocked:
277+
test.fail(f'Timeout. Keyring was not unlocked within {timeout} seconds')
278+
279+
280+
def is_keyring_locked() -> bool | None:
281+
if is_windows():
282+
return None
283+
237284
stdout, stderr, _ = run_sys_command(
238285
[
239286
'busctl',
@@ -250,18 +297,8 @@ def unlock_keyring():
250297
output = stdout.decode('utf-8')
251298
if stderr:
252299
output = stderr.decode('utf-8')
253-
254-
if not output.strip().endswith('false'):
255-
test.log('Unlocking keyring...')
256-
password = os.getenv('VNC_PW')
257-
command = f'echo -n "{password}" | gnome-keyring-daemon -r -d --unlock'
258-
stdout, stderr, returncode = run_sys_command(command, True)
259-
if stdout:
260-
output = stdout.decode('utf-8')
261-
if stderr:
262-
output = stderr.decode('utf-8')
263-
if returncode:
264-
test.log(f'Failed to unlock keyring:\n{output}')
300+
test.log(f'[INFO] Keyring locked status: {output}')
301+
return not output.strip().endswith('false')
265302

266303

267304
def run_sys_command(command=None, shell=False):

0 commit comments

Comments
 (0)