test: add Pest v1 security test infrastructure#772
Open
somethingwithproof wants to merge 1 commit intoCacti:developfrom
Open
test: add Pest v1 security test infrastructure#772somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof wants to merge 1 commit intoCacti:developfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an initial Pest-based security test scaffold for the thold plugin, focused on static checks for setup structure, SQL helper usage patterns, and avoidance of newer PHP syntax.
Changes:
- Introduces a Pest bootstrap with stubs for common Cacti framework functions/constants to support isolated loading.
- Adds security-oriented Pest tests to validate
setup.phpstructure, discourage interpolateddb_*calls in selected “hardened” files, and check for PHP 8-only APIs/syntax. - Adds
tests/Pest.phpto wire Pest to the bootstrap.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Security/SetupStructureTest.php | Static source checks for key functions and metadata handling in setup.php. |
| tests/Security/PreparedStatementConsistencyTest.php | Line-based scan to detect interpolated raw db_* calls in a small set of files. |
| tests/Security/Php74CompatibilityTest.php | Static scan forbidding select PHP 8.0+ APIs/syntax in core plugin files. |
| tests/Pest.php | Pest entry point requiring the test bootstrap. |
| tests/bootstrap.php | Defines stub Cacti functions/constants/config used by tests. |
Comment on lines
+16
to
+17
| $GLOBALS['config'] = array( | ||
| 'base_path' => '/var/www/html/cacti', |
| } | ||
|
|
||
| if (!defined('CACTI_PATH_BASE')) { | ||
| define('CACTI_PATH_BASE', '/var/www/html/cacti'); |
| foreach ($lines as $lineNumber => $line) { | ||
| $trimmed = ltrim($line); | ||
|
|
||
| if (strpos($trimmed, '//') === 0 || strpos($trimmed, '*') === 0 || strpos($trimmed, '#') === 0) { |
Comment on lines
+42
to
+47
| $hasInterpolatedRawCall = preg_match($rawInterpolatedPattern, $line) === 1; | ||
| $hasPreparedCall = preg_match($preparedPattern, $line) === 1; | ||
|
|
||
| expect($hasInterpolatedRawCall && !$hasPreparedCall)->toBeFalse( | ||
| sprintf('File %s contains an interpolated raw db_* call at line %d', $relativeFile, $lineNumber + 1) | ||
| ); |
Comment on lines
+10
to
+13
| /* | ||
| * Verify plugin source files do not use PHP 8.0+ syntax. | ||
| * Cacti 1.2.x plugins must remain compatible with PHP 7.4. | ||
| */ |
Comment on lines
+45
to
+48
| it('reads plugin metadata from INFO and returns the info section', function () { | ||
| $source = thold_read_setup_source(); | ||
| expect($source)->toContain('parse_ini_file'); | ||
| expect($source)->toContain("return \$info['info'];"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Separates the Pest security test infrastructure into its own PR as requested.