Skip to content

Commit

Permalink
Test VM => dom0 calls with skip-service-descriptor=true
Browse files Browse the repository at this point in the history
The test currently fails because the command is parsed, the
configuration is loaded, and then a GUI session is waited for if needed.
Then the parsed command is destroyed, and a _new_ parsed command is
created and used for execution, _without_ loading the configuration.

This will be fixed by not destroying and re-parsing the configuration.

The negative diffstat is because the tests had a massive amount of
duplicated code, some of which is now replaced by a common function.
  • Loading branch information
DemiMarie committed Apr 11, 2024
1 parent 7ce4f4e commit e0281de
Showing 1 changed file with 43 additions and 59 deletions.
102 changes: 43 additions & 59 deletions qrexec/tests/socket/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,41 +930,39 @@ def test_run_dom0_service_wait_for_session(self):
self.client.wait()
self.assertEqual(self.client.returncode, 0)

def test_run_dom0_service_socket(self):
socket_path = os.path.join(
self.tempdir, "rpc", "qubes.SocketService+arg"
)
server = qrexec.socket_server(socket_path)
self.addCleanup(server.close)
cmd = "QUBESRPC qubes.SocketService+arg src_domain name src_domain"
source = self.connect_service_request(cmd)

server.accept()
@unittest.expectedFailure
def test_run_dom0_service_socket_no_send_descriptor(self):
"""Socket based service with no service descriptor"""
config_path = os.path.join(self.tempdir, "rpc-config", "qubes.SocketService+arg")
with open(config_path, "w") as f:
f.write("skip-service-descriptor = true\n")
def callback(source, server):
message = b"stdin data"
source.send_message(qrexec.MSG_DATA_STDIN, message)
source.send_message(qrexec.MSG_DATA_STDIN, b"")
self.assertEqual(server.recvall(len(message)), message)

server.sendall(b"stdout data")
server.close()
self._test_run_dom0_service_socket_meta(callback)

expected = b"qubes.SocketService+arg src_domain name src_domain\0"
self.assertEqual(server.recvall(len(expected)), expected)

message = b"stdin data"
source.send_message(qrexec.MSG_DATA_STDIN, message)
source.send_message(qrexec.MSG_DATA_STDIN, b"")
self.assertEqual(server.recvall(len(message)), message)
def test_run_dom0_service_socket(self):
"""Socket based service"""
def callback(source, server):
expected = b"qubes.SocketService+arg src_domain name src_domain\0"
self.assertEqual(server.recvall(len(expected)), expected)

server.sendall(b"stdout data")
server.close()
message = b"stdin data"
source.send_message(qrexec.MSG_DATA_STDIN, message)
source.send_message(qrexec.MSG_DATA_STDIN, b"")
self.assertEqual(server.recvall(len(message)), message)

self.assertEqual(
source.recv_all_messages(),
[
(qrexec.MSG_DATA_STDOUT, b"stdout data"),
(qrexec.MSG_DATA_STDOUT, b""),
(qrexec.MSG_DATA_EXIT_CODE, b"\0\0\0\0"),
],
)
self.client.wait()
self.assertEqual(self.client.returncode, 0)
server.sendall(b"stdout data")
server.close()
self._test_run_dom0_service_socket_meta(callback)

def test_run_dom0_service_socket_no_read(self):
"""Socket based service that don't read its input stream"""
def _test_run_dom0_service_socket_meta(self, callback):
"""Socket based service meta test"""

socket_path = os.path.join(
self.tempdir, "rpc", "qubes.SocketService+arg"
Expand All @@ -975,11 +973,7 @@ def test_run_dom0_service_socket_no_read(self):
source = self.connect_service_request(cmd)

server.accept()
server.sendall(b"stdout data")
server.close()

source.send_message(qrexec.MSG_DATA_STDIN, b"stdin data")
source.send_message(qrexec.MSG_DATA_STDIN, b"")
callback(source, server)

self.assertEqual(
source.recv_all_messages(),
Expand All @@ -992,31 +986,21 @@ def test_run_dom0_service_socket_no_read(self):
self.client.wait()
self.assertEqual(self.client.returncode, 0)

def test_run_dom0_service_socket_no_read(self):
"""Socket based service that don't read its input stream"""
def callback(source, server):
server.sendall(b"stdout data")
server.close()
source.send_message(qrexec.MSG_DATA_STDIN, b"stdin data")
source.send_message(qrexec.MSG_DATA_STDIN, b"")
self._test_run_dom0_service_socket_meta(callback)

def test_run_dom0_service_socket_close(self):
"""Socket service closes connection"""

socket_path = os.path.join(
self.tempdir, "rpc", "qubes.SocketService+arg"
)
server = qrexec.socket_server(socket_path)
self.addCleanup(server.close)
cmd = "QUBESRPC qubes.SocketService+arg src_domain name src_domain"
source = self.connect_service_request(cmd)

server.accept()
server.sendall(b"stdout data")
server.close()

self.assertEqual(
source.recv_all_messages(),
[
(qrexec.MSG_DATA_STDOUT, b"stdout data"),
(qrexec.MSG_DATA_STDOUT, b""),
(qrexec.MSG_DATA_EXIT_CODE, b"\0\0\0\0"),
],
)
self.client.wait()
self.assertEqual(self.client.returncode, 0)
def callback(source, server):
server.sendall(b"stdout data")
server.close()
self._test_run_dom0_service_socket_meta(callback)

def test_run_dom0_service_socket_shutdown_rd(self):
"""Service does shutdown(SHUT_RD)"""
Expand Down

0 comments on commit e0281de

Please sign in to comment.