Skip to content

Commit

Permalink
Tests: Test for missing user/token more precisely.
Browse files Browse the repository at this point in the history
Previously the missing token wasn't tested for, and the FUT was passed an invalid data type for the user.
  • Loading branch information
iandunn committed Feb 14, 2023
1 parent 249e50d commit f7e42d6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/providers/class-two-factor-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,20 @@ public function test_authentication_page_no_user() {
}

/**
* Verify that email validation with no user returns false.
* Verify that email validation fails if user or token are missing.
*
* @covers Two_Factor_Email::validate_authentication
*/
public function test_validate_authentication_no_user_is_false() {
$this->assertFalse( $this->provider->validate_authentication( false ) );
public function test_validate_authentication_fails_with_missing_input() {
$logged_out_user = new WP_User();
$valid_user = new WP_User( self::factory()->user->create() );

// User but no code.
$this->assertFalse( $this->provider->validate_authentication( $valid_user ) );

// Code but no user.
$_REQUEST['two-factor-email-code'] = $this->provider->generate_token( $valid_user->ID );
$this->assertFalse( $this->provider->validate_authentication( $logged_out_user ) );
}

/**
Expand Down

0 comments on commit f7e42d6

Please sign in to comment.