Skip to content

Commit

Permalink
test: check and unlock keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Sep 23, 2024
1 parent e8071ce commit e200013
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
35 changes: 3 additions & 32 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync
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
from helpers.SetupClientHelper import wait_until_app_killed, unlock_keyring
from helpers.ConfigHelper import (
init_config,
get_config,
Expand All @@ -54,49 +54,20 @@
PREVIOUS_ERROR_RESULT_COUNT = 0


def check_keyring():
res = subprocess.run(
[
"busctl",
"--user",
"get-property",
"org.freedesktop.secrets",
"/org/freedesktop/secrets/collection/login",
"org.freedesktop.Secret.Collection",
"Locked",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
test.log("######## keyring status")
test.log(getpass.getuser())
test.log(str(os.getenv("DBUS_SESSION_BUS_ADDRESS")))
test.log(str(os.getenv("XDG_RUNTIME_DIR")))
test.log(str(res))
if res.stdout:
out = res.stdout.decode("utf-8")
test.log(out)
if res.stderr:
err = res.stderr.decode("utf-8")
test.log(err)
test.log("######## keyring status")


# runs before a feature
# Order: 1
@OnFeatureStart
def hook(context):
init_config()
check_keyring()
unlock_keyring()


# runs before every scenario
# Order: 1
@OnScenarioStart
def hook(context):
clear_scenario_config()
check_keyring()
unlock_keyring()


# runs before every scenario
Expand Down
46 changes: 46 additions & 0 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import uuid
import os
from urllib.parse import urlparse
from os import makedirs
from os.path import exists, join
import test
import psutil
import subprocess
import getpass
import squish

from helpers.SpaceHelper import get_space_id
Expand Down Expand Up @@ -207,3 +210,46 @@ def wait_until_app_killed(pid=0):

def generate_UUIDV4():
return str(uuid.uuid4())


def unlock_keyring():
cmd = subprocess.run(
[
'busctl',
'--user',
'get-property',
'org.freedesktop.secrets',
'/org/freedesktop/secrets/collection/login',
'org.freedesktop.Secret.Collection',
'Locked',
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
output = ''
if cmd.stdout:
output = cmd.stdout.decode('utf-8')
if cmd.stderr:
output = cmd.stderr.decode('utf-8')
output = output.strip()
test.log('-------------------------------------')
test.log(output)
if not output.endswith('false'):
test.log('Unlocking keyring...')
password = os.getenv('VNC_PW')
command = f'echo -n "{password}" | gnome-keyring-daemon -r --unlock'
cmd = subprocess.run(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
if cmd.stdout:
output = cmd.stdout.decode('utf-8')
if cmd.stderr:
output = cmd.stderr.decode('utf-8')
output = output.strip()
test.log(output)
test.log('-------------------------------------')

0 comments on commit e200013

Please sign in to comment.