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

Add skip strategies setting and tests #528

Merged
merged 2 commits into from
Sep 14, 2018
Merged

Conversation

joshcanhelp
Copy link
Contributor

Summary: Add a setting to the admin that skips email verification for specific strategies. This is being added based on Enterprise strategies that do not provide an email_verified flag in the userinfo object.

Admin Setting:

screenshot 2018-08-29 12 52 34

Specific Changes:

  • Add the WP_Auth0_UsersRepo::get_meta() method to abstract getting Auth0 user meta information; refactored all current uses of the core get_user_meta() function to use this new method.
  • Refactor WP_Auth0_LoginManager::login_user() to use the new skip strategies field.
  • Add WP_Auth0_Options::strategy_skips_verified_email() method to check whether a specific strategy can be skipped.
  • Refactor WP_Auth0_UsersRepo::create() to use the new skip strategies field and simplify logic.
  • Add tests for all new functionality and WP_Auth0_UsersRepo::create()

@joshcanhelp joshcanhelp added this to the v3-Next milestone Aug 31, 2018
@joshcanhelp joshcanhelp force-pushed the add-skip-strategies-setting branch from 93ece4f to df0f997 Compare September 3, 2018 16:43
@joshcanhelp joshcanhelp force-pushed the add-skip-strategies-setting branch from df0f997 to c20072b Compare September 3, 2018 17:17
@codecov-io
Copy link

codecov-io commented Sep 3, 2018

Codecov Report

Merging #528 into dev will increase coverage by 2.59%.
The diff coverage is 77.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##               dev    #528      +/-   ##
==========================================
+ Coverage     6.07%   8.66%   +2.59%     
- Complexity    1611    1615       +4     
==========================================
  Files           63      63              
  Lines         5600    5622      +22     
==========================================
+ Hits           340     487     +147     
+ Misses        5260    5135     -125
Impacted Files Coverage Δ Complexity Δ
lib/admin/WP_Auth0_Admin_Basic.php 19.25% <ø> (ø) 34 <0> (ø) ⬇️
lib/WP_Auth0_DBManager.php 18.55% <0%> (ø) 82 <0> (ø) ⬇️
lib/WP_Auth0_Export_Users.php 0% <0%> (ø) 19 <0> (ø) ⬇️
lib/WP_Auth0_LoginManager.php 1.16% <0%> (-0.02%) 122 <0> (+1)
lib/WP_Auth0_Options.php 54.86% <100%> (+3.43%) 32 <2> (+2) ⬆️
lib/admin/WP_Auth0_Admin_Advanced.php 17.81% <86.2%> (+10.61%) 70 <1> (+5) ⬆️
lib/WP_Auth0_UsersRepo.php 48.35% <88.88%> (+48.35%) 40 <20> (-4) ⬇️
lib/admin/WP_Auth0_Admin_Generic.php 42.85% <0%> (+9.52%) 46% <0%> (ø) ⬇️
... and 3 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 ccec093...8b29e07. Read the comment docs.

@@ -526,9 +526,7 @@ private function autoloader( $class ) {
if ( ! function_exists( 'get_auth0userinfo' ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switching to new WP_Auth0_UsersRepo::get_meta helper function

@@ -431,7 +431,7 @@ protected function migrate_users_data() {
$repo = new WP_Auth0_UsersRepo( $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.

Switching to new WP_Auth0_UsersRepo::get_meta helper function

@@ -69,7 +69,8 @@ public function a0_export_users( $user_ids = null ) {
global $wpdb;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switching to new WP_Auth0_UsersRepo::get_meta helper function

* @throws WP_Auth0_EmailNotVerifiedException
* @throws WP_Auth0_RegistrationNotEnabledException
*/
public function create( $userinfo, $token, $access_token = null, $role = null, $skip_email_verified = false ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the meat of this PR. This method was confusing to read and debug so just patching in the skip strategy logic would have probably taken as much time as a line-by-line re-write.

@@ -45,6 +45,12 @@ public function init() {
'id' => 'wpa0_verified_email',
'function' => 'render_verified_email',
),
array(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Declare the new settings field.

@joshcanhelp joshcanhelp force-pushed the add-skip-strategies-setting branch from c20072b to 8b29e07 Compare September 11, 2018 19:30
@cocojoe
Copy link
Member

cocojoe commented Sep 13, 2018

@joshcanhelp by Default it will skip Twitter? and Enterprise Strategies, where does that list come from?

$msg = __( 'Could not create user. The registration process were rejected. Please verify that your account is whitelisted for this system. Please contact your site’s administrator.', 'wp-auth0' );

throw new WP_Auth0_CouldNotCreateUserException( $msg );
} elseif ( -2 === $user_id ) {
Copy link
Member

Choose a reason for hiding this comment

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

Where does -2 come from? Could this be a constant that better defines what this means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's what WP_Auth0_Users::create_user() returns for that condition. I didn't want to go much further with this PR but I totally agree that this magic value is not ideal 👍

@joshcanhelp joshcanhelp force-pushed the add-skip-strategies-setting branch from 8b29e07 to a3622b3 Compare September 13, 2018 16:17
@joshcanhelp
Copy link
Contributor Author

joshcanhelp commented Sep 13, 2018

@cocojoe

by Default it will skip Twitter? and Enterprise Strategies, where does that list come from?

No, no default skipping, field will be blank by default.

@@ -780,7 +815,7 @@ public function link_accounts_validation( $old_options, $input ) {
* @return array
*/
public function loginredirection_validation( $old_options, $input ) {
$new_redirect_url = strtolower( $input['default_login_redirection'] );
$new_redirect_url = esc_url_raw( strtolower( $input['default_login_redirection'] ) );
Copy link
Member

Choose a reason for hiding this comment

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

why does this one get an esc_url_raw but the $old_redirect_url doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to sanitize the old one to check it as it's already saved. If the new email is different after sanitization, then we update with that one (assuming it passes all the other checks).

@cocojoe
Copy link
Member

cocojoe commented Sep 14, 2018

Should probably have an example of connection name entries in the Skip Strategies or could be placeholder? Sometimes not obvious for people and if they have something to match up against the connection name in dashboard it's clearer.

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.

👍

@joshcanhelp joshcanhelp merged commit 168f919 into dev Sep 14, 2018
@joshcanhelp joshcanhelp deleted the add-skip-strategies-setting branch September 14, 2018 16:55
@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