diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /spec/lib/gitlab/checks/global_file_size_check_spec.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/checks/global_file_size_check_spec.rb')
-rw-r--r-- | spec/lib/gitlab/checks/global_file_size_check_spec.rb | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/spec/lib/gitlab/checks/global_file_size_check_spec.rb b/spec/lib/gitlab/checks/global_file_size_check_spec.rb index 9ea0c73b1c7..a2b3ee0f761 100644 --- a/spec/lib/gitlab/checks/global_file_size_check_spec.rb +++ b/spec/lib/gitlab/checks/global_file_size_check_spec.rb @@ -14,13 +14,13 @@ RSpec.describe Gitlab::Checks::GlobalFileSizeCheck, feature_category: :source_co it 'does not log' do expect(subject).not_to receive(:log_timed) expect(Gitlab::AppJsonLogger).not_to receive(:info) - expect(Gitlab::Checks::FileSizeCheck::AllowExistingOversizedBlobs).not_to receive(:new) + expect(Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs).not_to receive(:new) subject.validate! end end it 'checks for file sizes' do - expect_next_instance_of(Gitlab::Checks::FileSizeCheck::AllowExistingOversizedBlobs, + expect_next_instance_of(Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs, project: project, changes: changes, file_size_limit_megabytes: 100 @@ -32,5 +32,35 @@ RSpec.describe Gitlab::Checks::GlobalFileSizeCheck, feature_category: :source_co expect(Gitlab::AppJsonLogger).to receive(:info).with('Checking for blobs over the file size limit') subject.validate! end + + context 'when there are oversized blobs' do + let(:blob_double) { instance_double(Gitlab::Git::Blob, size: 10) } + + 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_sizes: [10]) + expect { subject.validate! }.to raise_exception(Gitlab::GitAccess::ForbiddenError) + end + + context 'when the enforce_global_file_size_limit feature flag is disabled' do + before do + stub_feature_flags(enforce_global_file_size_limit: false) + end + + it 'does not raise an exception' do + expect { subject.validate! }.not_to raise_error + end + end + end end end |