Commit 7d9ad1b8 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '220008-follow-up-from-abstract-feature-flags-usage-patterns' into 'master'

Harden flipper feature.get access

Closes #220008

See merge request gitlab-org/gitlab!33590
parents 7fc9242c b54c4ca3
......@@ -338,7 +338,7 @@ module EE
# 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
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
if filter == UserPreference::FEATURE_FILTER_UNKNOWN
......
......@@ -982,6 +982,16 @@ describe User do
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)
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
......
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