Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SecureDrop workstation to support 4.2 and use an install-time base template. #970

Merged
merged 13 commits into from
Apr 9, 2024
Merged
47 changes: 5 additions & 42 deletions tests/test_qubes_rpc.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
import io
import os
import unittest
import yaml


# TODO: update for new policy format/layout
# TODO: add actual integration testing of policies
class SD_Qubes_Rpc_Tests(unittest.TestCase):
def setUp(self):
self.expected = self._loadVars()

def tearDown(self):
pass

def test_Policies(self):
# Using a for loop instead of pytest.parametrize due to
# the absence of pytest in dom0.
fail = False
for policy in self.expected:
if not self._startsWith(policy["policy"], policy["starts_with"]):
fail = True
self.assertFalse(fail), "Policy does not match: " + policy["policy"]

def _startsWith(self, filename, expectedPolicy):
filePath = filename
# The Qubes 4.0 grants assumed all policies were in the same dir.
# Support that for backwards-compatibility on 4.0, but we'll use
# absolute paths in the test vars from 4.1 onward.
if not filePath.startswith("/"):
filePath = os.path.join("/etc/qubes-rpc/policy", filename)

with io.open(filePath, "r") as f:
actualPolicy = f.read()
if actualPolicy.startswith(expectedPolicy):
return True
else:
print("\n\n#### BEGIN RPC policy error report ####\n\n")
print("Policy for {} is:\n{}".format(filename, actualPolicy))
print("Policy for {} should be:\n{}".format(filename, expectedPolicy))
print("\n\n#### END RPC policy error report ####\n\n")
return False

def _loadVars(self):
filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "vars", "qubes-rpc.yml")
with io.open(filepath, "r") as f:
data = yaml.safe_load(f)
return data
def test_policies(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good first step IMO

"""verify the policies are installed"""
assert os.path.exists("/etc/qubes/policy.d/70-securedrop-workstation.policy")
assert os.path.exists("/etc/qubes/policy.d/60-securedrop-workstation.policy")


def load_tests(loader, tests, pattern):
Expand Down
135 changes: 0 additions & 135 deletions tests/vars/qubes-rpc.yml

This file was deleted.