More test coverage (71%)
This commit is contained in:
parent
9a2516d858
commit
f82fd894ca
8 changed files with 605 additions and 10 deletions
33
tests/test_cache_security.py
Normal file
33
tests/test_cache_security.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_ensure_dir_secure_refuses_symlink(tmp_path: Path):
|
||||
from enroll.cache import _ensure_dir_secure
|
||||
|
||||
target = tmp_path / "target"
|
||||
target.mkdir()
|
||||
link = tmp_path / "link"
|
||||
link.symlink_to(target, target_is_directory=True)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
_ensure_dir_secure(link)
|
||||
|
||||
|
||||
def test_ensure_dir_secure_ignores_chmod_failures(tmp_path: Path, monkeypatch):
|
||||
from enroll.cache import _ensure_dir_secure
|
||||
|
||||
d = tmp_path / "d"
|
||||
|
||||
def boom(_path: str, _mode: int):
|
||||
raise OSError("no")
|
||||
|
||||
monkeypatch.setattr(os, "chmod", boom)
|
||||
|
||||
# Should not raise.
|
||||
_ensure_dir_secure(d)
|
||||
assert d.exists() and d.is_dir()
|
||||
Loading…
Add table
Add a link
Reference in a new issue