-
Notifications
You must be signed in to change notification settings - Fork 8
test: add Pest v1 security test infrastructure #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
dcebf40
7f36938
93c0fd6
de54e8c
5917961
5790087
cbfdd2b
847ac39
539590f
caf77b7
4050b23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "composer" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| open-pull-requests-limit: 10 | ||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| open-pull-requests-limit: 10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ | |
| # +-------------------------------------------------------------------------+ | ||
|
|
||
| locales/po/*.mo | ||
| .omc/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "cacti/plugin_maint", | ||
| "description": "plugin_maint plugin for Cacti", | ||
| "license": "GPL-2.0-or-later", | ||
| "require-dev": { | ||
| "pestphp/pest": "^1.23" | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "pestphp/pest-plugin": true | ||
| } | ||
| }, | ||
| "autoload-dev": { | ||
| "files": [ | ||
| "tests/bootstrap.php" | ||
| ] | ||
| }, | ||
| "scripts": { | ||
| "test": "vendor/bin/pest" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| // Pest configuration file. | ||
|
|
||
| require_once __DIR__ . '/bootstrap.php'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| /* | ||
| * Verify plugin source files do not use PHP 8.0+ syntax. | ||
| * Cacti 1.2.x plugins must remain compatible with PHP 7.4. | ||
| */ | ||
|
|
||
| describe('PHP 7.4 compatibility in maint', function () { | ||
| $files = [ | ||
| 'functions.php', | ||
| 'maint.php', | ||
| 'setup.php', | ||
| ]; | ||
|
|
||
| $readRequiredFile = function (string $relativeFile): string { | ||
| $path = realpath(__DIR__ . '/../../' . $relativeFile); | ||
|
|
||
| if ($path === false) { | ||
| throw new RuntimeException("Unable to resolve required file: {$relativeFile}"); | ||
| } | ||
|
|
||
| $contents = file_get_contents($path); | ||
|
|
||
| if ($contents === false) { | ||
| throw new RuntimeException("Unable to read required file: {$relativeFile}"); | ||
| } | ||
|
|
||
| return $contents; | ||
| }; | ||
|
|
||
| it('does not use str_contains (PHP 8.0)', function () use ($files, $readRequiredFile) { | ||
| foreach ($files as $relativeFile) { | ||
| $contents = $readRequiredFile($relativeFile); | ||
|
|
||
| expect(preg_match('/\bstr_contains\s*\(/', $contents))->toBe(0, | ||
| "{$relativeFile} uses str_contains() which requires PHP 8.0" | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('does not use str_starts_with (PHP 8.0)', function () use ($files, $readRequiredFile) { | ||
| foreach ($files as $relativeFile) { | ||
| $contents = $readRequiredFile($relativeFile); | ||
|
|
||
| expect(preg_match('/\bstr_starts_with\s*\(/', $contents))->toBe(0, | ||
| "{$relativeFile} uses str_starts_with() which requires PHP 8.0" | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('does not use str_ends_with (PHP 8.0)', function () use ($files, $readRequiredFile) { | ||
| foreach ($files as $relativeFile) { | ||
| $contents = $readRequiredFile($relativeFile); | ||
|
|
||
| expect(preg_match('/\bstr_ends_with\s*\(/', $contents))->toBe(0, | ||
| "{$relativeFile} uses str_ends_with() which requires PHP 8.0" | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('does not use nullsafe operator (PHP 8.0)', function () use ($files, $readRequiredFile) { | ||
| foreach ($files as $relativeFile) { | ||
| $contents = $readRequiredFile($relativeFile); | ||
|
|
||
| expect(preg_match('/\?->/', $contents))->toBe(0, | ||
| "{$relativeFile} uses nullsafe operator which requires PHP 8.0" | ||
| ); | ||
| } | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||||
| <?php | ||||||||||||||||||
| /* | ||||||||||||||||||
| +-------------------------------------------------------------------------+ | ||||||||||||||||||
| | Copyright (C) 2004-2026 The Cacti Group | | ||||||||||||||||||
| +-------------------------------------------------------------------------+ | ||||||||||||||||||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||||||||||||||||||
| +-------------------------------------------------------------------------+ | ||||||||||||||||||
| */ | ||||||||||||||||||
|
|
||||||||||||||||||
| /* | ||||||||||||||||||
| * Verify migrated files use prepared DB helpers exclusively. | ||||||||||||||||||
| * Catches regressions where raw db_execute/db_fetch_* calls creep back in. | ||||||||||||||||||
| */ | ||||||||||||||||||
|
|
||||||||||||||||||
| describe('prepared statement consistency in maint', function () { | ||||||||||||||||||
| it('uses prepared DB helpers in all plugin files', function () { | ||||||||||||||||||
| $targetFiles = [ | ||||||||||||||||||
| 'functions.php', | ||||||||||||||||||
| 'maint.php', | ||||||||||||||||||
| 'setup.php', | ||||||||||||||||||
|
Comment on lines
+16
to
+20
|
||||||||||||||||||
| it('uses prepared DB helpers in all plugin files', function () { | |
| $targetFiles = array( | |
| 'functions.php', | |
| 'maint.php', | |
| 'setup.php', | |
| it('uses prepared DB helpers in migrated plugin files', function () { | |
| $targetFiles = array( | |
| 'functions.php', |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| // Verify setup.php defines required plugin hooks and info function. | ||
|
|
||
| describe('maint setup.php structure', function () { | ||
| $setupPath = realpath(__DIR__ . '/../../setup.php'); | ||
| expect($setupPath)->not->toBeFalse(); | ||
|
|
||
| $source = file_get_contents($setupPath); | ||
| expect($source)->not->toBeFalse(); | ||
|
|
||
| $infoPath = realpath(__DIR__ . '/../../INFO'); | ||
| expect($infoPath)->not->toBeFalse(); | ||
|
|
||
| $info = parse_ini_file($infoPath, true); | ||
| expect($info)->not->toBeFalse(); | ||
|
|
||
| it('defines plugin_maint_install function', function () use ($source) { | ||
| expect($source)->toContain('function plugin_maint_install'); | ||
| }); | ||
|
|
||
| it('defines plugin_maint_version function', function () use ($source) { | ||
| expect($source)->toContain('function plugin_maint_version'); | ||
| }); | ||
|
|
||
| it('defines plugin_maint_uninstall function', function () use ($source) { | ||
| expect($source)->toContain('function plugin_maint_uninstall'); | ||
| }); | ||
|
|
||
| it('declares a name in INFO', function () use ($info) { | ||
| expect($info['info'])->toHaveKey('name'); | ||
| }); | ||
|
|
||
| it('declares a version in INFO', function () use ($info) { | ||
| expect($info['info'])->toHaveKey('version'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds a Pest test suite, but the repo’s CI workflow doesn’t run
vendor/bin/pesttoday (it only runs the Cacti integration workflow). Consider adding ascriptsentry (e.g., atestscript) and/or updating CI to execute the Pest suite so these security/compatibility checks are actually enforced.