Commit 894157ad authored by Patrick Bajao's avatar Patrick Bajao

Add feature flag enabled by default

parent 6e46fa00
......@@ -84,8 +84,6 @@ module EE
def check_push_size!
return unless check_size_limit?
git_env = ::Gitlab::Git::HookEnv.all(repository.gl_repository)
# Use #quarantine_size to get correct push size whenever a lof of changes
# gets pushed at the same time containing the same blobs. This is only
# doable if GIT_OBJECT_DIRECTORY_RELATIVE env var is set and happens
......@@ -94,13 +92,21 @@ module EE
# Fallback to determining push size using the changes_list so we can still
# determine the push size if env var isn't set (e.g. changes are made
# via UI and API).
push_size = git_env['GIT_OBJECT_DIRECTORY_RELATIVE'].present? ? quarantine_size : changes_size
push_size = check_quarantine_size? ? quarantine_size : changes_size
if project.changes_will_exceed_size_limit?(push_size)
raise ::Gitlab::GitAccess::UnauthorizedError, ::Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
def check_quarantine_size?
strong_memoize(:check_quarantine_size) do
git_env = ::Gitlab::Git::HookEnv.all(repository.gl_repository)
git_env['GIT_OBJECT_DIRECTORY_RELATIVE'].present? && ::Feature.enabled?(:quarantine_push_size_check, default_enabled: true)
end
end
def quarantine_size
project.repository.object_directory_size
end
......
......@@ -220,21 +220,7 @@ describe Gitlab::GitAccess do
end
end
context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set' do
let(:object_directory_size) { 1.megabyte }
before do
allow(Gitlab::Git::HookEnv)
.to receive(:all)
.with(repository.gl_repository)
.and_return({ 'GIT_OBJECT_DIRECTORY_RELATIVE' => 'objects' })
# Stub the object directory size to "simulate" quarantine size
allow(repository)
.to receive(:object_directory_size)
.and_return(object_directory_size)
end
shared_examples_for 'a push to repository using git-rev-list for checking against repository size limit' do
context 'when repository size is over limit' do
let(:repository_size) { 2.megabytes }
let(:repository_size_limit) { 1.megabyte }
......@@ -248,18 +234,20 @@ describe Gitlab::GitAccess do
it_behaves_like 'a push to repository below the limit'
context 'when object directory (quarantine) size exceeds the limit' do
let(:object_directory_size) { 2.megabytes }
context 'when new change exceeds the limit' do
it 'rejects the push' do
expect(repository.new_blobs(sha_with_2_mb_file)).to be_present
expect do
push_changes("#{Gitlab::Git::BLANK_SHA} #{sha_with_2_mb_file} refs/heads/my_branch_2")
end.to raise_error(described_class::UnauthorizedError, /Your push to this repository would cause it to exceed the size limit/)
end
end
context 'when object directory (quarantine) size does not exceed the limit' do
context 'when new change does not exceed the limit' do
it 'accepts the push' do
expect(repository.new_blobs(sha_with_smallest_changes)).to be_present
expect do
push_changes("#{Gitlab::Git::BLANK_SHA} #{sha_with_smallest_changes} refs/heads/my_branch_3")
end.not_to raise_error
......@@ -268,7 +256,24 @@ describe Gitlab::GitAccess do
end
end
context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is not set' do
context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set' do
before do
allow(Gitlab::Git::HookEnv)
.to receive(:all)
.with(repository.gl_repository)
.and_return({ 'GIT_OBJECT_DIRECTORY_RELATIVE' => 'objects' })
end
context 'when quarantine_push_size_check feature is enabled (default)' do
let(:object_directory_size) { 1.megabyte }
before do
# Stub the object directory size to "simulate" quarantine size
allow(repository)
.to receive(:object_directory_size)
.and_return(object_directory_size)
end
context 'when repository size is over limit' do
let(:repository_size) { 2.megabytes }
let(:repository_size_limit) { 1.megabyte }
......@@ -282,20 +287,18 @@ describe Gitlab::GitAccess do
it_behaves_like 'a push to repository below the limit'
context 'when new change exceeds the limit' do
it 'rejects the push' do
expect(repository.new_blobs(sha_with_2_mb_file)).to be_present
context 'when object directory (quarantine) size exceeds the limit' do
let(:object_directory_size) { 2.megabytes }
it 'rejects the push' do
expect do
push_changes("#{Gitlab::Git::BLANK_SHA} #{sha_with_2_mb_file} refs/heads/my_branch_2")
end.to raise_error(described_class::UnauthorizedError, /Your push to this repository would cause it to exceed the size limit/)
end
end
context 'when new change does not exceed the limit' do
context 'when object directory (quarantine) size does not exceed the limit' do
it 'accepts the push' do
expect(repository.new_blobs(sha_with_smallest_changes)).to be_present
expect do
push_changes("#{Gitlab::Git::BLANK_SHA} #{sha_with_smallest_changes} refs/heads/my_branch_3")
end.not_to raise_error
......@@ -303,6 +306,19 @@ describe Gitlab::GitAccess do
end
end
end
context 'when quarantine_push_size_check feature is disabled' do
before do
stub_feature_flags(quarantine_push_size_check: false)
end
it_behaves_like 'a push to repository using git-rev-list for checking against repository size limit'
end
end
context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is not set' do
it_behaves_like 'a push to repository using git-rev-list for checking against repository size limit'
end
end
describe 'Geo' do
......
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