Skip to content

Develop - #32

Closed
TheWitness wants to merge 2 commits into
mainfrom
develop
Closed

TheWitness wants to merge 2 commits into
mainfrom
develop

Conversation

@TheWitness

Copy link
Copy Markdown
Member

No description provided.

somethingwithproof and others added 2 commits September 11, 2026 02:17
* refactor: DRY evidence tab page wrapper

* fix: tighten evidence DRY helper and routing tests
… framework with Thold (#30)

* security: migrate uninstall drop statements to prepared

* fix: complete uninstall drop coverage and harden tests

* fix: harden evidence uninstall drop path with IF EXISTS

* test: expand security test coverage for hardening changes

Add targeted tests for prepared statement migration, output escaping,
auth guard presence, CSRF token validation, redirect safety, and
PHP 7.4 compatibility. Tests use source-scan patterns that verify
security invariants without requiring the Cacti database.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix: escape quotes in Pest regex patterns

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(security): escape evidence filter output

* test: align Evidence test framework with Thold model

Supersedes #25 ("hardening: migrate uninstall drop statements to
prepared" by @somethingwithproof) — this branch carries forward that
PR's prepared-statement hardening and test coverage, then updates the
test/CI plumbing to match the model used by Cacti/plugin_thold, mirroring
the same work already applied in PR #29:

- Remove composer.json (no composer.lock was present): Pest/PHPUnit no
  longer come from a vendor tree local to this plugin.
- Add tests/.cacti-version, tests/TestCase.php, and tests/bootstrap-unit.php
  (adapted from thold). bootstrap-unit.php verifies the Cacti checkout in
  CI matches tests/.cacti-version, requires Cacti's own Composer vendor
  autoloader, and stubs the Cacti global functions plugin source expects.
- Replace tests/bootstrap.php with tests/bootstrap-unit.php and update
  tests/Pest.php's comment to match.
- Add phpunit.xml (none existed before) bootstrapping from
  tests/bootstrap-unit.php and covering tests/Security, tests/Unit,
  tests/Integration, and tests/E2E.
- Add .github/copilot-instructions.md adapted from thold's for the
  Evidence plugin.
- Add .github/workflows/php-unit-tests.yml modeled on thold's workflow:
  checks out this plugin plus a pinned Cacti runtime and test toolchain,
  builds a Docker test image, lints, and runs Pest with coverage.

* fix(tests): correct pre-existing test bugs surfaced by new CI run

Adding phpunit.xml means these tests actually execute in CI for the
first time; two of them had latent bugs that were never caught before:

- AuthGuardTest.php checked tests/test_prepared_statements.php (a test
  helper script) instead of the plugin's real UI entry points
  (evidence.php, evidence_tab.php), causing a false-positive failure and
  a risky (zero-assertion) test once no matching line existed.
- SetupStructureTest.php regexed setup.php's raw source for `'name' =>`
  / `'version' =>`, but those keys live in the INFO ini file that
  setup.php parses at runtime, not in its literal source text. Assert
  against the parsed INFO file instead, matching PR #29's approach.

* chore: normalize line endings to LF and enforce via .gitattributes

.github/copilot-instructions.md, .github/workflows/php-unit-tests.yml,
tests/.cacti-version, tests/TestCase.php, and tests/bootstrap-unit.php
were committed with CRLF line endings. Normalize them to LF to match the
rest of the repo, and add .gitattributes (`* text=auto eol=lf`) so this
doesn't regress.

* fix(tests): address Copilot review feedback on PR #30

- PreparedStatementConsistencyTest.php: drop the non-existent
  tests/test_prepared_statements.php target and narrow the description/
  scope to the setup.php uninstall/drop path it actually verifies,
  instead of implying (and failing to enforce) coverage of every plugin
  file's DB calls.
- RedirectSafetyTest.php: scan the real redirect entry points
  (index.php, images/index.php, data/index.php) instead of setup.php,
  which has no header(Location) call at all.
- index.php, images/index.php, data/index.php: follow the
  header("Location: ...") redirect with exit, so the test above passes
  for a real reason and the scripts can't fall through if code is later
  added after the redirect.
- Php74CompatibilityTest.php: drop the dangling reference to the removed
  tests/test_prepared_statements.php.
- Convert tests/test_prepared_statements.php (a standalone script never
  discovered by phpunit.xml or Pest's *Test.php convention, so its
  assertions never ran in CI) into
  tests/Security/UninstallPreparedStatementsTest.php, a proper Pest test
  with the same assertions.

* chore: remove php-unit-tests.yml workflow from this PR

* docs: merge copilot-instructions.md with main's structure

* docs: bring in CHANGELOG.md and updated README.md from main

* fix(tests): align phpunit.xml schema path and cacti version check with main

* docs: clarify renaming plugin_evidence directory to evidence on install

* ci: add plugin-ci-workflow.yml from main and run full test suite; docs: raise PHP floor to 8.2

* ci: run composer install without sudo to avoid root-owned vendor tree breaking Pest cache writes

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI lite review requested due to automatic review settings September 12, 2026 23:39
@TheWitness TheWitness closed this Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved credential exposure and CI, compatibility, reproducibility, and test-execution issues remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This pull request hardens the Evidence plugin’s uninstall, redirect, and HTML output handling while adding automated security, integration, and CI coverage.

Changes:

  • Adds prepared uninstall statements and safe redirect termination.
  • Escapes rendered output and centralizes tab-page rendering.
  • Adds Pest tests, CI integration, documentation, and repository guidance.
File summaries
File Summary
tests/Unit/FilterOutputEscapingTest.php Tests HTML escaping.
tests/TestCase.php Adds a reusable test base class.
tests/test_tab_wrapper.php Tests tab-wrapper behavior; nit (2 votes): this check is not executed by CI.
tests/Security/UninstallPreparedStatementsTest.php Tests prepared uninstall statements.
tests/Security/SetupStructureTest.php Adds setup-structure security checks.
tests/Security/RedirectSafetyTest.php Tests redirect safety.
tests/Security/PreparedStatementConsistencyTest.php Checks prepared-statement consistency.
tests/Security/Php74CompatibilityTest.php Adds PHP compatibility checks; moderate (1 vote): the no-op assertion always passes.
tests/Security/OutputEscapingTest.php Tests output escaping.
tests/Security/AuthGuardTest.php Tests authentication guards.
tests/Pest.php Adds Pest configuration.
tests/Integration/EvidenceTabEscapingTest.php Tests escaped tab output.
tests/E2E/EvidenceFilterXssRegressionTest.php Adds filter XSS regression coverage.
tests/bootstrap-unit.php Bootstraps Cacti/Pest tests.
tests/.cacti-version Records the expected Cacti version.
setup.php Uses prepared table drops during uninstall.
README.md Updates plugin documentation.
phpunit.xml Configures suites and coverage; nit (1 vote): the standalone tab-wrapper test is not discovered.
index.php Terminates after redirects.
include/ui_helpers.php Adds shared tab rendering.
images/index.php Terminates after redirects.
evidence_tab.php Uses shared rendering and escapes output.
data/index.php Terminates after redirects.
CHANGELOG.md Updates changelog history; nit (1 vote): current changes are not documented.
.github/workflows/plugin-ci-workflow.yml Adds CI integration; critical (2 votes): removes credential-printing diagnostics. Moderate findings (1 vote each) cover missing coverage-driver setup, the PHP 8.2/Pest 3 mismatch, and deleting the generated lockfile.
.github/copilot-instructions.md Adds development guidance.
.gitattributes Normalizes line endings.
Review details

Suppressed comments (7)

.github/workflows/plugin-ci-workflow.yml:114

  • MYSQL_AUTH_USR stores ~ inside an environment variable. Bash does not perform tilde expansion after parameter expansion, so mysql $MYSQL_AUTH_USR passes the literal --defaults-file=~/.my.cnf; the database-initialization step can fail before the schema is loaded. Invoke mysql with --defaults-file="$HOME/.my.cnf" directly or provide an absolute path.
      env:
        MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf'

.github/workflows/plugin-ci-workflow.yml:83

  • The workflow requests a Clover coverage report below, but this PHP setup does not enable Xdebug or PCOV. PHPUnit will fail with no available coverage driver on these jobs; add a coverage driver (for example coverage: pcov) or remove the coverage option from the Pest command.
        extensions: intl, mysql, gd, ldap, gmp, xml, curl, json, mbstring, snmp
        ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York"

.github/workflows/plugin-ci-workflow.yml:138

  • Pest 3 requires PHP 8.3+, but this matrix still runs PHP 8.2 (line 44), so dependency resolution fails for that job before the tests run. Use a Pest release compatible with PHP 8.2 or remove/update the 8.2 matrix entry.
          composer require --dev --no-progress --no-interaction "pestphp/pest: ^3" "pestphp/pest-plugin-drift: ^3.0"

.github/workflows/plugin-ci-workflow.yml:139

  • Deleting composer.lock immediately after composer require makes every CI run resolve the full dependency graph from moving package metadata instead of using a lockfile. A future transitive release can break all PHP jobs without any repository change; keep the lockfile produced by composer require or pin a reproducible dependency set.
          rm -f composer.lock

CHANGELOG.md:10

  • This PR changes uninstall behavior, output escaping, redirects, and the test/CI setup, but the changelog only contains the historical 0.1–0.3 entries. The release notes therefore omit the current changes; add a current entry (and align the plugin version if this is intended as a release).
--- 0.3 ---
* Add generic snmp info

--- 0.2 ---
* Better data display

--- 0.1 ---
* Beginning

phpunit.xml:20

  • tests/test_tab_wrapper.php is neither under these configured directories nor named with the standard *Test.php suffix. The CI invocation therefore will not execute this standalone wrapper check, leaving the new rendering helper without the intended regression test; convert it to a discovered Pest test or explicitly run it in CI.
            <directory>tests/Security</directory>
            <directory>tests/Unit</directory>
            <directory>tests/Integration</directory>
            <directory>tests/E2E</directory>

tests/Security/Php74CompatibilityTest.php:107

  • This branch intentionally contains no assertion, and the only assertion after the loop is unconditionally true, so the test passes regardless of whether mixed array syntax is present. It provides false confidence under the stated test name; either enforce the condition or remove this no-op test.
			if ($hasArrayFunc && $hasShortArray) {
				// Allow mixed if the file existed before our changes
				// This is informational, not a hard fail
			}
  • Files reviewed: 27/27 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- name: Create MySQL Config
run: |
echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf
cat ~/.my.cnf
Comment on lines +43 to +44
evidence_render_tab_page('evidence_tab_test_content');
assert_same(['header', 'form', 'content', 'footer'], $events, 'Tab helper should render wrapper in correct order.');
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.

3 participants