Repository navigation
Login and Registration: Add support for /.well-known/change-password #12621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
HasnainAshfaq
wants to merge
13
commits into
WordPress:trunk
from
HasnainAshfaq:feature/51173-well-known-change-password
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5eae8d0
Login and Registration: Add support for /.well-known/change-password
HasnainAshfaq a9135c9
Login and Registration: Address code review feedback for #51173
HasnainAshfaq cdcbb21
Coding Standards: Fix variable alignment in changePassword test
HasnainAshfaq 56e236c
Login and Registration: Improve test isolation in changePassword tests
HasnainAshfaq a1a5ed5
Login and Registration: Simplify change-password URL matching; update…
HasnainAshfaq 802a96c
Use `wp_safe_redirect()` to redirect chagne password URL.
peterwilsoncc 8b46429
MVP redirect capture.
peterwilsoncc 1afc6e7
Assert full destination matches.
peterwilsoncc 87fc0a6
`$_SERVER` is reset by base test suite, see `tests_reset__SERVER()`.
peterwilsoncc f9b2209
Improve docblock.
peterwilsoncc a9b9b12
Merge branch 'trunk' into feature/51173-well-known-change-password
peterwilsoncc 5e819b6
Remove unneeded remove_filter.
peterwilsoncc caa3e7a
Merge branch 'trunk' into feature/51173-well-known-change-password
peterwilsoncc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the /.well-known/change-password redirect. | ||
| * | ||
| * @group canonical | ||
| * @group rewrite | ||
| * @group query | ||
| * @ticket 51173 | ||
| */ | ||
| class Tests_Canonical_ChangePassword extends WP_UnitTestCase { | ||
| public function set_up() { | ||
| parent::set_up(); | ||
| $this->set_permalink_structure( '/%postname%/' ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the redirect URL triggered by wp_redirect_admin_locations() | ||
| * for the given REQUEST_URI, or null if no redirect fires. | ||
| * | ||
| * @param string $request_uri Requested URL. | ||
| * @return string|null Redirect destination, null if no redirect. | ||
| */ | ||
| private function get_redirect_for( $request_uri ) { | ||
| $_SERVER['REQUEST_URI'] = $request_uri; | ||
|
|
||
| global $wp_query; | ||
| $wp_query->is_404 = true; | ||
|
|
||
| $captured = null; | ||
|
|
||
| $capture = static function ( $location ) use ( &$captured ) { | ||
| $captured = $location; | ||
| return false; | ||
| }; | ||
|
|
||
| // Runs late to ensure filters added by other tests fire first. | ||
| add_filter( 'wp_redirect', $capture, 20 ); | ||
| wp_redirect_admin_locations(); | ||
| return $captured; | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::wp_redirect_admin_locations | ||
| */ | ||
| public function test_well_known_change_password_redirects_to_profile() { | ||
| $redirect = $this->get_redirect_for( '/.well-known/change-password' ); | ||
| $this->assertNotNull( $redirect, 'A redirect should fire for the well-known change-password URL.' ); | ||
| $this->assertSame( admin_url( 'profile.php' ), $redirect, 'Should redirect to the profile page.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::wp_redirect_admin_locations | ||
| */ | ||
| public function test_well_known_change_password_with_trailing_slash_redirects_to_profile() { | ||
| $redirect = $this->get_redirect_for( '/.well-known/change-password/' ); | ||
| $this->assertNotNull( $redirect, 'A redirect should fire for the trailing-slash variant.' ); | ||
| $this->assertSame( admin_url( 'profile.php' ), $redirect, 'Trailing slash variant should also redirect to the profile page.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::wp_redirect_admin_locations | ||
| */ | ||
| public function test_well_known_change_password_no_redirect_without_pretty_permalinks() { | ||
| $this->set_permalink_structure( '' ); | ||
|
|
||
| $redirect = $this->get_redirect_for( '/.well-known/change-password' ); | ||
|
|
||
| $this->assertNull( $redirect, 'Should not redirect when pretty permalinks are disabled.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::wp_redirect_admin_locations | ||
| */ | ||
| public function test_wp_change_password_url_filter() { | ||
| $custom_url = 'https://example.com/my-account/change-password/'; | ||
|
peterwilsoncc marked this conversation as resolved.
|
||
| $url_filter = static fn() => $custom_url; | ||
|
|
||
| add_filter( | ||
| 'allowed_redirect_hosts', | ||
| static function ( $hosts ) { | ||
| $hosts[] = 'example.com'; | ||
| return $hosts; | ||
| } | ||
| ); | ||
|
|
||
| add_filter( 'wp_change_password_url', $url_filter ); | ||
| $redirect = $this->get_redirect_for( '/.well-known/change-password' ); | ||
| $this->assertSame( $custom_url, $redirect ); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.