From 5e6b83d17629fb8e8ae81638b2056a37364ec703 Mon Sep 17 00:00:00 2001 From: Grégoire Détrez Date: Tue, 28 Jun 2022 16:46:42 +0200 Subject: 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. --- sigsum-witness_test.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sigsum-witness_test.py (limited to 'sigsum-witness_test.py') 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) -- cgit v1.2.3