Skip to content

test: add Pest v1 security test infrastructure#772

Open
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:test/security-test-infrastructure-v2
Open

test: add Pest v1 security test infrastructure#772
somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof:test/security-test-infrastructure-v2

Conversation

@somethingwithproof
Copy link
Copy Markdown

Separates the Pest security test infrastructure into its own PR as requested.

Copilot AI review requested due to automatic review settings April 11, 2026 23:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.php structure, discourage interpolated db_* calls in selected “hardened” files, and check for PHP 8-only APIs/syntax.
  • Adds tests/Pest.php to 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'];");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants