44"""
55
66__author__ = 'Agnieszka Bylica, Marcin Usielski'
7- __copyright__ = 'Copyright (C) 2018-2023 , Nokia'
7+ __copyright__ = 'Copyright (C) 2018-2025 , Nokia'
8899
1010import pytest
@@ -66,6 +66,28 @@ def test_sudo_su(buffer_connection):
6666 assert ret == expected_dict
6767
6868
69+ def test_sudo_su_twice_failed_object (buffer_connection ):
70+ from moler .cmd .unix .sudo import Sudo
71+ from moler .cmd .unix .rm import Rm
72+ from moler .exceptions import CommandFailure
73+ rm_output_denied = """rm important_file.txt
74+ rm: cannot remove 'important_file.txt': Permission denied
75+ moler_bash#"""
76+
77+ buffer_connection .remote_inject_response ([rm_output_denied ])
78+
79+ cmd_rm = Rm (connection = buffer_connection .moler_connection , file = "important_file.txt" )
80+ with pytest .raises (CommandFailure ):
81+ cmd_rm ()
82+
83+ cmd_su = Su (connection = buffer_connection .moler_connection , prompt = r"moler_bash#" ,
84+ cmd_object = cmd_rm )
85+ cmd_sudo = Sudo (connection = buffer_connection .moler_connection , cmd_object = cmd_su )
86+ with pytest .raises (CommandFailure ) as exc :
87+ cmd_sudo ()
88+ assert "Not allowed to run again" in str (exc .value )
89+
90+
6991def test_sudo_su_object (buffer_connection , command_output_and_expected_result_ls_l ):
7092 from moler .cmd .unix .sudo import Sudo
7193 from moler .cmd .unix .ls import Ls
@@ -129,7 +151,7 @@ def test_su_catches_missing_binary_failure(buffer_connection):
129151@pytest .fixture
130152def command_output_and_expected_result_auth ():
131153 output = """xyz@debian:~/Moler$ su
132- Password:
154+ Password:
133155su: Authentication failure
134156xyz@debian:~/Moler$"""
135157 result = dict ()
@@ -138,7 +160,7 @@ def command_output_and_expected_result_auth():
138160
139161@pytest .fixture
140162def command_output_and_expected_result_command_format_failure ():
141- output = """xyz@debian:~/Moler$ su -g
163+ output = """xyz@debian:~/Moler$ su -g
142164su: invalid option -- 'g'
143165Usage: su [options] [LOGIN]
144166
@@ -201,7 +223,7 @@ def command_output_and_expected_result_ls_l():
201223@pytest .fixture ()
202224def command_output_and_expected_result_pwd ():
203225 output = """user@client:~/moler$ su -c 'pwd'
204- password:
226+ password:
205227/home/user/moler
206228ute@debdev:~/moler$ """
207229 result = {
0 commit comments