Skip to content

Commit

Permalink
Dummy Two Factor: Require that the form is actually submitted before …
Browse files Browse the repository at this point in the history
…returning truthful, this closer matches the expectation from other providers.
  • Loading branch information
dd32 committed Feb 27, 2023
1 parent f0b2205 commit 87985df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion providers/class-two-factor-dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function authentication_page( $user ) {
require_once ABSPATH . '/wp-admin/includes/template.php';
?>
<p><?php esc_html_e( 'Are you really you?', 'two-factor' ); ?></p>
<input type="hidden" name="dummy-auth" value="1" />
<?php
submit_button( __( 'Yup.', 'two-factor' ) );
}
Expand All @@ -73,7 +74,7 @@ public function authentication_page( $user ) {
* @return boolean
*/
public function validate_authentication( $user ) {
return true;
return ! empty( $_POST['dummy-auth'] );
}

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/providers/class-two-factor-dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ public function test_authentication_page() {

$this->assertStringContainsString( 'Are you really you?', $contents );
$this->assertStringContainsString( '<p class="submit">', $contents );
$this->assertStringContainsString( '<input type="hidden" name="dummy-auth"', $contents );
$this->assertStringContainsString( 'Yup', $contents );

}

/**
* Verify that dummy validation returns true.
* Verify that dummy validation returns true when appropriate.
*
* @covers Two_Factor_Dummy::validate_authentication
*/
public function test_validate_authentication() {

$this->assertFalse( $this->provider->validate_authentication( false ) );

$_POST['dummy-auth'] = 1;

$this->assertTrue( $this->provider->validate_authentication( false ) );

}
Expand Down

0 comments on commit 87985df

Please sign in to comment.