mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
fix(sys-ctl-hlth-runtime): bound the engine calls and catch hidden PHP runtimes
Three CodeRabbit findings on PR #1265: - script.py listed the running containers with `container ps` and `container inspect` without a timeout, so a hung engine kept the daily unit active forever and blocked the next timer run. Both calls now use EXEC_TIMEOUT_SECONDS; main turns a timeout or engine error into a one-line failure and exit 1 instead of a traceback. - runtime.py's PHP_PACKAGE_PATTERN requires a digit after "php", so an image installing an unversioned interpreter package (`php-cli`) and setting no PHP_VERSION was reported as PHP-free. The interpreter packages php, php-cli, php-fpm, php-cgi, php-phpdbg and libapache2-mod-php are now recorded as PhpRuntime.packages and reported with an unknown patch level; extension and library packages (php-mysql, php-pear, php-common, phpmyadmin) and paths do not count. - php_finding returned early for a patched PHP_VERSION, so an end-of-life package line installed next to it (e.g. php7) was never reported. The version only returns a finding now; otherwise the lines are judged too. Every finding has unit tests that fail on the previous code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06f896d231
commit
d116dde659
6 files changed
+150
-17
No files matched your search
@@ -11,8 +11,10 @@ from utils.docker.image import runtime
|
||||
FLOORS = {"8.2": "8.2.35", "8.3": "8.3.36", "8.4": "8.4.27", "8.5": "8.5.12"}
|
||||
|
||||
|
||||
def _php(version=None, lines=()):
|
||||
return runtime.PhpRuntime(version=version, lines=tuple(lines))
|
||||
def _php(version=None, lines=(), packages=()):
|
||||
return runtime.PhpRuntime(
|
||||
version=version, lines=tuple(lines), packages=tuple(packages)
|
||||
)
|
||||
|
||||
|
||||
class TestPhpRuntime(TestCase):
|
||||
@@ -75,6 +77,35 @@ class TestPhpRuntime(TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_an_unversioned_debian_runtime_package_is_php(self):
|
||||
self.assertEqual(
|
||||
runtime.php_runtime(["RUN apt-get install -y php-cli"]),
|
||||
_php(packages=["php-cli"]),
|
||||
)
|
||||
|
||||
def test_unversioned_runtime_packages_are_php(self):
|
||||
found = runtime.php_runtime(
|
||||
[
|
||||
"RUN dnf install -y php php-fpm php-mysqlnd",
|
||||
"RUN apt-get install -y libapache2-mod-php php-cgi=2:8.2+93 \\",
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
found, _php(packages=["libapache2-mod-php", "php", "php-cgi", "php-fpm"])
|
||||
)
|
||||
|
||||
def test_php_libraries_extensions_and_paths_are_not_a_runtime(self):
|
||||
self.assertIsNone(
|
||||
runtime.php_runtime(
|
||||
[
|
||||
(
|
||||
"RUN apt-get install -y php-common php-pear php-mysql phpmyadmin"
|
||||
" && docker-php-ext-install gd && cp php-fpm.conf /etc/php-fpm.d/"
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
def test_an_image_without_php_has_no_runtime(self):
|
||||
self.assertIsNone(
|
||||
runtime.php_runtime(
|
||||
@@ -114,6 +145,21 @@ class TestPhpFinding(TestCase):
|
||||
def test_a_supported_distro_line_is_no_finding(self):
|
||||
self.assertIsNone(runtime.php_finding(_php(lines=["8.3"]), FLOORS))
|
||||
|
||||
def test_an_eol_line_fails_next_to_a_patched_php_version(self):
|
||||
self.assertEqual(
|
||||
runtime.php_finding(_php("8.4.27", lines=["7"]), FLOORS),
|
||||
"line 7 is end of life",
|
||||
)
|
||||
|
||||
def test_a_php_version_below_its_floor_outranks_an_eol_line(self):
|
||||
self.assertIn(
|
||||
"below the security floor 8.4.27",
|
||||
runtime.php_finding(_php("8.4.15", lines=["7"]), FLOORS),
|
||||
)
|
||||
|
||||
def test_an_unversioned_package_alone_is_no_finding(self):
|
||||
self.assertIsNone(runtime.php_finding(_php(packages=["php-cli"]), FLOORS))
|
||||
|
||||
|
||||
class TestLoadPhpFloors(TestCase):
|
||||
def test_reads_the_php_floors_from_the_vars_file(self):
|
||||
|
||||
Reference in new issue
Block a user