-
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
Do not try accessing the appsec settings if the appsec module is not loaded #2679
Do not try accessing the appsec settings if the appsec module is not loaded #2679
Conversation
3b3eb80
to
397a1f3
Compare
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.
👍 Left a note and a suggestion of how to test this, but otherwise big thanks for the fast fix!
lib/datadog/appsec/component.rb
Outdated
return unless settings.enabled | ||
return unless defined?(Datadog::AppSec::Configuration) && settings.appsec.enabled |
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 initially suggested defined?
, but looking at the code here, I think we could probably get away with respond_to?(:appsec)
.
That would probably make it way easier to test -- we could just pass in a mock settings object that did not have an appsec entry.
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.
That makes a lot of sense. I like the idea of being able to test that functionality as well.
Thanks for the suggestion 😄
Codecov Report
@@ Coverage Diff @@
## master #2679 +/- ##
==========================================
- Coverage 98.09% 98.09% -0.01%
==========================================
Files 1168 1168
Lines 64216 64222 +6
Branches 2857 2857
==========================================
+ Hits 62994 62999 +5
- Misses 1222 1223 +1
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
👍 Looks great!
fix #2677
The issue is that trying to access
settings.appsec
when configuringDatadog
is that if theappsec
hasn't being required or if the customer did not requireddtrace
the error we would get isundefined method :appsec
for #Datadog::Core::Configuration::Settings`The appsec setting is loaded here:
dd-trace-rb/lib/ddtrace.rb
Line 7 in 28c3c3e
dd-trace-rb/lib/datadog/appsec.rb
Line 32 in 28c3c3e
The fix makes sure to double check before if the appsec configuration module has been loaded, and if it hasn't, we will no-op.
I tested this change loading just
datadog/ci
in anirb
session and callingDatadog.configure {}