Skip to content
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 dup the default value when setting it #2999

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion lib/datadog/core/configuration/option.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative '../utils/safe_dup'

module Datadog
module Core
module Configuration
Expand Down Expand Up @@ -137,7 +139,7 @@ def default_value
if definition.default.instance_of?(Proc)
context_eval(&definition.default)
else
definition.experimental_default_proc || definition.default
definition.experimental_default_proc || Core::Utils::SafeDup.frozen_or_dup(definition.default)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/appsec/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def patcher
context 'is not defined' do
let(:appsec_obfuscator_key_regex) { nil }

it { is_expected.to be described_class::DEFAULT_OBFUSCATOR_KEY_REGEX }
it { is_expected.to eq described_class::DEFAULT_OBFUSCATOR_KEY_REGEX }
end

context 'is defined' do
Expand Down Expand Up @@ -423,7 +423,7 @@ def patcher
context 'is not defined' do
let(:appsec_obfuscator_value_regex) { nil }

it { is_expected.to be described_class::DEFAULT_OBFUSCATOR_VALUE_REGEX }
it { is_expected.to eq described_class::DEFAULT_OBFUSCATOR_VALUE_REGEX }
end

context 'is defined' do
Expand Down
9 changes: 9 additions & 0 deletions spec/datadog/core/configuration/option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
let(:setter_value) { double('setter_value') }
let(:context) { double('configuration object') }

# When setting the setting value, we make sure to duplicate it to avoid unwanted modifications
# to make sure specs pass when comparing result ex. expect(result).to be value
# we ensure that frozen_or_dup returns the same instance
before do
allow(Datadog::Core::Utils::SafeDup).to receive(:frozen_or_dup) do |args, _block|
args
end
end

describe '#initialize' do
it { expect(option.definition).to be(definition) }
end
Expand Down
9 changes: 9 additions & 0 deletions spec/datadog/core/configuration/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
end
end

# When setting the setting value, we make sure to duplicate it to avoid unwanted modifications
# to make sure specs pass when comparing result ex. expect(result).to be value
# we ensure that frozen_or_dup returns the same instance
before do
allow(Datadog::Core::Utils::SafeDup).to receive(:frozen_or_dup) do |args, _block|
args
end
end

describe 'class behavior' do
describe '#options' do
subject(:options) { options_class.options }
Expand Down