Skip to content

Commit

Permalink
Filter which providers should be available to users
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Nov 15, 2022
1 parent 9bbbefe commit c1afa88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require dirname( __DIR__, 2 ) . '/two-factor/two-factor.php';
require dirname( __DIR__ ) . '/wporg-two-factor.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
Expand Down
13 changes: 12 additions & 1 deletion tests/test-wporg-two-factor.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<?php

use function WordPressdotorg\Two_Factor\{};
//use function WordPressdotorg\Two_Factor\{};

defined( 'WPINC' ) || die();

class Test_WPorg_Two_Factor extends WP_UnitTestCase {
public function test_two_factor_providers() {
$actual = Two_Factor_Core::get_providers();

$this->assertArrayHasKey( 'Two_Factor_Totp', $actual );
$this->assertArrayHasKey( 'Two_Factor_Backup_Codes', $actual );
// @todo enable after https://github.com/WordPress/two-factor/issues/427 merges
//$this->assertArrayHasKey( 'Two_Factor_WebAuthn', $actual );

$this->assertArrayNotHasKey( 'Two_Factor_Email', $actual );
$this->assertArrayNotHasKey( 'Two_Factor_Dummy', $actual );
}
}
15 changes: 15 additions & 0 deletions wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@
namespace WordPressdotorg\Two_Factor;
defined( 'WPINC' ) || die();

add_filter( 'two_factor_providers', __NAMESPACE__ . '\two_factor_providers', 99 ); // Must run after all other plugins.

/**
* Determine which providers should be available to users.
*/
function two_factor_providers( array $providers ) : array {
// Match the name => file path format of input var, but the path isn't needed.
$desired_providers = array(
'Two_Factor_WebAuthn' => '',
'Two_Factor_Totp' => '',
'Two_Factor_Backup_Codes' => '',
);

return array_intersect_key( $providers, $desired_providers );
}

0 comments on commit c1afa88

Please sign in to comment.