From 3f66da04121fd7dd7b22a80e8276f03e7a8ef407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 3 Mar 2016 01:07:23 +0100 Subject: [PATCH] tests: add a function for adding qrexec rules QubesOS/qubes-issues#1800 --- tests/__init__.py | 24 ++++++++++++++++++++++++ tests/extra.py | 1 + 2 files changed, 25 insertions(+) create mode 100644 tests/extra.py diff --git a/tests/__init__.py b/tests/__init__.py index 07858aab..c8a31a6b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -424,6 +424,30 @@ class SystemTestsMixin(object): for vmname in vmnames: cls._remove_vm_disk(vmname) + def qrexec_policy(self, service, source, destination, allow=True): + """ + Allow qrexec calls for duration of the test + :param service: service name + :param source: source VM name + :param destination: destination VM name + :return: + """ + + def add_remove_rule(add=True): + with open('/etc/qubes-rpc/policy/{}'.format(service), 'r+') as policy: + policy_rules = policy.readlines() + rule = "{} {} {}\n".format(source, destination, + 'allow' if allow else 'deny') + if add: + policy_rules.insert(0, rule) + else: + policy_rules.remove(rule) + policy.truncate(0) + policy.seek(0) + policy.write(''.join(policy_rules)) + add_remove_rule(add=True) + self.addCleanup(add_remove_rule, add=False) + def wait_for_window(self, title, timeout=30, show=True): """ Wait for a window with a given title. Depending on show parameter, diff --git a/tests/extra.py b/tests/extra.py new file mode 100644 index 00000000..e6b28fd8 --- /dev/null +++ b/tests/extra.py @@ -0,0 +1 @@ +__author__ = 'user'