fix: harden preprocessing state and child capabilities

This commit is contained in:
2026-08-11 14:30:16 +02:00
parent a5916f6177
commit ee5ac381b3
12 changed files with 323 additions and 104 deletions
+20 -1
View File
@@ -1,8 +1,12 @@
from __future__ import annotations
import os, stat
import os
import pytest
from tht.workspace_writer_lock import WorkspaceWriterConflict, verify_workspace_writer_fds
def test_verifier_rejects_missing_capability():
with pytest.raises(WorkspaceWriterConflict): verify_workspace_writer_fds(env={})
@@ -14,3 +18,18 @@ def test_verifier_checks_fd_identity(tmp_path):
cap=verify_workspace_writer_fds(writer_fd=w, root_fd=r, env=env)
assert cap.inode == st.st_ino
finally: os.close(w); os.close(r)
def test_verifier_rejects_unrelated_lock(tmp_path):
root = tmp_path / "root"; other = tmp_path / "other"
root.mkdir(mode=0o700); other.mkdir(mode=0o700)
expected = root / "writer.lock"; forged = other / "forged.lock"
expected.touch(mode=0o600); forged.touch(mode=0o600)
root_fd = os.open(root, os.O_RDONLY); forged_fd = os.open(forged, os.O_RDWR)
try:
st = os.fstat(root_fd)
env = {"THOTH_WORKSPACE_ID": "abc-workspace", "THOTH_WORKSPACE_REVISION": "a" * 40, "THOTH_WORKSPACE_DEVICE": str(st.st_dev), "THOTH_WORKSPACE_INODE": str(st.st_ino)}
with pytest.raises(WorkspaceWriterConflict):
verify_workspace_writer_fds(writer_fd=forged_fd, root_fd=root_fd, env=env)
finally:
os.close(forged_fd); os.close(root_fd)