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

Fix Migration Token Generation; Add JSON Content-Type header #617

Merged
merged 4 commits into from
Jan 9, 2019

Conversation

joshcanhelp
Copy link
Contributor

Changes

  • Add a check for existing token so it does not get regenerated when the endpoints are turned off, then on again (current behavior is to regenerate without warning, which could unintentionally cause login issues).
  • Add Content-Type: application/json header to endpoints that output JSON

Note: We added an internal task to add a control to regenerate this token in wp-admin.

Testing

  • Adjusted existing tests to follow how this setting is handled
  • Unable to add unit tests for header output (script exits, making testing impossible)

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 added this to the 3.9.0 milestone Jan 8, 2019
*
* @return mixed
*/
public function add_json_header( array $headers ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs to be public to work with add_filter() call

@@ -612,6 +612,7 @@ public function migration_ws_validation( array $old_options, array $input ) {
return $input;
}

$input['migration_token'] = $this->options->get( 'migration_token' );
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 setting is not typical in that it does not accept an input. The token is generated and then remains in the database (or is received from a constant).

Copy link
Contributor

Choose a reason for hiding this comment

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

what if the value is missing/null? When generated I guess this is not the case. But when taking it from a constant value, are you checking this is not null in the "constants reader" logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the value is empty/null, then a token gets generated.

The constant loading populates $this->options->get() so that call catches both.

@@ -1,6 +1,6 @@
<?php
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming test suite

@@ -98,10 +100,27 @@ public function custom_requests( $wp, $return = false ) {
return $output;
}

if ( $json_header ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this OK here or should it go before the if ($return) above ?? Maybe the send_headers() function might need to be called as well and you missed that (I don't really know)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for a header if we're just spitting back the data rather than outputting.

@@ -612,6 +612,7 @@ public function migration_ws_validation( array $old_options, array $input ) {
return $input;
}

$input['migration_token'] = $this->options->get( 'migration_token' );
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the value is missing/null? When generated I guess this is not the case. But when taking it from a constant value, are you checking this is not null in the "constants reader" logic?

@joshcanhelp joshcanhelp force-pushed the fix-migration-token-reset-on-save branch from ef5fd12 to e152006 Compare January 9, 2019 17:42
@codecov-io
Copy link

codecov-io commented Jan 9, 2019

Codecov Report

Merging #617 into master will increase coverage by 0.01%.
The diff coverage is 40%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #617      +/-   ##
============================================
+ Coverage      36.4%   36.42%   +0.01%     
- Complexity     1264     1266       +2     
============================================
  Files            51       51              
  Lines          3920     3929       +9     
============================================
+ Hits           1427     1431       +4     
- Misses         2493     2498       +5
Impacted Files Coverage Δ Complexity Δ
lib/admin/WP_Auth0_Admin_Advanced.php 32.48% <100%> (+0.24%) 58 <0> (ø) ⬇️
lib/WP_Auth0_Routes.php 86.61% <33.33%> (-3.68%) 55 <1> (+2)
lib/WP_Auth0_Options_Generic.php 98.27% <0%> (+1.72%) 27% <0%> (ø) ⬇️

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 f9072db...7458714. Read the comment docs.

@joshcanhelp joshcanhelp merged commit 7147fd0 into master Jan 9, 2019
@joshcanhelp joshcanhelp deleted the fix-migration-token-reset-on-save branch January 9, 2019 23:10
@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