Skip to content

Commit

Permalink
wait 5 sec for keyring to be unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Jan 9, 2025
1 parent 7b40603 commit abaf2c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 61 deletions.
4 changes: 2 additions & 2 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from helpers.SyncHelper import close_socket_connection, clear_waited_after_sync
from helpers.SpaceHelper import delete_project_spaces
from helpers.api.provisioning import delete_created_groups, delete_created_users
from helpers.SetupClientHelper import wait_until_app_killed, unlock_keyring
from helpers.SetupClientHelper import wait_until_app_killed, check_keyring
from helpers.ConfigHelper import (
init_config,
get_config,
Expand Down Expand Up @@ -62,7 +62,7 @@ def hook(context):
# Order: 1
@OnScenarioStart
def hook(context):
unlock_keyring()
check_keyring()
clear_scenario_config()


Expand Down
99 changes: 40 additions & 59 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from helpers.SyncHelper import listen_sync_status_for_item
from helpers.api.utils import url_join
from helpers.UserHelper import get_displayname_for_user
from helpers.ReportHelper import is_video_enabled, take_screenshot
from helpers.ReportHelper import is_video_enabled


def substitute_inline_codes(value):
Expand Down Expand Up @@ -230,10 +230,46 @@ def generate_uuidv4():


# sometimes the keyring is locked during the test execution, and we need to unlock it
def unlock_keyring():
def check_keyring():
if is_windows():
return

if is_keyring_locked():
test.log('Keyring is locked or service is down. Unlocking...')
wait_until_keyring_unlocked()


def unlock_keyring():
password = os.getenv('VNC_PW')
command = f'echo -n "{password}" | gnome-keyring-daemon -r --unlock'
stdout, stderr, returncode = run_sys_command(command, True)

output = ''
if stdout:
output = stdout.decode('utf-8')
if stderr:
output = stderr.decode('utf-8')
test.log(f'Unlock output: {output}')
# wait for keyring to unlock
squish.snooze(1)

if returncode:
return False

return not is_keyring_locked()


def wait_until_keyring_unlocked():
timeout = 5 * 1000
unlocked = squish.waitFor(
lambda: unlock_keyring(), # pylint: disable=unnecessary-lambda
timeout,
)
if not unlocked:
test.fail(f'Timeout. Keyring was not unlocked within {timeout} milliseconds')


def is_keyring_locked():
stdout, stderr, _ = run_sys_command(
[
'busctl',
Expand All @@ -250,63 +286,8 @@ def unlock_keyring():
output = stdout.decode('utf-8')
if stderr:
output = stderr.decode('utf-8')

test.log(f'Keyring status: {output}')
command = 'ps aux | grep keyring | grep -v grep'
stdout, stderr, returncode = run_sys_command(command, True)
pso = ''
if stdout:
pso = stdout.decode('utf-8')
if stderr:
pso = stderr.decode('utf-8')
test.log('PS: -------------------')
test.log(pso)
test.log(':-------------------')

if not output.strip().endswith('false'):
test.log('[INFO] Keyring is locked...')
squish.snooze(5)
# command = 'ps aux | grep dbus | grep -v grep'
# stdout, stderr, returncode = run_sys_command(command, True)
# if stdout:
# output = stdout.decode('utf-8')
# if stderr:
# output = stderr.decode('utf-8')
# test.log(f'dbus ps: {output}')

start_client()
take_screenshot('keyring_locked.png')

password = os.getenv('VNC_PW')
command = f'echo -n "{password}" | gnome-keyring-daemon -r -d --unlock'
stdout, stderr, returncode = run_sys_command(command, True)
if stdout:
output = stdout.decode('utf-8')
if stderr:
output = stderr.decode('utf-8')
test.log(f'unlock: {output}')
squish.snooze(5)
command = 'ps aux | grep keyring | grep -v grep'
stdout, stderr, returncode = run_sys_command(command, True)
if stdout:
output = stdout.decode('utf-8')
if stderr:
output = stderr.decode('utf-8')
test.log('PS: -------------------')
test.log(output)
test.log(':-------------------')

take_screenshot('keyring_unlocked.png')

for ctx in squish.applicationContextList():
# get pid before detaching
pid = ctx.pid
ctx.detach()
wait_until_app_killed(pid)
test.fail('debug')

if returncode:
test.log(f'Failed to unlock keyring:\n{output}')
test.log(f'Keyring Locked: {output}')
return not output.strip().endswith('false')


def run_sys_command(command=None, shell=False):
Expand Down

0 comments on commit abaf2c7

Please sign in to comment.