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
+20
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import os
import unittest
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
@@ -68,3 +69,22 @@ class ArchitectureSettingsTests(unittest.TestCase):
self.assertRaisesRegex(ConfigurationError, "unsupported host architecture: riscv64"),
):
Settings.from_environment()
class KnownHostsSettingsTests(unittest.TestCase):
def test_known_hosts_files_are_loaded_as_explicit_absolute_paths(self) -> None:
with patch.dict(os.environ, {
"UVM_KNOWN_HOSTS_FILES": "/root/.ssh/known_hosts:/home/operator/.ssh/known_hosts",
}, clear=True):
settings = Settings.from_environment()
self.assertEqual(settings.known_hosts_files, (
Path("/root/.ssh/known_hosts"), Path("/home/operator/.ssh/known_hosts"),
))
with patch.dict(os.environ, {}, clear=True):
self.assertIsNone(Settings.from_environment().known_hosts_files)
def test_relative_or_empty_path_entries_are_rejected(self) -> None:
for value in ("known_hosts", "/tmp/known_hosts:", ":/tmp/known_hosts"):
with self.subTest(value=value), patch.dict(os.environ, {"UVM_KNOWN_HOSTS_FILES": value}, clear=True):
with self.assertRaisesRegex(ConfigurationError, "UVM_KNOWN_HOSTS_FILES"):
Settings.from_environment()