-
Notifications
You must be signed in to change notification settings - Fork 102
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 log suppression to VIP_Request_Block #5478
Add log suppression to VIP_Request_Block #5478
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5478 +/- ##
=============================================
+ Coverage 29.41% 29.42% +0.01%
- Complexity 4759 4764 +5
=============================================
Files 281 281
Lines 20533 20530 -3
=============================================
+ Hits 6039 6041 +2
+ Misses 14494 14489 -5 ☔ View full report in Codecov by Sentry. |
I wanted to add a test for this change, but there currently isn't a test for the |
Yes, that is correct. |
Maybe smth like public static function log( string $criteria, string $value ): void {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( sprintf( 'VIP Request Block: request was blocked based on "%s" with value of "%s"', $criteria, $value ) );
} - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
- error_log( sprintf( 'VIP Request Block: request was blocked based on "%s" with value of "%s"', $criteria, $value ) );
+ static::log( $criteria, $value ); Then in the test: class MyRequestBlock extends VIP_Request_Block {
static $log_called = false;
public static function log( string $criteria, string $value ): void {
self::$log_called = true;
}
} and in the test case in This is probably easier than mocking. |
@sjinks I've tried a few different things but couldn't get the test to work. I haz no PHP skills. If you could give me a little help getting that across the finish line, that would be much appreciated. Thanks |
@yolih for awareness |
eec6e85
to
0b231ce
Compare
…tatic should_log method. Call the class method instead of php 'log' function.
…ircuited for tests we had to duplicate the logic in LogTrackingRequestBlock test class
4c8f120
to
aa1ccb0
Compare
Quality Gate passedIssues Measures |
Description
This PR introduces a new method that allows suppression of the logs. In case it's too noisy a new helper can be used in vip-config.php
Changelog Description
VIP_Request_Block Log Output Control
Added an option to suppress logging for requests blocked by
VIP_Request_Block
:Pre-review checklist
Please make sure the items below have been covered before requesting a review:
Pre-deploy checklist
Steps to Test
VIP_Request_Block::should_log( false );
tovip-config.php
VIP_Request_Block::should_log( false );
line, repeat step 5, verify the block was logged.