mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-20 14:11:11 +00:00
Add latest changes from gitlab-org/gitlab@17-10-stable-ee
This commit is contained in:
@ -8,6 +8,8 @@ module Gitlab
|
||||
LOG_MESSAGE = 'Checking for blobs over the file size limit'
|
||||
|
||||
def validate!
|
||||
return unless file_size_limit.present?
|
||||
|
||||
Gitlab::AppJsonLogger.info(LOG_MESSAGE)
|
||||
logger.log_timed(LOG_MESSAGE) do
|
||||
oversized_blobs = Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs.new(
|
||||
@ -46,9 +48,13 @@ module Gitlab
|
||||
|
||||
private
|
||||
|
||||
# rubocop:disable Gitlab/NoCodeCoverageComment -- This is fully overriden in EE
|
||||
# :nocov:
|
||||
def file_size_limit
|
||||
project.actual_limits.file_size_limit_mb
|
||||
nil
|
||||
end
|
||||
# :nocov:
|
||||
# rubocop:enable Gitlab/NoCodeCoverageComment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
ARG GDK_SHA=bf5f1d451d227e78f68f244205af138fb942f2d3
|
||||
ARG GDK_SHA=53f340dd33a94d101c1ab051dbab2beef81390fc
|
||||
# Use tag prefix when running on 'stable' branch to make sure 'protected' image is used which is not deleted by registry cleanup
|
||||
ARG GDK_BASE_TAG_PREFIX
|
||||
|
||||
|
@ -8,47 +8,10 @@ RSpec.describe Gitlab::Checks::FileSizeLimitCheck, feature_category: :source_cod
|
||||
subject(:file_size_check) { described_class.new(changes_access) }
|
||||
|
||||
describe '#validate!' do
|
||||
it 'checks for file sizes' do
|
||||
expect_next_instance_of(Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs,
|
||||
project: project,
|
||||
changes: changes,
|
||||
file_size_limit_megabytes: 100
|
||||
) do |check|
|
||||
expect(check).to receive(:find).and_call_original
|
||||
end
|
||||
expect(file_size_check.logger).to receive(:log_timed).with('Checking for blobs over the file size limit')
|
||||
.and_call_original
|
||||
expect(Gitlab::AppJsonLogger).to receive(:info).with('Checking for blobs over the file size limit')
|
||||
it 'does not check for file sizes' do
|
||||
expect(Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs).not_to receive(:new)
|
||||
expect(file_size_check.logger).not_to receive(:log_timed)
|
||||
file_size_check.validate!
|
||||
end
|
||||
|
||||
context 'when there are oversized blobs' do
|
||||
let(:mock_blob_id) { "88acbfafb1b8fdb7c51db870babce21bd861ac4f" }
|
||||
let(:mock_blob_size) { 300 * 1024 * 1024 } # 300 MiB
|
||||
let(:size_msg) { "300" }
|
||||
let(:blob_double) { instance_double(Gitlab::Git::Blob, size: mock_blob_size, id: mock_blob_id) }
|
||||
|
||||
before do
|
||||
allow_next_instance_of(Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs,
|
||||
project: project,
|
||||
changes: changes,
|
||||
file_size_limit_megabytes: 100
|
||||
) do |check|
|
||||
allow(check).to receive(:find).and_return([blob_double])
|
||||
end
|
||||
end
|
||||
|
||||
it 'logs a message with blob size and raises an exception' do
|
||||
expect(Gitlab::AppJsonLogger).to receive(:info).with('Checking for blobs over the file size limit')
|
||||
expect(Gitlab::AppJsonLogger).to receive(:info).with(
|
||||
message: 'Found blob over global limit',
|
||||
blob_details: [{ "id" => mock_blob_id, "size" => mock_blob_size }]
|
||||
)
|
||||
expect do
|
||||
file_size_check.validate!
|
||||
end.to raise_exception(Gitlab::GitAccess::ForbiddenError,
|
||||
/- #{mock_blob_id} \(#{size_msg} MiB\)/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user