Commit 2711bcd8 authored by Sean McGivern's avatar Sean McGivern

Merge branch '266986-update-img-resizing-ffs' into 'master'

Replace existing Feature Flags with a single of OPS type

See merge request gitlab-org/gitlab!45050
parents c88d9aa6 a78d0b3f
...@@ -70,16 +70,7 @@ module SendFileUpload ...@@ -70,16 +70,7 @@ module SendFileUpload
Avatarable::ALLOWED_IMAGE_SCALER_WIDTHS.include?(params[:width]&.to_i) Avatarable::ALLOWED_IMAGE_SCALER_WIDTHS.include?(params[:width]&.to_i)
end end
# We use two separate feature gates to allow image resizing.
# The first, `:dynamic_image_resizing_requester`, based on the content requester.
# Enabling it for the user would allow that user to send resizing requests for any avatar.
# The second, `:dynamic_image_resizing_owner`, based on the content owner.
# Enabling it for the user would allow anyone to send resizing requests against the mentioned user avatar only.
# This flag allows us to operate on trusted data only, more in https://gitlab.com/gitlab-org/gitlab/-/issues/241533.
# Because of this, you need to enable BOTH to serve resized image,
# as you would need at least one allowed requester and at least one allowed avatar.
def scaling_allowed_by_feature_flags?(file_upload) def scaling_allowed_by_feature_flags?(file_upload)
Feature.enabled?(:dynamic_image_resizing_requester, current_user) && Feature.enabled?(:dynamic_image_resizing, default_enabled: true, type: :ops)
Feature.enabled?(:dynamic_image_resizing_owner, file_upload.model)
end end
end end
---
title: Replace existing Image Resizing FFs with a single of `ops` type enabled by default
merge_request: 45050
author:
type: other
---
name: dynamic_image_resizing_requester
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37342
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/233704
group: group::memory
type: development
default_enabled: false
--- ---
name: dynamic_image_resizing_owner name: dynamic_image_resizing
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40606 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45050
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/241533 rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/266986
type: ops
group: group::memory group: group::memory
type: development default_enabled: true
default_enabled: false
...@@ -70,61 +70,18 @@ RSpec.describe SendFileUpload do ...@@ -70,61 +70,18 @@ RSpec.describe SendFileUpload do
allow(uploader).to receive(:model).and_return(image_owner) allow(uploader).to receive(:model).and_return(image_owner)
end end
context 'when boths FFs are enabled' do it_behaves_like 'handles image resize requests allowed by FF'
before do
stub_feature_flags(dynamic_image_resizing_requester: image_requester)
stub_feature_flags(dynamic_image_resizing_owner: image_owner)
end
it_behaves_like 'handles image resize requests allowed by FFs'
end
context 'when boths FFs are enabled globally' do
before do
stub_feature_flags(dynamic_image_resizing_requester: true)
stub_feature_flags(dynamic_image_resizing_owner: true)
end
it_behaves_like 'handles image resize requests allowed by FFs'
context 'when current_user is nil' do
before do
allow(controller).to receive(:current_user).and_return(nil)
end
it_behaves_like 'handles image resize requests allowed by FFs'
end
end
context 'when only FF based on content requester is enabled for current user' do
before do
stub_feature_flags(dynamic_image_resizing_requester: image_requester)
stub_feature_flags(dynamic_image_resizing_owner: false)
end
it_behaves_like 'bypasses image resize requests not allowed by FFs'
end
context 'when only FF based on content owner is enabled for requested avatar owner' do
before do
stub_feature_flags(dynamic_image_resizing_requester: false)
stub_feature_flags(dynamic_image_resizing_owner: image_owner)
end
it_behaves_like 'bypasses image resize requests not allowed by FFs'
end
context 'when both FFs are disabled' do context 'when FF is disabled' do
before do before do
stub_feature_flags(dynamic_image_resizing_requester: false) stub_feature_flags(dynamic_image_resizing: false)
stub_feature_flags(dynamic_image_resizing_owner: false)
end end
it_behaves_like 'bypasses image resize requests not allowed by FFs' it_behaves_like 'bypasses image resize requests not allowed by FF'
end end
end end
shared_examples 'bypasses image resize requests not allowed by FFs' do shared_examples 'bypasses image resize requests not allowed by FF' do
it 'does not write workhorse command header' do it 'does not write workhorse command header' do
expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/)
...@@ -132,7 +89,7 @@ RSpec.describe SendFileUpload do ...@@ -132,7 +89,7 @@ RSpec.describe SendFileUpload do
end end
end end
shared_examples 'handles image resize requests allowed by FFs' do shared_examples 'handles image resize requests allowed by FF' do
context 'with valid width parameter' do context 'with valid width parameter' do
it 'renders OK with workhorse command header' do it 'renders OK with workhorse command header' do
expect(controller).not_to receive(:send_file) expect(controller).not_to receive(:send_file)
......
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