-
Notifications
You must be signed in to change notification settings - Fork 375
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
make sure to assign a valid processor to the appsec component #2637
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with a few suggestions.
We should improve thread safety further when we get to remote configuration.
lib/datadog/appsec/component.rb
Outdated
if processor | ||
processor.finalize | ||
@processor = nil | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve thread safety, Processor
might be finalized already but not yet nil
.
Also, prefer a guard clause:
if processor | |
processor.finalize | |
@processor = nil | |
end | |
return if processor.nil? || !processor.ready? | |
processor.finalize | |
@processor = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer a guard clause too. It looks like steep likes:
def shutdown!
if processor && processor.ready?
processor.finalize
@processor = nil
end
end
With this form, steep is able to resolve the type checking issue we discussed earlier in which steep does not find the finalize
method
lib/datadog/appsec/component.rb:28:18: [error] Type `::Datadog::AppSec::Processor` does not have method `finalize`
│ Diagnostic ID: Ruby::NoMethod
│
└ processor.finalize if processor
~~~~~~~~
Detected 1 problem from 1 file
Codecov Report
@@ Coverage Diff @@
## master #2637 +/- ##
==========================================
- Coverage 98.08% 98.08% -0.01%
==========================================
Files 1155 1155
Lines 63330 63358 +28
Branches 2826 2828 +2
==========================================
+ Hits 62117 62142 +25
- Misses 1213 1216 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
What does this PR do?
After merging #2632, we got alerted that our system tests were failing.
The scenario that is failing is when the appsec processor fails to parse the WAF rules.
The test fails when the app wants tries to shout down and we try to finalize the appsec component. The problem is that the processor was never ready, so finalizing a non-ready processor caused an error.
This PR fix that case by making sure to check if the processor is ready to assign to the appsec component.
Additional Notes
Should we make the
AppSec::Component.new
method private and only allow to usebuild_appsec_component
?How to test the change?