Skip to content

Commit 92da313

Browse files
fmoessbauerjan-kiszka
authored andcommitted
add test for setup and forward of SSH agent
This patch adds a test for forwarding an external ssh agent, as well as an invalid combination of the external and internal ssh agent. Signed-off-by: Felix Moessbauer <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent b1d8f47 commit 92da313

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
'KAS_MACHINE',
3131
'KAS_TARGET',
3232
'KAS_TASK',
33-
'KAS_PREMIRRORS'
33+
'KAS_PREMIRRORS',
34+
'SSH_AUTH_SOCK',
3435
]
3536

3637

tests/test_environment_variables.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import shutil
2626
import pathlib
2727
import re
28+
import pytest
2829
from kas import kas
30+
from kas.kasusererror import ArgsCombinationError
2931

3032

3133
def test_build_dir_is_placed_inside_work_dir_by_default(monkeykas, tmpdir):
@@ -51,6 +53,36 @@ def test_build_dir_can_be_specified_by_environment_variable(monkeykas, tmpdir):
5153
assert os.path.exists(os.path.join(build_dir, 'conf'))
5254

5355

56+
def test_ssh_agent_setup(monkeykas, tmpdir):
57+
conf_dir = str(tmpdir / 'test_ssh_agent_setup')
58+
shutil.copytree('tests/test_environment_variables', conf_dir)
59+
monkeykas.chdir(conf_dir)
60+
61+
SSH_AUTH_SOCK = '/tmp/ssh-KLTafE/agent.64708'
62+
63+
with monkeykas.context() as mp:
64+
envfile = tmpdir / 'env'
65+
mp.setenv('SSH_AUTH_SOCK', SSH_AUTH_SOCK)
66+
kas.kas(['shell', '-c', f'env > {envfile}', 'test.yml'])
67+
env = _get_env_from_file(envfile)
68+
assert env['SSH_AUTH_SOCK'] == SSH_AUTH_SOCK
69+
70+
with monkeykas.context() as mp:
71+
mp.setenv('SSH_AUTH_SOCK', SSH_AUTH_SOCK)
72+
mp.setenv('SSH_PRIVATE_KEY', 'id_rsa')
73+
with pytest.raises(ArgsCombinationError):
74+
kas.kas(['checkout', 'test.yml'])
75+
76+
77+
def _get_env_from_file(filename):
78+
env = {}
79+
with filename.open() as f:
80+
for line in f.readlines():
81+
key, val = line.split("=", 1)
82+
env[key] = val.strip()
83+
return env
84+
85+
5486
def _test_env_section_export(monkeykas, tmpdir, bb_env_var, bb_repo):
5587
conf_dir = pathlib.Path(str(tmpdir / 'test_env_variables'))
5688
env_out = conf_dir / 'env_out'
@@ -79,11 +111,7 @@ def _test_env_section_export(monkeykas, tmpdir, bb_env_var, bb_repo):
79111
kas.kas(['shell', '-c', 'bitbake -e > %s' % bb_env_out, 'test_env.yml'])
80112

81113
# Check kas environment
82-
test_env = {}
83-
with env_out.open() as f:
84-
for line in f.readlines():
85-
key, val = line.split("=", 1)
86-
test_env[key] = val.strip()
114+
test_env = _get_env_from_file(env_out)
87115

88116
# Variables with 'None' assigned should not be added to environment
89117
try:

0 commit comments

Comments
 (0)