def test_path_not_writeable(self, tmpdir, caplog): e = PyEncfs("--paranoia") assert e._createpath(tmpdir + "/userdir") os.chmod(str(tmpdir + "/userdir"), 0o000) assert not e._createpath(tmpdir + "/userdir/dir") self.assert_logging(1, "ERROR", caplog) assert "Failed to create path" in caplog.text
def test_allready_mounted_directory(self, tmpdir, caplog): e = PyEncfs("--paranoia") assert e.create(tmpdir + "/e", tmpdir + "/d", "PASSWORD") assert not e._createpath(tmpdir + "/d") self.assert_logging(1, "ERROR", caplog) assert "Path is a mount point" in caplog.text assert e.umount(tmpdir + "/d")
def test_spaces_in_file_names(self, tmpdir, caplog): e = PyEncfs("--paranoia") d = tmpdir + "/created path with spaces" assert e._createpath(d) assert os.path.isdir(str(d)) self.assert_logging(0, "ERROR", caplog) assert "Using existing empty directory" not in caplog.text
def test_valid_multi_level_creation(self, tmpdir, caplog): e = PyEncfs("--paranoia") d = tmpdir + "/created_path/a/b/c/d/e/f/" assert e._createpath(d) assert os.path.isdir(str(d)) self.assert_logging(0, "ERROR", caplog) assert "Using existing empty directory" not in caplog.text
def test_failed_subprocess_run(self, tmpdir, caplog): e = PyEncfs("--paranoia") assert e._createpath(tmpdir + "/e") assert e._createpath(tmpdir + "/d") with mock.patch("subprocess.run", mock.MagicMock(return_value=True)): assert not e.mount(tmpdir + "/e", tmpdir + "/d", "PASSWORD") assert "Failed to detect valid mount point at" in caplog.text
def test_path_is_file(self, tmpdir, caplog): e = PyEncfs("--paranoia") open(str(tmpdir + "/nodir"), "w+") assert not e._createpath(tmpdir + "/nodir") self.assert_logging(1, "ERROR", caplog) assert "is not a directory" in caplog.text
def test_non_empty_directory(self, tmpdir, caplog): e = PyEncfs("--paranoia") open(str(tmpdir + "/foo.txt"), "w+") assert not e._createpath(tmpdir) self.assert_logging(1, "ERROR", caplog) assert "Given path is not empty" in caplog.text
def test_empty_directory(self, tmpdir, caplog): caplog.set_level(logging.DEBUG) e = PyEncfs("--paranoia") assert e._createpath(tmpdir) self.assert_logging(0, "ERROR", caplog) assert "Using existing empty directory" in caplog.text
def test_encryption_directory_is_file(self, tmpdir, caplog): e = PyEncfs("--paranoia") assert e._createpath(tmpdir + "/d") open(str(tmpdir + "/e"), "w+") assert not e.mount(tmpdir + "/e", tmpdir + "/d", "PASSWORD") assert "Failed to mount encfs file system" in caplog.text
def test_encfs_mount_subprocess_failure(self, tmpdir): e = PyEncfs("--paranoia") assert e._createpath(tmpdir + "/e") assert e._createpath(tmpdir + "/d") with mock.patch("subprocess.run", side_effect=Exception("outch")): assert not e.mount(tmpdir + "/e", tmpdir + "/d", "PASSWORD")