aboutsummaryrefslogtreecommitdiff
path: root/sigsum-witness_test.py
diff options
context:
space:
mode:
authorGrégoire Détrez <gregoire@mullvad.net>2022-06-28 16:46:42 +0200
committerGrégoire Détrez <gregoire@mullvad.net>2022-06-28 17:28:42 +0200
commit5e6b83d17629fb8e8ae81638b2056a37364ec703 (patch)
treec8e89bb254f3a73122535fb472aa6776b164e0f4 /sigsum-witness_test.py
parentb614c855be543b5acc1873fc13454893b08718ef (diff)
Allow --sigkey-file to be a symlink
Also adds the first tests (using pytest) & a short paragraph to the README on how to run them.
Diffstat (limited to 'sigsum-witness_test.py')
-rw-r--r--sigsum-witness_test.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/sigsum-witness_test.py b/sigsum-witness_test.py
new file mode 100644
index 0000000..3c0241b
--- /dev/null
+++ b/sigsum-witness_test.py
@@ -0,0 +1,66 @@
+import importlib
+
+import pytest
+
+witness = importlib.import_module("sigsum-witness") # To import a module with a '-'
+
+
+class Test_check_sigkeyfile:
+ def test_file_ok(self, tmp_path):
+ path = tmp_path / "key"
+ path.touch(mode=0o700)
+ witness.check_sigkeyfile(path)
+
+ def test_file_notfound(self, tmp_path):
+ path = tmp_path / "key"
+ with pytest.raises(
+ witness.SigKeyFileError,
+ match=f"ERROR: File not found: {path}",
+ ):
+ witness.check_sigkeyfile(path)
+
+ def test_notafile(self, tmp_path):
+ path = tmp_path / "key"
+ path.mkdir()
+ with pytest.raises(
+ witness.SigKeyFileError,
+ match=f"ERROR: Signing key file {path} must be a regular file",
+ ):
+ witness.check_sigkeyfile(path)
+
+ def test_file_badmode(self, tmp_path):
+ path = tmp_path / "key"
+ path.touch(mode=0o755)
+ with pytest.raises(
+ witness.SigKeyFileError,
+ match=f"ERROR: Signing key file {path} permissions too lax: 0755",
+ ):
+ witness.check_sigkeyfile(path)
+
+ def test_symlink_ok(self, tmp_path):
+ filepath = tmp_path / "thekey"
+ filepath.touch(mode=0o700)
+ linkpath = tmp_path / "key"
+ linkpath.symlink_to(filepath)
+ assert witness.check_sigkeyfile(linkpath) is None
+
+ def test_symlink_badmode(self, tmp_path):
+ filepath = tmp_path / "thekey"
+ filepath.touch(mode=0o755)
+ linkpath = tmp_path / "key"
+ linkpath.symlink_to(filepath)
+ with pytest.raises(
+ witness.SigKeyFileError,
+ match=f"ERROR: Signing key file {linkpath} permissions too lax: 0755",
+ ):
+ witness.check_sigkeyfile(linkpath)
+
+ def test_symlink_dangling(self, tmp_path):
+ filepath = tmp_path / "thekey"
+ linkpath = tmp_path / "key"
+ linkpath.symlink_to(filepath)
+ with pytest.raises(
+ witness.SigKeyFileError,
+ match=f"ERROR: File not found: {linkpath}",
+ ):
+ witness.check_sigkeyfile(linkpath)