Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,100 +299,100 @@ def mailcap_hardened(self) -> None:


class Test_SD_VM_Common:
def test_vm_config_keys(self, qube: QubeWrapper) -> None:
def test_vm_config_keys(self, tested_qube: QubeWrapper) -> None:
"""Every VM should check that it has only the configuration keys it
expects.
"""
qube.vm_config_check(qube.expected_config_keys)
tested_qube.vm_config_check(tested_qube.expected_config_keys)

def test_lsm_enabled(self, qube: QubeWrapper) -> None:
def test_lsm_enabled(self, tested_qube: QubeWrapper) -> None:
"""Check that the expected LSM is enabled"""
if qube.linux_security_modules == "apparmor":
assert qube.package_is_installed("apparmor")
if tested_qube.linux_security_modules == "apparmor":
assert tested_qube.package_is_installed("apparmor")
# returns error code if AppArmor not enabled
qube.run("sudo aa-status --enabled")
elif qube.linux_security_modules == "selinux":
sestatus = qube.run("sudo sestatus")
tested_qube.run("sudo aa-status --enabled")
elif tested_qube.linux_security_modules == "selinux":
sestatus = tested_qube.run("sudo sestatus")
assert "SELinux status: enabled\n" in sestatus
assert "Current mode: enforcing\n" in sestatus
else:
raise ValueError(f"Unsupported LSM: {qube.linux_security_modules}")
raise ValueError(f"Unsupported LSM: {tested_qube.linux_security_modules}")

def test_enforced_apparmor_profiles(self, qube: QubeWrapper) -> None:
def test_enforced_apparmor_profiles(self, tested_qube: QubeWrapper) -> None:
"""Check the expected AppArmor profiles are enforced"""
if not qube.enforced_apparmor_profiles:
pytest.skip(f"No enforced AppArmor profiles in {qube.name}")
if not tested_qube.enforced_apparmor_profiles:
pytest.skip(f"No enforced AppArmor profiles in {tested_qube.name}")

results = json.loads(qube.run("sudo aa-status --json"))
for profile in qube.enforced_apparmor_profiles:
results = json.loads(tested_qube.run("sudo aa-status --json"))
for profile in tested_qube.enforced_apparmor_profiles:
assert results["profiles"][profile] == "enforce"

def test_grsec_kernel(self, qube: QubeWrapper) -> None:
def test_grsec_kernel(self, tested_qube: QubeWrapper) -> None:
"""
Confirms expected grsecurity-patched kernel is running.
"""
# base doesn't have kernel configured
exceptions = [SD_TEMPLATE_BASE, "sys-usb"]

if qube.vm.name in exceptions:
pytest.skip(f"Skipping grsec test on VM: '{qube.vm.name}'")
if tested_qube.vm.name in exceptions:
pytest.skip(f"Skipping grsec test on VM: '{tested_qube.vm.name}'")

# Running custom kernel in PVH mode requires pvgrub2-pvh
assert qube.vm.virt_mode == "pvh"
assert qube.vm.kernel == "pvgrub2-pvh"
assert tested_qube.vm.virt_mode == "pvh"
assert tested_qube.vm.kernel == "pvgrub2-pvh"

# Check running kernel is grsecurity-patched
stdout = qube.run("uname -r")
stdout = tested_qube.run("uname -r")
assert stdout.endswith("-grsec-workstation")
qube.service_is_active("paxctld")
tested_qube.service_is_active("paxctld")

def test_debian_platform_version(self, qube: QubeWrapper) -> None:
def test_debian_platform_version(self, tested_qube: QubeWrapper) -> None:
"""
Asserts that the given AppVM is based on an OS listed in the
SUPPORTED_<XX>_PLATFORMS list, as specified in tests.
All workstation-provisioned VMs should be based on DEBIAN_CODENAME.
"""

if qube.name.startswith("sys-"):
pytest.skip(f"skipping Debian platform check on QubesOS sys VM: {qube.name}")
if tested_qube.name.startswith("sys-"):
pytest.skip(f"skipping Debian platform check on QubesOS sys VM: {tested_qube.name}")

stdout = qube.run("cat /etc/os-release")
stdout = tested_qube.run("cat /etc/os-release")
search = re.search(r'^PRETTY_NAME="(.*)"', stdout)
if not search:
raise RuntimeError(f"Unable to determine platform for {qube.name}")
raise RuntimeError(f"Unable to determine platform for {tested_qube.name}")
platform = search.group(1)
assert DEBIAN_CODENAME in platform

@pytest.mark.mime
@pytest.mark.slow
@pytest.mark.configuration
def test_mime_types(self, qube: QubeWrapper) -> None:
def test_mime_types(self, tested_qube: QubeWrapper) -> None:
"""
Functionally verifies that the VM config handles specific filetypes correctly,
opening them with the appropriate program.
"""
if not qube.mime_types_handling:
pytest.skip(f"MIME types handling not enabled for {qube.name}")
if not tested_qube.mime_types_handling:
pytest.skip(f"MIME types handling not enabled for {tested_qube.name}")

for mime_type, expected_app in get_mimeapp_vars_for_vm(qube.mime_vars_vm_name):
actual_app = qube.run(f"xdg-mime query default {mime_type}")
for mime_type, expected_app in get_mimeapp_vars_for_vm(tested_qube.mime_vars_vm_name):
actual_app = tested_qube.run(f"xdg-mime query default {mime_type}")
assert (
actual_app == expected_app
), f"MIME type {mime_type}: expected {expected_app}, got {actual_app}"

@pytest.mark.skip(reason="Broken in CI. Tracked as #1579")
def test_mock_device_attach_deny(
self, qube: QubeWrapper, mock_block_device: str, qubesd_log: Iterator[str]
self, tested_qube: QubeWrapper, mock_block_device: str, qubesd_log: Iterator[str]
) -> None:
if qube.name == "sys-usb":
if tested_qube.name == "sys-usb":
pytest.skip("Test does not run on 'sys-usb' (no need to attach devices to itself)")
if qube.devices_attachable:
if tested_qube.devices_attachable:
pytest.skip("On this qube device attachment is not denied")

# Device attachment expected to fail (generic qubes)
with pytest.raises(subprocess.CalledProcessError) as exc_info:
subprocess.check_output(
["qvm-block", "attach", qube.name, mock_block_device],
["qvm-block", "attach", tested_qube.name, mock_block_device],
stderr=subprocess.STDOUT, # Capture qubesd error message
text=True,
)
Expand All @@ -405,7 +405,7 @@ def test_mock_device_attach_deny(
r"WARNING: permission denied for call "
r"b'admin.vm.device.block.Attach'\+b'{device_id}\+\+\d+' "
r"\(b'dom0' → b'{target_qube}'\)"
).format(device_id=mock_block_device.replace(":", r"\+"), target_qube=qube.name)
).format(device_id=mock_block_device.replace(":", r"\+"), target_qube=tested_qube.name)
)

# Exactly one policy denial match
Expand Down
32 changes: 17 additions & 15 deletions tests/test_vm_sd_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.fixture(scope="module")
def qube() -> QubeWrapper:
def tested_qube() -> QubeWrapper:
return QubeWrapper(
"sd-app",
expected_config_keys={
Expand All @@ -34,8 +34,8 @@ def qube() -> QubeWrapper:


@pytest.mark.configuration
def test_open_in_dvm_desktop(qube: QubeWrapper) -> None:
contents = qube.get_file_contents("/usr/share/applications/open-in-dvm.desktop")
def test_open_in_dvm_desktop(tested_qube: QubeWrapper) -> None:
contents = tested_qube.get_file_contents("/usr/share/applications/open-in-dvm.desktop")
expected_contents = [
"TryExec=/usr/bin/qvm-open-in-vm",
"Exec=/usr/bin/qvm-open-in-vm --view-only @dispvm:sd-viewer %f",
Expand All @@ -45,28 +45,30 @@ def test_open_in_dvm_desktop(qube: QubeWrapper) -> None:


@pytest.mark.configuration
def test_mailcap_hardened(qube: QubeWrapper) -> None:
qube.mailcap_hardened()
def test_mailcap_hardened(tested_qube: QubeWrapper) -> None:
tested_qube.mailcap_hardened()


@pytest.mark.configuration
def test_sd_app_package_installed(qube: QubeWrapper) -> None:
assert qube.package_is_installed("securedrop-app")
def test_sd_app_package_installed(tested_qube: QubeWrapper) -> None:
assert tested_qube.package_is_installed("securedrop-app")
# And the client has been removed
assert not qube.package_is_installed("securedrop-client")
assert not tested_qube.package_is_installed("securedrop-client")


@pytest.mark.provisioning
def test_sd_client_config(dom0_config: Dom0Config, qube: QubeWrapper) -> None:
assert dom0_config.submission_key_fpr == qube.vm_config_read("SD_SUBMISSION_KEY_FPR")
def test_sd_client_config(dom0_config: Dom0Config, tested_qube: QubeWrapper) -> None:
assert dom0_config.submission_key_fpr == tested_qube.vm_config_read("SD_SUBMISSION_KEY_FPR")


@pytest.mark.provisioning
def test_logging_configured(qube: QubeWrapper) -> None:
qube.logging_configured()
def test_logging_configured(tested_qube: QubeWrapper) -> None:
tested_qube.logging_configured()


def test_sd_app_config(dom0_config: Dom0Config, qube: QubeWrapper, all_vms: VMCollection) -> None:
def test_sd_app_config(
dom0_config: Dom0Config, tested_qube: QubeWrapper, all_vms: VMCollection
) -> None:
vm = all_vms["sd-app"]
nvm = vm.netvm
assert nvm is None
Expand All @@ -86,7 +88,7 @@ def test_sd_app_config(dom0_config: Dom0Config, qube: QubeWrapper, all_vms: VMCo
# MIME handling
assert vm.features["service.securedrop-mime-handling"] == "1"
assert vm.features["vm-config.SD_MIME_HANDLING"] == "sd-app"
assert qube.service_is_active("securedrop-mime-handling")
assert tested_qube.service_is_active("securedrop-mime-handling")

# Arti should *not* be running
assert not qube.service_is_active("securedrop-arti")
assert not tested_qube.service_is_active("securedrop-arti")
22 changes: 12 additions & 10 deletions tests/test_vm_sd_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pytestmark = needs_journalist

# NOTE: this file needs includes tests for the functionally similar 'sd-devices'
# and 'sd-printers'. Some tests overlap (tested on both through the 'qube' fixture)
# and 'sd-printers'. Some tests overlap (tested on both through the 'tested_qube' fixture)
# and some only happen in one VM. In this last case dedicated qube fixtures are used
_qube_kwargs = {
"sd-devices": {
Expand Down Expand Up @@ -65,14 +65,16 @@ def qube_sd_printers(qube_factory: Callable[[str], QubeWrapper]) -> QubeWrapper:

# Parameterize: tests calling this fixture will run for each qube
@pytest.fixture(scope="module", params=list(_qube_kwargs))
def qube(request: pytest.FixtureRequest, qube_factory: Callable[[str], QubeWrapper]) -> QubeWrapper:
def tested_qube(
request: pytest.FixtureRequest, qube_factory: Callable[[str], QubeWrapper]
) -> QubeWrapper:
return qube_factory(request.param) # returns a fixture for each qube


def test_files_are_properly_copied(qube: QubeWrapper) -> None:
assert qube.fileExists("/usr/bin/send-to-usb")
assert qube.fileExists("/usr/share/applications/send-to-usb.desktop")
assert qube.fileExists("/usr/share/mime/packages/application-x-sd-export.xml")
def test_files_are_properly_copied(tested_qube: QubeWrapper) -> None:
assert tested_qube.fileExists("/usr/bin/send-to-usb")
assert tested_qube.fileExists("/usr/share/applications/send-to-usb.desktop")
assert tested_qube.fileExists("/usr/share/mime/packages/application-x-sd-export.xml")


def test_sd_export_package_installed(qube_sd_devices: QubeWrapper) -> None:
Expand All @@ -81,12 +83,12 @@ def test_sd_export_package_installed(qube_sd_devices: QubeWrapper) -> None:
assert qube_sd_devices.package_is_installed("gnome-disk-utility")


def test_logging_configured(qube: QubeWrapper) -> None:
qube.logging_configured()
def test_logging_configured(tested_qube: QubeWrapper) -> None:
tested_qube.logging_configured()


def test_mailcap_hardened(qube: QubeWrapper) -> None:
qube.mailcap_hardened()
def test_mailcap_hardened(tested_qube: QubeWrapper) -> None:
tested_qube.mailcap_hardened()


def test_open_in_dvm_desktop(qube_sd_devices: QubeWrapper) -> None:
Expand Down
38 changes: 20 additions & 18 deletions tests/test_vm_sd_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@pytest.fixture(scope="module")
def qube() -> QubeWrapper:
def tested_qube() -> QubeWrapper:
return QubeWrapper("sd-gpg")


Expand Down Expand Up @@ -60,24 +60,24 @@ def dom0_fingerprint() -> list[str]:


@pytest.fixture
def vm_fingerprint(qube: QubeWrapper) -> list[str]:
def vm_fingerprint(tested_qube: QubeWrapper) -> list[str]:
"""
Obtain fingerprints for all keys actually present in GPG VM
"""
remote_results = qube.run("/usr/bin/gpg --list-secret-keys")
remote_results = tested_qube.run("/usr/bin/gpg --list-secret-keys")
return _extract_fingerprints(remote_results)


@pytest.mark.configuration
def test_sd_gpg_timeout(qube: QubeWrapper) -> None:
assert "QUBES_GPG_AUTOACCEPT=2147483647" in qube.run("env")
def test_sd_gpg_timeout(tested_qube: QubeWrapper) -> None:
assert "QUBES_GPG_AUTOACCEPT=2147483647" in tested_qube.run("env")


def test_sd_gpg_timeout_not_in_home_profile(qube: QubeWrapper) -> None:
def test_sd_gpg_timeout_not_in_home_profile(tested_qube: QubeWrapper) -> None:
"""This is mostly a test against lingering state"""
if qube.vm.klass == "DispVM":
if tested_qube.vm.klass == "DispVM":
pytest.fail("Test may no longer be needed")
assert "QUBES_GPG_AUTOACCEPT" not in qube.run("cat /home/user/.profile")
assert "QUBES_GPG_AUTOACCEPT" not in tested_qube.run("cat /home/user/.profile")


@pytest.mark.configuration
Expand All @@ -94,7 +94,9 @@ def test_local_key_in_remote_keyring(


@pytest.mark.configuration
def test_local_key_in_remote_keyring_clean(qube: QubeWrapper, config_fingerprint: str) -> None:
def test_local_key_in_remote_keyring_clean(
tested_qube: QubeWrapper, config_fingerprint: str
) -> None:
"""
Confirm key presence in sd-gpg, but simulate clean environment.

Expand All @@ -103,28 +105,28 @@ def test_local_key_in_remote_keyring_clean(qube: QubeWrapper, config_fingerprint
there from before or if it was in fact placed there by the workstation version
under testing.
"""
if qube.vm.klass == "DispVM":
if tested_qube.vm.klass == "DispVM":
# This condition is just a note for developers
pytest.fail("Test can be removed, as we no longer need to test against clean slate")

tmp_dir = qube.run("mktemp -d")
qube.run(f"GNUPGHOME={tmp_dir} securedrop-get-secret-keys")
tmp_dir = tested_qube.run("mktemp -d")
tested_qube.run(f"GNUPGHOME={tmp_dir} securedrop-get-secret-keys")
vm_fingerprints = _extract_fingerprints(
qube.run(f"GNUPGHOME={tmp_dir} /usr/bin/gpg --list-secret-keys")
tested_qube.run(f"GNUPGHOME={tmp_dir} /usr/bin/gpg --list-secret-keys")
)
assert vm_fingerprints == [config_fingerprint]


@pytest.mark.configuration
def test_logging_disabled(qube: QubeWrapper) -> None:
def test_logging_disabled(tested_qube: QubeWrapper) -> None:
# Logging to sd-log should be disabled on sd-gpg
assert not qube.fileExists("/etc/rsyslog.d/sdlog.conf")
assert qube.fileExists("/var/run/qubes-service/securedrop-logging-disabled")
assert not tested_qube.fileExists("/etc/rsyslog.d/sdlog.conf")
assert tested_qube.fileExists("/var/run/qubes-service/securedrop-logging-disabled")


@pytest.mark.configuration
def test_sd_gpg_services(qube: QubeWrapper) -> None:
assert qube.service_is_active("securedrop-get-secret-keys")
def test_sd_gpg_services(tested_qube: QubeWrapper) -> None:
assert tested_qube.service_is_active("securedrop-get-secret-keys")


@pytest.mark.provisioning
Expand Down
Loading
Loading