From 0ec9c1efda0b309cc13a063f9039bac903f3e0d6 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Fri, 1 Sep 2023 15:40:43 -0700 Subject: [PATCH] cleaner --- class-two-factor-core.php | 56 ++------------------------------- tests/class-two-factor-core.php | 29 ----------------- 2 files changed, 2 insertions(+), 83 deletions(-) diff --git a/class-two-factor-core.php b/class-two-factor-core.php index ef003063..96b9cf69 100644 --- a/class-two-factor-core.php +++ b/class-two-factor-core.php @@ -1845,63 +1845,11 @@ public static function disable_provider_for_user( $user_id, $provider_to_delete return true; } - $primary_provider = self::get_primary_provider_for_user( $user_id ); $new_enabled_providers = array_diff( $old_enabled_providers, array( $provider_to_delete ) ); $was_disabled = update_user_meta( $user_id, self::ENABLED_PROVIDERS_USER_META_KEY, $new_enabled_providers ); - // $disabled_primary_provider = is_object( $primary_provider ) && $primary_provider->get_key() === $provider_to_delete; - - // if ( $disabled_primary_provider ) { - // if ( $new_enabled_providers ) { - // // call the prim func to set it? - // $new_primary_provider = array_keys( $new_enabled_providers )[0]; // need to use key? - // $has_primary = update_user_meta( $user_id, self::PROVIDER_USER_META_KEY, $new_primary_provider ); - // } else { - // $has_primary = delete_user_meta( $user_id, self::PROVIDER_USER_META_KEY ); - // // failing to delete b/c it doesn't exist i guess, maybe tests need to manually set which is primary - // } - // } else { - // $has_primary = true; - // } - - return (bool) $was_disabled; //&& $has_primary; - } - // overcomplicated - // /** - // * Get the most secure provider among the available to the user. - // * - // * @param int $user_id The ID of the user. - // */ - // public static function get_most_secure_available_provider_for_user( $user_id ) { - // /** - // * Filter which provider is selected as the most secure for the user. The first provider in the array is - // * considered the most secure, and the last provider is considered the least secure. - // * - // * @param string $selected_provider The most secure provider available to the user. - // * @param int $user_id The ID of the user. - // */ - // $most_secure_to_least = apply_filters( - // 'two_factor_provider_security_rank', - // array( - // 'Two_Factor_FIDO_U2F', - // 'Two_Factor_Totp', - // 'Two_Factor_Email', - // 'Two_Factor_Backup_Codes', - // 'Two_Factor_Dummy', - // ), - // $user_id - // ); - - // $user_available_providers = array_keys( self::get_available_providers_for_user( $user_id ) ); - - // foreach ( $most_secure_to_least as $provider ) { - // if ( in_array( $provider, $user_available_providers, true ) ) { - // return $provider; - // } - // } - - // return false; - // } + return (bool) $was_disabled; + } /** * Update the user meta value. diff --git a/tests/class-two-factor-core.php b/tests/class-two-factor-core.php index 0c086d86..64bdb682 100644 --- a/tests/class-two-factor-core.php +++ b/tests/class-two-factor-core.php @@ -866,35 +866,6 @@ public function test_enable_disable_provider_for_user() { $this->assertSame( 'Two_Factor_Dummy', Two_Factor_Core::get_primary_provider_for_user( $user->ID )->get_key() ); } - /** - * @covers Two_Factor_Core::get_most_secure_available_provider_for_user() - */ - // public function test_get_most_secure_available_provider_for_user() { - // $user = self::factory()->user->create_and_get(); - - // $this->assertFalse( Two_Factor_Core::get_most_secure_available_provider_for_user( $user->ID ) ); - - // // Enable TOTP and Email. TOTP should be most secure. - // Two_Factor_Core::enable_provider_for_user( $user->ID, 'Two_Factor_Totp' ); - // Two_Factor_Core::enable_provider_for_user( $user->ID, 'Two_Factor_Email' ); - - // $totp = Two_Factor_Totp::get_instance(); - // $totp->set_user_totp_key( $user->ID, 'foo' ); - // $available_providers = array_keys( Two_Factor_Core::get_available_providers_for_user( $user->ID ) ); - - // $this->assertSame( array( 'Two_Factor_Email', 'Two_Factor_Totp' ), $available_providers ); - // $this->assertSame( 'Two_Factor_Totp', Two_Factor_Core::get_most_secure_available_provider_for_user( $user->ID ) ); - - - // // Enable Dummy and disable TOTP. Email should be more secure. - // Two_Factor_Core::enable_provider_for_user( $user->ID, 'Two_Factor_Dummy' ); - // Two_Factor_Core::disable_provider_for_user( $user->ID, 'Two_Factor_Totp' ); - // $available_providers = array_keys( Two_Factor_Core::get_available_providers_for_user( $user->ID ) ); - - // $this->assertSame( array( 'Two_Factor_Email', 'Two_Factor_Dummy'), $available_providers ); - // $this->assertSame( 'Two_Factor_Email', Two_Factor_Core::get_most_secure_available_provider_for_user( $user->ID ) ); - // } - /** * Ensure that when a user enables two factor, that they are able to continue to change settings. *