2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Checks::LfsCheck do
|
2021-09-04 01:27:46 +05:30
|
|
|
include_context 'changes access checks context'
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
let(:blob_object) { project.repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::Git::LfsChanges).to receive(:new_pointers) do
|
|
|
|
[blob_object]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#validate!' do
|
|
|
|
context 'with LFS not enabled' do
|
2021-09-04 01:27:46 +05:30
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it 'skips integrity check' do
|
|
|
|
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
|
|
|
|
|
|
|
|
subject.validate!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with LFS enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
context 'with lfs_check feature disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(lfs_check: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips integrity check' do
|
|
|
|
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
|
|
|
|
|
|
|
|
subject.validate!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'with deletion' do
|
|
|
|
shared_examples 'a skipped integrity check' do
|
|
|
|
it 'skips integrity check' do
|
|
|
|
expect(project.repository).not_to receive(:new_objects)
|
|
|
|
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
|
|
|
|
|
|
|
|
subject.validate!
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'with missing newrev' do
|
|
|
|
it_behaves_like 'a skipped integrity check' do
|
2021-09-04 01:27:46 +05:30
|
|
|
let(:changes) { [{ oldrev: oldrev, ref: ref }] }
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'with blank newrev' do
|
|
|
|
it_behaves_like 'a skipped integrity check' do
|
2021-09-04 01:27:46 +05:30
|
|
|
let(:changes) { [{ oldrev: oldrev, newrev: Gitlab::Git::BLANK_SHA, ref: ref }] }
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails if any LFS blobs are missing' do
|
2020-04-08 14:13:33 +05:30
|
|
|
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, /LFS objects are missing/)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'succeeds if LFS objects have already been uploaded' do
|
|
|
|
lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
|
|
|
|
create(:lfs_objects_project, project: project, lfs_object: lfs_object)
|
|
|
|
|
|
|
|
expect { subject.validate! }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|