Skip to content

Conversation

@priethor
Copy link
Contributor

@priethor priethor commented Dec 30, 2025

What

Part of #315.

Adds PHPUnit security test coverage for all AJAX handlers in includes/ajax/.

Why

These tests verify nonce verification, capability enforcement, and input sanitization

How

With the help of Claude, adding 69 tests covering:

  • ACF_Ajax base class

    • Nonce verification (valid/invalid/missing)
    • Request key identification
    • Request initialization and value retrieval
  • ACF_Ajax_Query

    • Page/per_page integer sanitization
    • Search parameter sanitization
    • HTML injection prevention in search
    • Empty and whitespace-only search handling
  • ACF_Ajax_Query_Users

    • Conditional logic capability enforcement
    • Admin vs subscriber access control
  • ACF_Ajax_Check_Screen

    • Post edit capability verification
  • ACF_Ajax_Upgrade

    • Admin capability enforcement
  • ACF_Ajax_User_Setting

    • Admin capability enforcement
  • ACF_Ajax_Local_JSON_Diff

    • Admin capability enforcement
    • Post type validation

Testing Instructions

Run the test suite: ./vendor/bin/phpunit --filter Test_Ajax_Handlers

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props priethor.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.04%. Comparing base (f0036e7) to head (880a8ea).
⚠️ Report is 5 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #326      +/-   ##
============================================
+ Coverage     16.68%   17.04%   +0.35%     
  Complexity     4410     4410              
============================================
  Files           291      291              
  Lines         36995    36995              
============================================
+ Hits           6173     6306     +133     
+ Misses        30822    30689     -133     
Flag Coverage Δ
e2e 28.87% <ø> (ø)
javascript 2.50% <ø> (ø)
phpunit 15.37% <ø> (+0.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@priethor priethor changed the title Tests: Add security tests for AJAX handlers Tests: AJAX Security - Add comprehensive handler tests Dec 30, 2025
@priethor priethor changed the title Tests: AJAX Security - Add comprehensive handler tests Tests: Add security tests for AJAX handlers Dec 30, 2025
@priethor priethor changed the title Tests: Add security tests for AJAX handlers Tests: Add PHPUnit security tests for AJAX handlers Dec 30, 2025
Add comprehensive PHPUnit test coverage for AJAX handler security:

- ACF_Ajax base class: Nonce verification, request handling
- ACF_Ajax_Query: Public endpoint verification, input sanitization
- ACF_Ajax_Query_Users: Nonce and capability checks
- ACF_Ajax_Check_Screen: Permission verification
- ACF_Ajax_Upgrade: Admin capability enforcement
- ACF_Ajax_User_Setting: Admin-only access checks
- ACF_Ajax_Local_JSON_Diff: Admin access and post type validation
- acf_verify_ajax(): Nonce validation function tests
- acf_current_user_can_admin(): Capability helper tests

72 new tests covering P0 security areas including:
- Nonce verification for all handlers
- Capability enforcement per handler requirements
- Input sanitization for search parameters
- Public vs non-public endpoint registration

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@priethor priethor force-pushed the 3468-phase-2-pr-9-aja branch from 92c5ad9 to 880a8ea Compare December 30, 2025 12:26
@priethor priethor mentioned this pull request Dec 30, 2025
22 tasks
@priethor priethor changed the title Tests: Add PHPUnit security tests for AJAX handlers Tests: Add PHPUnit tests for AJAX handlers Dec 30, 2025
@priethor priethor merged commit 3982342 into trunk Dec 30, 2025
9 checks passed
@priethor priethor deleted the 3468-phase-2-pr-9-aja branch December 30, 2025 12:37
@priethor priethor self-assigned this Dec 30, 2025
@priethor priethor added this to the 6.8.0 milestone Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants