@@ -109,6 +109,8 @@ def get_current_user_sync_path():
109109
110110
111111def 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
267304def run_sys_command (command = None , shell = False ):
0 commit comments