Skip to content

Commit

Permalink
Add tests for the backup code length filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Dec 2, 2024
1 parent 1b10310 commit bbcd041
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/providers/class-two-factor-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,25 @@ public function test_delete_code() {
$this->provider->delete_code( $user, $backup_codes[0] );
$this->assertEquals( 1, $this->provider->codes_remaining_for_user( $user ) );
}

public function test_backup_code_length_filter() {
$user = new WP_User( self::factory()->user->create() );

$code_default = $this->provider->generate_codes( $user, array( 'number' => 1 ) );

add_filter(
'two_factor_backup_code_length',
function() {
return 7;
}
);

$code_custom_length = $this->provider->generate_codes( $user, array( 'number' => 1 ) );

$this->assertNotEquals( strlen( $code_custom_length[0] ), strlen( $code_default[0] ), 'Backup code length can be adjusted via filter' );

$this->assertEquals( 7, strlen( $code_custom_length[0] ), 'Backup code length matches the filtered length' );

remove_all_filters( 'two_factor_backup_code_length' );
}
}

0 comments on commit bbcd041

Please sign in to comment.