Repository navigation
Tests: Check that private user fields are only returned to the user and to callers who can edit them - #16246
Tests: Check that private user fields are only returned to the user and to callers who can edit them#16246hmbashar wants to merge 2 commits into
Conversation
…nd to callers who can edit them. See #66549.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
lancewillett
left a comment
There was a problem hiding this comment.
The extra profile fields are worth covering. I checked by omitting the first name from an authorized response: the existing 108 tests still passed, and your new self and administrator cases caught it.
Could you fold the new field assertions into test_roles_have_expected_field_visibility_for_another_public_author() and test_visible_current_user_reads_their_own_sensitive_fields()? Those tests already set up these callers and query the same public author. That keeps the additional coverage and avoids maintaining a second role matrix.
AI review · gpt-6.2-astra
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the test-only change adding user-field visibility coverage.
No open issues 🎉
What changed in this PR
Adds regression coverage for core/users-query field visibility, checking that private user fields are returned only to the user or callers who can edit them.
Changes:
- Adds a parameterized test covering the user, an administrator, an editor, a contributor, and a subscriber.
- Checks the exact returned field set for each caller and selected public and private field values.
- Changes tests only; production behavior is unchanged.
| File | Description |
|---|---|
tests/phpunit/tests/abilities-api/wpRegisterCoreUsersAbility.php |
Adds the field-visibility test and caller data provider. |
Review effort: Balanced
…y tests. See #66549.
|
Thanks @lancewillett, done in 051c49a. I removed the separate test and provider and moved the checks into |
lancewillett
left a comment
There was a problem hiding this comment.
Thanks for folding the field checks into the existing role and self tests. I ran the class in random order on single-site (108 tests) and multisite (110). Returning an empty first name for the current user failed the revised assertion in both modes. The fixture stays inside the test transaction. The Abilities API review from @gziolo is still requested.
AI review · gpt-6.2-astra
Summary
Extends two existing tests in
Tests_Abilities_API_WpRegisterCoreUsersAbility, following the suggestions in comment 4 on the ticket: public and private user fields returned to callers with different permissions.Behavior this protects
core/users-queryreturns a user's login, email, first and last name, nickname, locale, registration date and roles only to the user and to callers who can edit that user. Name, description, URL, link and slug are public.The existing tests check
emailandrolesfor the different roles, but notfirst_name,last_name,nickname,locale,registeredandusername, which sit behind the same check inWP_Abilities_Users::format_user(). If that check were removed or widened, those fields would be exposed to any caller who can read a public author, and no test would fail.test_roles_have_expected_field_visibility_for_another_public_author()now requests every private field of a public author, plusdescriptionandurl, and checks that each private field is returned only to the administrator, while the public fields are returned to every role.test_visible_current_user_reads_their_own_sensitive_fields()now checks that the user receives their own first and last name, nickname, locale and registration date.Testing
Mutation check (quality check only): 9 of 10 changes to
class-wp-abilities-users.phpwere caught (the shared check set to true, therolescheck removed, theedit_usercheck removed, and the value or check ofnickname,locale,last_name,description,urlandregistered). The one that survives removes the "is the current user" check. It is an equivalent change, since a user can always edit themselves, soedit_useralready returns true for them.Trac ticket: https://core.trac.wordpress.org/ticket/66549
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.