4
4
import time
5
5
import inspect
6
6
from tempfile import mkdtemp
7
- from subprocess import Popen , PIPE , STDOUT
7
+ from subprocess import Popen , PIPE , STDOUT , run
8
8
import pytest
9
9
10
10
from misc import check_recording , mklogfile , mkcfgfile , \
@@ -22,6 +22,25 @@ def utempter_enabled():
22
22
return 'libutempter.so' in stdout_data
23
23
24
24
25
+ @pytest .fixture
26
+ def gen_ssh_key (request ):
27
+ def _del_ssh_key (user ):
28
+ # Remove ssh key to ensure no tests affected later
29
+ run (f'sed -i "/stdin_test/d" ~{ user } /.ssh/authorized_keys' , shell = True )
30
+ run (f'rm -rf ~/.ssh/id_rsa_{ user } *' , shell = True )
31
+
32
+ def _gen_ssh_key (user ):
33
+ # Generate SSH Key for test
34
+ run (f'rm -rf ~/.ssh/id_rsa_{ user } *' , shell = True )
35
+ run (f'ssh-keygen -t rsa -b 2048 -N "" -C stdin_test -f ~/.ssh/id_rsa_{ user } ' , shell = True )
36
+ run (f"mkdir -p ~{ user } /.ssh" , shell = True )
37
+ run (f"cat ~/.ssh/id_rsa_{ user } .pub >> ~{ user } /.ssh/authorized_keys" , shell = True )
38
+ run (f"chown -R { user } :{ user } ~{ user } /.ssh" , shell = True )
39
+ request .addfinalizer (lambda : _del_ssh_key (user ))
40
+
41
+ return _gen_ssh_key
42
+
43
+
25
44
class TestTlogRecSession :
26
45
""" Test tlog-rec-session functionality """
27
46
user = 'tlitestlocaluser2'
@@ -217,10 +236,14 @@ def test_session_record_pipe_io_stdin(self):
217
236
"""
218
237
text_in_stdio = 'print("hello world")\n '
219
238
text_out = "hello world"
220
- p = Popen (['sshpass' , '-p' , 'Secret123' , 'ssh' , '-o' ,
221
- 'StrictHostKeyChecking=no' ,
222
- 'tlitestlocaluser2@localhost' , 'python3' ],
223
- stdout = PIPE , stdin = PIPE , stderr = PIPE , encoding = 'utf8' )
239
+
240
+ sessionclass = TlogRecSessionConfig (writer = "syslog" )
241
+ sessionclass .generate_config (SYSTEM_TLOG_REC_SESSION_CONF )
242
+
243
+ p = Popen (['ssh' , '-i' , f'~/.ssh/id_rsa_{ self .user } ' ,
244
+ '-o' , 'StrictHostKeyChecking=no' ,
245
+ f'{ self .user } @localhost' , 'python3' ],
246
+ stdout = PIPE , stdin = PIPE , stderr = PIPE , encoding = 'utf8' )
224
247
stdout_data = p .communicate (input = text_in_stdio )[0 ]
225
248
assert text_out in stdout_data
226
249
0 commit comments