Skip to content

Conversation

@kasparsd
Copy link
Collaborator

@kasparsd kasparsd commented Sep 19, 2024

What?

Users expect a method to be enabled if they chose to configure it.

Why?

Fixes #556.

How?

Testing Instructions

Setup workflow:

  1. Configure the TOTP method by submitting the generated code.
  2. Confirm the TOTP method is now enabled in the table.

Reset workflow:

  1. Click on RESET TOTP method button.
  2. Confirm the TOTP method is now disabled in the table.

Screenshots or screencast

totp-actions.mp4

Changelog Entry

Added - New feature.
Changed - Existing functionality.
Deprecated - Soon-to-be removed feature.
Removed - Feature.
Fixed - Bug fix.
Security - Vulnerability.

@kasparsd kasparsd marked this pull request as ready for review September 19, 2024 12:22
@jeffpaul jeffpaul added this to the 0.10.0 milestone Sep 19, 2024
$user = self::factory()->user->create_and_get();
$enabled_providers = Two_Factor_Core::get_enabled_providers_for_user( $user->ID );
$this->assertEmpty( $enabled_providers );
$this->assertEmpty( $enabled_providers, 'No providers are enabled by default' );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These help us identify failing tests instead of just showing the test method name.


$this->delete_user_totp_key( $user_id );

if ( ! Two_Factor_Core::disable_provider_for_user( $user_id, 'Two_Factor_Totp' ) ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting the TOTP key now also disables the method because it is unusable without the key.

$enabled_providers[] = $new_provider;
$enabled = update_user_meta( $user_id, self::ENABLED_PROVIDERS_USER_META_KEY, $enabled_providers );

// Primary provider must be enabled.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary provider is determined during get_primary_provider_for_user() so there is no need update it here. If no primary is configured, we always default to the first enabled.


$error.find('p').text( errorMessage );

$( '#enabled-Two_Factor_Totp' ).prop( 'checked', false );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now enable the TOTP method when the key has been registered by default.

user_id: <?php echo wp_json_encode( $user->ID ); ?>,
key: key,
code: code,
enable_provider: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instruct the validator to also enable the provider, if everything is a pass.

@kasparsd kasparsd merged commit 4c733e4 into master Jan 9, 2025
48 checks passed
@kasparsd kasparsd deleted the 556-enable-totp-on-submit branch January 9, 2025 11:36
@kasparsd kasparsd mentioned this pull request Jan 9, 2025
@jeffpaul jeffpaul modified the milestones: 0.12.0, 0.11.0 Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOTP: After successful set up, JS should check the "Enabled" checkbox for the TOTP provider

3 participants