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

Refactor migration route handling and add tests #606

Merged
merged 2 commits into from
Dec 19, 2018

Conversation

joshcanhelp
Copy link
Contributor

Changes

Simplify how migration endpoints are served and add tests.

Testing

  • This change adds unit test coverage
  • This change has been tested on the latest version of WordPress

Checklist

  • All existing and new tests complete without errors
  • All code quality tools/guidelines in the Contribution guide have been run/followed
  • All active GitHub CI checks have passed

@joshcanhelp joshcanhelp force-pushed the change-migration-route-handling branch from a426ff4 to 0abb338 Compare December 18, 2018 19:52
@codecov-io
Copy link

Codecov Report

Merging #606 into master will increase coverage by 0.33%.
The diff coverage is 96.42%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #606      +/-   ##
============================================
+ Coverage     34.02%   34.35%   +0.33%     
+ Complexity     1317     1314       -3     
============================================
  Files            54       54              
  Lines          4174     4163      -11     
============================================
+ Hits           1420     1430      +10     
+ Misses         2754     2733      -21
Impacted Files Coverage Δ Complexity Δ
lib/WP_Auth0_Routes.php 90.29% <96.42%> (+13.74%) 53 <11> (-3) ⬇️

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 ab4683a...0abb338. Read the comment docs.

@@ -38,7 +38,7 @@ public function init() {
add_action( 'parse_request', array( $this, 'custom_requests' ) );
}

public function setup_rewrites( $force_ws = 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.

Allowed in PHP. Parameter was not used and anyone calling this with a parameter will not get an error.

if ( ! $this->ip_check->connection_is_valid( $allowed_ips ) ) {
return $this->error_return_array( 401 );
}
$code = $this->check_endpoint_access_error();
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 call handles all the checks above.

if ( ! $this->ip_check->connection_is_valid( $allowed_ips ) ) {
return $this->error_return_array( 401 );
}
$code = $this->check_endpoint_access_error();
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 call handles all the checks above.

if ( ! isset( $_POST['username'] ) ) {
throw new Exception( __( 'Username is required', 'wp-auth0' ) );
}
$this->check_endpoint_request();
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 call handles all the checks above.

if ( empty( $_POST['password'] ) ) {
throw new Exception( __( 'Password is required', 'wp-auth0' ) );
}
$this->check_endpoint_request( true );
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 call handles all the checks above.

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.

Just check the comment.

*/
private function check_endpoint_request( $require_password = false ) {
$authorization = $this->getAuthorizationHeader();
$authorization = trim( str_replace( 'Bearer ', '', $authorization ) );
Copy link
Member

Choose a reason for hiding this comment

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

Feels like the sort of thing that might be nice in a tested helper method.

@joshcanhelp joshcanhelp merged commit 8482071 into master Dec 19, 2018
@joshcanhelp joshcanhelp deleted the change-migration-route-handling branch December 19, 2018 17:14
@joshcanhelp joshcanhelp added this to the 3.9.0 milestone Dec 19, 2018
@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.

None yet

3 participants