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'