Repository navigation
Protect: Let the firewall and Account protection endpoints accept the wanted state - #53317
Conversation
toggle-waf and toggle-account-protection inverted whatever the current state was, so a stale page or a double submit did the opposite of what was asked. Both now take an optional `enabled` boolean and the Protect UI sends it. A request without it still flips, so a cached copy of the old script keeps working. The firewall notice now reports the state that was requested.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Protect plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Coverage check overridden by
Covered by non-unit tests
|
The Protect UI can only turn the firewall on, so the mutation now always sends enabled: true and keeps its single pair of notices. The two-way notices were being merged by the production minifier, which failed the i18n check.
Fixes JETPACK-2948
Proposed changes
POST jetpack-protect/v1/toggle-wafandPOST jetpack-protect/v1/toggle-account-protectiontook no argument and inverted whatever the current state was. A stale page, a second tab, or a double submit did the opposite of what was asked. Both now accept an optionalenabledboolean and set that state, so sending "on" twice leaves the feature on.enabledstill flips, so a browser holding the previous script keeps working through an update.No unit test here. The plugin has no PHP or JS test harness for its REST routes (
tests/phpis only a bootstrap), and standing one up for this felt out of proportion. Tested on a live site instead, steps below.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
On a connected site with the Protect plugin active (with or without the Jetpack plugin):
Account protection, stale page
Firewall, stale page
The endpoints directly (an application password works for auth)
POST /wp-json/jetpack-protect/v1/toggle-wafwith{"enabled":true}twice:GET jetpack-protect/v1/wafreportsisEnabled: trueafter each.{"enabled":false}: stays off.{"enabled":"banana"}returns a 400.toggle-account-protectionandGET jetpack-protect/v1/account-protection.