Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/datadog/appsec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def self.add_settings!(base)
option :enabled do |o|
o.type :bool, nilable: true
o.env 'DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED'
o.default false
o.default true
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/appsec/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ def report_routes_via_telemetry(routes)

return unless Datadog.configuration.appsec.api_security.endpoint_collection.enabled

GUARD_ROUTES_REPORTING_ONCE_PER_APP[self].run do
GUARD_ROUTES_REPORTING_ONCE_PER_APP[::Rails.application].run do
AppSec.telemetry.app_endpoints_loaded(
APISecurity::EndpointCollection::RailsRoutesSerializer.new(routes).to_enum
)
end
rescue => e
AppSec.telemetry.report(e, description: 'failed to report application endpoints')
end

def setup_security
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/appsec/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ def patcher
ClimateControl.modify('DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED' => nil) { example.run }
end

it { expect(settings.appsec.api_security.endpoint_collection.enabled).to eq(false) }
it { expect(settings.appsec.api_security.endpoint_collection.enabled).to eq(true) }
end

context 'when DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED is set to true' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ def initialize(files, dirs = {}, &block)
Datadog::AppSec::APISecurity::Sampler.reset!
end

before(:each) do
# reset guard that only allows routes to be reported once
Datadog::AppSec::Contrib::Rails::Patcher::GUARD_ROUTES_REPORTING_ONCE_PER_APP[Rails.application]
.instance_variable_set(:@ran_once, false)
end

it 'rescues exceptions' do
allow(Datadog::AppSec.telemetry).to receive(:app_endpoints_loaded).and_raise(StandardError)

ActiveSupport.run_load_hooks(:after_routes_loaded, Rails.application)
end

it 'reports routes via telemetry' do
ActiveSupport.run_load_hooks(:after_routes_loaded, Rails.application)

Expand Down
Loading