Skip to content

Commit

Permalink
tests/vm_qrexec_gui: do not swallow stderr on failure
Browse files Browse the repository at this point in the history
QubesVM.run_for_stdio() by default captures stderr. In case of call fail
(non-zero return code), captured stderr is included in the exception
object, but isn't printed by default CalledProcessError message.
Make it visible by:
 - handling CalledProcessError and including in the test failure message
   (when exception is captured already)
 - not capturing stderr (if no exception handling is present in the
   test)

(cherry picked from commit 5423ead)
  • Loading branch information
marmarek committed Apr 18, 2020
1 parent e76de2e commit 4da7e63
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions qubes/tests/integ/vm_qrexec_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ def test_052_qrexec_vm_service_eof(self):
/bin/sh -c 'echo test; exec >&-; cat >&$SAVED_FD_1'
'''.format(self.testvm2.name)),
timeout=10))
except subprocess.CalledProcessError as e:
self.fail('{} exited with non-zero code {}; stderr: {}'.format(
e.cmd, e.returncode, e.stderr))
except asyncio.TimeoutError:
self.fail("Timeout, probably EOF wasn't transferred")

Expand All @@ -262,6 +265,9 @@ def test_053_qrexec_vm_service_eof_reverse(self):
/bin/sh -c 'cat >&$SAVED_FD_1'
'''.format(self.testvm2.name)),
timeout=10))
except subprocess.CalledProcessError as e:
self.fail('{} exited with non-zero code {}; stderr: {}'.format(
e.cmd, e.returncode, e.stderr))
except asyncio.TimeoutError:
self.fail("Timeout, probably EOF wasn't transferred")

Expand Down Expand Up @@ -295,6 +301,9 @@ def test_055_qrexec_dom0_service_abort(self):
e=$(cat /tmp/exit-code);
test $e -eq 141 -o $e -eq 1'''),
timeout=10))
except subprocess.CalledProcessError as e:
self.fail('{} exited with non-zero code {}; stderr: {}'.format(
e.cmd, e.returncode, e.stderr))
except asyncio.TimeoutError:
self.fail("Timeout, probably stdout wasn't closed")

Expand All @@ -316,15 +325,17 @@ def test_065_qrexec_exit_code_vm(self):
(stdout, stderr) = self.loop.run_until_complete(
self.testvm1.run_for_stdio('''\
/usr/lib/qubes/qrexec-client-vm {} test.Retcode;
echo $?'''.format(self.testvm2.name)))
echo $?'''.format(self.testvm2.name),
stderr=None))
self.assertEqual(stdout, b'0\n')

self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Retcode',
'exit 3')
(stdout, stderr) = self.loop.run_until_complete(
self.testvm1.run_for_stdio('''\
/usr/lib/qubes/qrexec-client-vm {} test.Retcode;
echo $?'''.format(self.testvm2.name)))
echo $?'''.format(self.testvm2.name),
stderr=None))
self.assertEqual(stdout, b'3\n')

def test_070_qrexec_vm_simultaneous_write(self):
Expand Down Expand Up @@ -363,8 +374,9 @@ def test_070_qrexec_vm_simultaneous_write(self):
dd of=/dev/null bs=993 count=10000 iflag=fullblock;
wait'
'''.format(self.testvm2.name)), timeout=10))
except subprocess.CalledProcessError:
self.fail('Service call failed')
except subprocess.CalledProcessError as e:
self.fail('{} exited with non-zero code {}; stderr: {}'.format(
e.cmd, e.returncode, e.stderr))
except asyncio.TimeoutError:
self.fail('Timeout, probably deadlock')

Expand Down Expand Up @@ -483,7 +495,8 @@ def test_080_qrexec_service_argument_allow_default(self):
with self.qrexec_policy('test.Argument', self.testvm1, self.testvm2):
stdout, stderr = self.loop.run_until_complete(
self.testvm1.run_for_stdio('/usr/lib/qubes/qrexec-client-vm '
'{} test.Argument+argument'.format(self.testvm2.name)))
'{} test.Argument+argument'.format(self.testvm2.name),
stderr=None))
self.assertEqual(stdout, b'argument')

def test_081_qrexec_service_argument_allow_specific(self):
Expand All @@ -502,7 +515,8 @@ def test_081_qrexec_service_argument_allow_specific(self):
stdout, stderr = self.loop.run_until_complete(
self.testvm1.run_for_stdio(
'/usr/lib/qubes/qrexec-client-vm '
'{} test.Argument+argument'.format(self.testvm2.name)))
'{} test.Argument+argument'.format(self.testvm2.name),
stderr=None))
self.assertEqual(stdout, b'argument')

def test_082_qrexec_service_argument_deny_specific(self):
Expand All @@ -521,7 +535,8 @@ def test_082_qrexec_service_argument_deny_specific(self):
self.loop.run_until_complete(
self.testvm1.run_for_stdio(
'/usr/lib/qubes/qrexec-client-vm {} '
'test.Argument+argument'.format(self.testvm2.name)))
'test.Argument+argument'.format(self.testvm2.name),
stderr=None))

def test_083_qrexec_service_argument_specific_implementation(self):
"""Qrexec service call with argument - argument specific
Expand All @@ -540,7 +555,8 @@ def test_083_qrexec_service_argument_specific_implementation(self):
with self.qrexec_policy('test.Argument', self.testvm1, self.testvm2):
stdout, stderr = self.loop.run_until_complete(
self.testvm1.run_for_stdio('/usr/lib/qubes/qrexec-client-vm '
'{} test.Argument+argument'.format(self.testvm2.name)))
'{} test.Argument+argument'.format(self.testvm2.name),
stderr=None))

self.assertEqual(stdout, b'specific: argument')

Expand All @@ -557,7 +573,8 @@ def test_084_qrexec_service_argument_extra_env(self):
with self.qrexec_policy('test.Argument', self.testvm1, self.testvm2):
stdout, stderr = self.loop.run_until_complete(
self.testvm1.run_for_stdio('/usr/lib/qubes/qrexec-client-vm '
'{} test.Argument+argument'.format(self.testvm2.name)))
'{} test.Argument+argument'.format(self.testvm2.name),
stderr=None))

self.assertEqual(stdout, b'test.Argument+argument argument')

Expand Down

0 comments on commit 4da7e63

Please sign in to comment.