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

Installs mimetype handlers for SVS DispVM via package #201

Merged
merged 2 commits into from
Nov 11, 2018
Merged
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
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ remove-sd-gpg: assert-dom0 ## Destroys SD GPG keystore VM
clean: assert-dom0 destroy-all clean-salt ## Destroys all SD VMs

test: assert-dom0 ## Runs all application tests (no integration tests yet)
python -m unittest discover tests
python3 -m unittest discover -v tests

test-base: assert-dom0 ## Runs tests for VMs layout
python -m unittest -v tests.test_vms_exist.SD_VM_Tests
python3 -m unittest -v tests.test_vms_exist.SD_VM_Tests

test-svs: assert-dom0 ## Runs tests for SD SVS VM config
python -m unittest -v tests.test_svs.SD_SVS_Tests
python3 -m unittest -v tests.test_svs.SD_SVS_Tests

test-journalist: assert-dom0 ## Runs tests for SD Journalist VM
python -m unittest -v tests.test_journalist_vm
python3 -m unittest -v tests.test_journalist_vm

test-whonix: assert-dom0 ## Runs tests for SD Whonix VM
python -m unittest -v tests.test_sd_whonix
python3 -m unittest -v tests.test_sd_whonix

test-gpg: assert-dom0 ## Runs tests for SD GPG functionality
python -m unittest -v tests.test_gpg
python3 -m unittest -v tests.test_gpg

validate: assert-dom0 ## Checks for local requirements in dev env
@bash -c "test -e config.json" || \
Expand Down
20 changes: 10 additions & 10 deletions dom0/sd-svs-disp-files.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# sd-svs-disp-files
# ========
#
# Moves files into place on sd-svs-disp
# Installs configuration packages specific to the SVS DispVM,
# used for opening submissions.
#
##

sd-svs-disp-write-mimetyeps:
file.managed:
- name: /usr/share/applications/mimeapps.list
- source: salt://sd/sd-svs/mimeapps-sd-svs-disp.list
- user: root
- group: root
- mode: 644
include:
- fpf-apt-test-repo

sudo update-mime-database /usr/share/mime:
cmd.run
sd-svs-disp-install-mimetype-handler-package:
pkg.installed:
- pkgs:
- securedrop-workstation-svs-disp
require:
- sls: fpf-apt-test-repo
1 change: 1 addition & 0 deletions dom0/sd-svs-disp-files.top
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

base:
sd-svs-disp-template:
- fpf-apt-test-repo
- sd-svs-disp-files
2 changes: 0 additions & 2 deletions sd-svs/mimeapps-sd-svs-disp.list

This file was deleted.

Empty file added tests/__init__.py
Empty file.
7 changes: 4 additions & 3 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def _reboot(self):
self.vm.start()

def _get_file_contents(self, path):
contents = subprocess.check_output(["qvm-run", "-p", self.vm_name,
"/bin/cat {}".format(path)])
cmd = ["qvm-run", "-p", self.vm_name,
"/bin/cat {}".format(path)]
contents = subprocess.check_output(cmd).decode("utf-8")
return contents

def _package_is_installed(self, pkg):
Expand All @@ -79,7 +80,7 @@ def assertFilesMatch(self, remote_path, local_path):
with open(local_path) as f:
content = f.read()
import difflib
print("".join(difflib.unified_diff(remote_content, content)))
print("".join(difflib.unified_diff(remote_content, content)), end="")
self.assertTrue(remote_content == content)

def assertFileHasLine(self, remote_path, wanted_line):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def find_fp_from_gpg_output(gpg):

lines = gpg.split("\n")
lines = gpg.decode("utf-8").split("\n")

for line in lines:
# dom0 uses Fedora25 with gpg 1.4.22, whereas AppVMs
Expand Down
10 changes: 10 additions & 0 deletions tests/test_svs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def test_sd_client_package_installed(self):
self.assertTrue(self._package_is_installed("securedrop-client"))


class SD_SVS_Disp_Tests(SD_VM_Local_Test):
def setUp(self):
self.vm_name = "sd-svs-disp"
super(SD_SVS_Disp_Tests, self).setUp()

def test_sd_client_package_installed(self):
pkg = "securedrop-workstation-svs-disp"
self.assertTrue(self._package_is_installed(pkg))


def load_tests(loader, tests, pattern):
suite = unittest.TestLoader().loadTestsFromTestCase(SD_SVS_Tests)
return suite
5 changes: 2 additions & 3 deletions tests/test_vms_exist.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def _check_kernel(self, vm):
self.assertTrue(vm.kernel == "")

# Check exact kernel version in VM
raw_output = vm.run("uname -r")
# Response is a tuple of e.g. ('4.14.74-grsec\n', '')
kernel_version = raw_output[0].rstrip()
stdout, stderr = vm.run("uname -r")
kernel_version = stdout.decode("utf-8").rstrip()
assert kernel_version.endswith("-grsec")
assert kernel_version == EXPECTED_KERNEL_VERSION

Expand Down
8 changes: 4 additions & 4 deletions tests/test_vms_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_platform_info(self, vm):
# let's maintain the default config and retrieve the value elsewise.
cmd = "perl -nE '/^PRETTY_NAME=\"(.*)\"$/ and say $1' /etc/os-release"
stdout, stderr = vm.run(cmd)
platform = stdout.rstrip("\n")
platform = stdout.decode("utf-8").rstrip("\n")
return platform

def _validate_vm_platform(self, vm):
Expand All @@ -47,7 +47,7 @@ def _ensure_packages_up_to_date(self, vm, fedora=False):
if not fedora:
cmd = "apt list --upgradable"
stdout, stderr = vm.run(cmd)
results = stdout.rstrip()
results = stdout.rstrip().decode("utf-8")
# `apt list` will always print "Listing..." to stdout,
# so expect only that string.
self.assertEqual(results, "Listing...")
Expand All @@ -56,7 +56,7 @@ def _ensure_packages_up_to_date(self, vm, fedora=False):
# Will raise CalledProcessError if updates available
stdout, stderr = vm.run(cmd)
# 'stdout' will contain timestamped progress info; ignore it
results = stderr.rstrip()
results = stderr.rstrip().decode("utf-8")
self.assertEqual(results, "")

def test_all_sd_vms_uptodate(self):
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_dispvm_default_platform(self):
test because DispVMs may not be running at present.
"""
cmd = ["qubes-prefs", "default_dispvm"]
result = subprocess.check_output(cmd).rstrip("\n")
result = subprocess.check_output(cmd).decode("utf-8").rstrip("\n")
self.assertEqual(result, "fedora-28-dvm")


Expand Down