Skip to content
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

Account Protection: Fix invalid auth early return #41652

Open
wants to merge 2 commits into
base: add/account-protection
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix tests
  • Loading branch information
dkmyta committed Feb 7, 2025
commit 94f2355801ee72f97d87c77ca31ed8e374c31cfa
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ public function render_page() {
*
* @param \WP_User $user The user.
* @param string $token The token.
*
* @return void
*/
public function render_content( \WP_User $user, string $token ): void {
public function render_content( \WP_User $user, string $token ) {
$transient_key = Config::TRANSIENT_PREFIX . "_error_{$user->ID}";
$error_message = get_transient( $transient_key );
delete_transient( $transient_key );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,19 @@ public function test_render_page_checks_2fa_code_successfully(): void {
$user->user_pass = 'pw';
$user->add_cap( 'publish_posts' );

$sut = $this->createPartialMock( Password_Detection::class, array( 'redirect_and_exit', 'load_user' ) );
$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user', 'redirect_and_exit', 'render_content' ) );
$sut->expects( $this->once() )
->method( 'load_user' )
->with( 123 )
->willReturn( $user );
$sut->expects( $this->once() )
->method( 'redirect_and_exit' )
->with( 'http://example.org/wp-admin/' );
$sut->expects( $this->once() )
->method( 'render_content' )
->willReturn( null );

$calls = 0;
$calls = 0;
$call_counter = function () use ( &$calls ) {
++$calls;
return false;
Expand Down Expand Up @@ -249,11 +252,14 @@ public function test_render_page_sets_transient_error_if_2fa_code_is_wrong(): vo
$user->user_pass = 'pw';
$user->add_cap( 'publish_posts' );

$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user' ) );
$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user', 'render_content' ) );
$sut->expects( $this->once() )
->method( 'load_user' )
->with( 123 )
->willReturn( $user );
$sut->expects( $this->once() )
->method( 'render_content' )
->willReturn( null );

$sut->render_page();

Expand Down
Loading