feat: add tests for known hosts management and enhance validation in known_hosts.py

This commit is contained in:
2026-09-21 20:46:34 +05:30
parent 4a46685a4c
commit 871afcf454
3 changed files with 302 additions and 3 deletions
+5 -3
View File
@@ -84,12 +84,14 @@ class KnownHostsManager:
return
with os.fdopen(descriptor, "rb") as source:
metadata = os.fstat(source.fileno())
if not stat.S_ISREG(metadata.st_mode) or metadata.st_nlink != 1:
if not stat.S_ISREG(metadata.st_mode):
raise UvmError(f"known_hosts must be a regular, single-link file: {path}")
fcntl.flock(source.fileno(), fcntl.LOCK_EX)
metadata = os.fstat(source.fileno())
if metadata.st_nlink != 1:
raise UvmError(f"known_hosts must be a regular, single-link file: {path}")
if owner is not None and metadata.st_uid != owner:
raise UvmError(f"known_hosts has an unexpected owner: {path}")
fcntl.flock(source.fileno(), fcntl.LOCK_EX)
metadata = os.fstat(source.fileno())
contents = source.read()
updated = _without_hosts(contents, hosts, candidates)
if updated == contents: