Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change and improve user profile #532

Merged
merged 7 commits into from
Oct 1, 2018
Merged

Conversation

joshcanhelp
Copy link
Contributor

@joshcanhelp joshcanhelp commented Sep 5, 2018

Improve the user profile to send password changes to Auth0 in all cases, stop password changes if they do not meet the security policy, move all in-line profile JS to an external file, TESTS. Uses the Management API framework merged in #537.

Specific Changes:

  • Extract all JS out of WP_Auth0_EditProfile and into an external JS file assets/js/edit-user-profile.js using wp_localize_script for PHP-generated data; add WP_Auth0_EditProfile::admin_enqueue_scripts() to load that JS on the user profile and profile edit pages.
  • Move WP_Auth0_EditProfile::validate_new_password() to a new method WP_Auth0_Profile_Change_Password::validate_new_password and improve to check for a failed password update and stop WordPress from updating if so; tie this to validate_password_reset so password reset attempts are sent and checked as well.
  • Moved WP_Auth0_EditProfile::delete_user_data() and WP_Auth0_EditProfile::delete_mfa() to WP_Auth0_Profile_Delete_Data::delete_user_data and WP_Auth0_Profile_Delete_Mfa::delete_mfa() respectively; add nonce and capability checks to both methods for more robust error handling.
  • Add WP_Auth0_Api_Change_Password to send password changes to Auth0.
  • Add WP_Auth0_Api_Delete_User_Mfa to delete an MFA provider for a user on Auth0.
  • Don't load Lock on the password reset screen of wp-login.php

Note to reviewers:

This is a large change but almost 60% is new tests to reach diff coverage of ~100%.

Closes #300
Closes #310
Closes #375

@joshcanhelp joshcanhelp added this to the v3-Next milestone Sep 5, 2018
@auth0 auth0 deleted a comment from codecov-io Sep 5, 2018
@cocojoe
Copy link
Member

cocojoe commented Sep 13, 2018

Will review once other merged and rebased.

@joshcanhelp joshcanhelp force-pushed the fix-password-saved-to-auth0 branch from f964e10 to a746b2d Compare September 17, 2018 22:48
WP_Auth0.php Outdated
@@ -123,7 +123,15 @@ public function init() {
$this->social_amplificator = new WP_Auth0_Amplificator( $this->db_manager, $this->a0_options );
$this->social_amplificator->init();

$edit_profile = new WP_Auth0_EditProfile( $this->db_manager, $users_repo, $this->a0_options );
$api_change_password = new WP_Auth0_Api_Change_Password( $this->a0_options );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding dependency injection to assist with testing.

@@ -420,7 +428,7 @@ public function render_form( $html ) {
// Do not show Auth0 form when ...
if (
// .. processing lost password
( isset( $_GET['action'] ) && $_GET['action'] == 'lostpassword' )
( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'lostpassword', 'rp' ) ) )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sure we can still reset the password if stuck.

@@ -0,0 +1,81 @@
/* global jQuery, wpa0UserProfile, alert */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving in all inline JS from user profile.


if ( $pagenow == 'profile.php' || $pagenow == 'user-edit.php' ) {
add_action( 'admin_footer', array( $this, 'disable_email_field' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move all JS to an external file, see above.

@joshcanhelp joshcanhelp force-pushed the fix-password-saved-to-auth0 branch from 75e4066 to 3dd43d0 Compare September 26, 2018 23:44
@auth0 auth0 deleted a comment from codecov-io Sep 27, 2018
$edit_profile = new WP_Auth0_EditProfile( $this->db_manager, $users_repo, $this->a0_options );
$edit_profile->init();

$api_change_password = new WP_Auth0_Api_Change_Password( $this->a0_options, $api_client_creds );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dependency injection for classes using the new API framework.


add_action( 'edit_user_profile', array( $this, 'show_delete_identity' ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving to individual classes

@codecov-io
Copy link

codecov-io commented Sep 27, 2018

Codecov Report

Merging #532 into dev will increase coverage by 2.08%.
The diff coverage is 99.18%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #532      +/-   ##
============================================
+ Coverage     12.25%   14.33%   +2.08%     
- Complexity     1666     1712      +46     
============================================
  Files            66       71       +5     
  Lines          5762     5865     +103     
============================================
+ Hits            706      841     +135     
+ Misses         5056     5024      -32
Impacted Files Coverage Δ Complexity Δ
lib/WP_Auth0_Api_Client.php 1.56% <ø> (ø) 121 <0> (ø) ⬇️
lib/api/WP_Auth0_Api_Client_Credentials.php 100% <ø> (ø) 8 <0> (ø) ⬇️
lib/WP_Auth0_ErrorLog.php 68.42% <ø> (+3.42%) 12 <0> (-1) ⬇️
lib/WP_Auth0_Email_Verification.php 100% <ø> (ø) 4 <0> (ø) ⬇️
lib/api/WP_Auth0_Api_Jobs_Verification.php 100% <100%> (+62.5%) 7 <3> (+1) ⬆️
lib/api/WP_Auth0_Api_Delete_User_Mfa.php 100% <100%> (ø) 8 <8> (?)
lib/profile/WP_Auth0_Profile_Delete_Data.php 100% <100%> (ø) 7 <7> (?)
lib/api/WP_Auth0_Api_Change_Password.php 100% <100%> (ø) 10 <10> (?)
lib/profile/WP_Auth0_Profile_Delete_Mfa.php 100% <100%> (ø) 11 <11> (?)
lib/WP_Auth0_EditProfile.php 4.92% <100%> (+4.92%) 57 <1> (-2) ⬇️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38dab4f...9e9308e. Read the comment docs.

Copy link
Member

@cocojoe cocojoe left a comment

Choose a reason for hiding this comment

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

That was a long read, in general LGTM. As always the progression of tests within the SDK is great 👌
One small comment re docheader, but will approve.

/**
* Set the user_id and provider, set the authorization header, call the API, and handle the response.
*
* @param string|null $user_id - Auth0 user ID to delete the MFA provider.
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention in docheader that the default MFA provider is google-authenticator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cocojoe - Function params default there and it's mostly an internally-used functionality.

@joshcanhelp joshcanhelp merged commit 9338009 into dev Oct 1, 2018
@joshcanhelp joshcanhelp deleted the fix-password-saved-to-auth0 branch October 1, 2018 16:58
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants