Commit b54c4ca3 authored by Alper Akgun's avatar Alper Akgun

Harden flipper feature.get access

For ab_feature_enabled makes sure we don't get a runtime error if
flipper implementation for `get` changes
parent b7fc4b31
...@@ -338,7 +338,7 @@ module EE ...@@ -338,7 +338,7 @@ module EE
# We use a 2nd feature flag for control as enabled and percentage_of_time for chatops # We use a 2nd feature flag for control as enabled and percentage_of_time for chatops
flipper_feature = ::Feature.get((feature.to_s + '_control').to_sym) # rubocop:disable Gitlab/AvoidFeatureGet flipper_feature = ::Feature.get((feature.to_s + '_control').to_sym) # rubocop:disable Gitlab/AvoidFeatureGet
percentage ||= flipper_feature.gate_values[:percentage_of_time] || 0 if flipper_feature percentage ||= flipper_feature&.percentage_of_time_value || 0
return false if percentage <= 0 return false if percentage <= 0
if filter == UserPreference::FEATURE_FILTER_UNKNOWN if filter == UserPreference::FEATURE_FILTER_UNKNOWN
......
...@@ -982,6 +982,16 @@ describe User do ...@@ -982,6 +982,16 @@ describe User do
expect(experiment_user.ab_feature_enabled?(:discover_security)).to eq(true) expect(experiment_user.ab_feature_enabled?(:discover_security)).to eq(true)
expect(experiment_user.user_preference.feature_filter_type).to eq(UserPreference::FEATURE_FILTER_EXPERIMENT) expect(experiment_user.user_preference.feature_filter_type).to eq(UserPreference::FEATURE_FILTER_EXPERIMENT)
end end
it 'returns false if flipper returns nil for non-existing feature' do
# The following setup ensures that if the Feature interface changes
# it does not break any user-facing screens
allow(Feature).to receive(:get).with(:discover_security).and_return(nil)
allow(Feature).to receive(:enabled?).and_return(true)
allow(Feature).to receive(:get).with(:discover_security_control).and_return(nil)
expect(experiment_user.ab_feature_enabled?(:discover_security)).to eq(false)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment