diff options
Diffstat (limited to 'spec/lib/gitlab/checks')
-rw-r--r-- | spec/lib/gitlab/checks/global_file_size_check_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/tag_check_spec.rb | 30 |
2 files changed, 43 insertions, 3 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 a2b3ee0f761..db615053356 100644 --- a/spec/lib/gitlab/checks/global_file_size_check_spec.rb +++ b/spec/lib/gitlab/checks/global_file_size_check_spec.rb @@ -34,7 +34,10 @@ RSpec.describe Gitlab::Checks::GlobalFileSizeCheck, feature_category: :source_co end context 'when there are oversized blobs' do - let(:blob_double) { instance_double(Gitlab::Git::Blob, size: 10) } + let(:mock_blob_id) { "88acbfafb1b8fdb7c51db870babce21bd861ac4f" } + let(:mock_blob_size) { 300 * 1024 * 1024 } # 300 MiB + let(:size_msg) { "300.0" } # it is (mock_blob_size / 1024.0 / 1024.0).round(2).to_s + 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, @@ -48,8 +51,15 @@ RSpec.describe Gitlab::Checks::GlobalFileSizeCheck, feature_category: :source_co 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) + expect(Gitlab::AppJsonLogger).to receive(:info).with( + message: 'Found blob over global limit', + blob_sizes: [mock_blob_size], + blob_details: { mock_blob_id => { "size" => mock_blob_size } } + ) + expect do + subject.validate! + end.to raise_exception(Gitlab::GitAccess::ForbiddenError, + /- #{mock_blob_id} \(#{size_msg} MiB\)/) end context 'when the enforce_global_file_size_limit feature flag is disabled' do diff --git a/spec/lib/gitlab/checks/tag_check_spec.rb b/spec/lib/gitlab/checks/tag_check_spec.rb index 60d3eb4bfb3..b5aafde006f 100644 --- a/spec/lib/gitlab/checks/tag_check_spec.rb +++ b/spec/lib/gitlab/checks/tag_check_spec.rb @@ -41,6 +41,36 @@ RSpec.describe Gitlab::Checks::TagCheck, feature_category: :source_code_manageme expect { subject.validate! }.not_to raise_error end end + + it "prohibits tag names that include characters incompatible with UTF-8" do + allow(subject).to receive(:tag_name).and_return("v6.0.0-\xCE.BETA") + + expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, "Tag names must be valid when converted to UTF-8 encoding") + end + + it "doesn't prohibit UTF-8 compatible characters" do + allow(subject).to receive(:tag_name).and_return("v6.0.0-Ü.BETA") + + expect { subject.validate! }.not_to raise_error + end + + context "when prohibited_tag_name_encoding_check feature flag is disabled" do + before do + stub_feature_flags(prohibited_tag_name_encoding_check: false) + end + + it "doesn't prohibit tag names that include characters incompatible with UTF-8" do + allow(subject).to receive(:tag_name).and_return("v6.0.0-\xCE.BETA") + + expect { subject.validate! }.not_to raise_error + end + + it "doesn't prohibit UTF-8 compatible characters" do + allow(subject).to receive(:tag_name).and_return("v6.0.0-Ü.BETA") + + expect { subject.validate! }.not_to raise_error + end + end end context 'with protected tag' do |